@usethrottle/builder-react 0.2.4 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-WZOWM2I7.cjs → chunk-IDGSPYRH.cjs} +54 -22
- package/dist/{chunk-IBRAMTUT.js → chunk-LXBCOZP2.js} +38 -6
- package/dist/index.cjs +46 -11
- package/dist/index.d.cts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +46 -11
- package/dist/next.cjs +6 -6
- package/dist/next.js +1 -1
- package/dist/server.cjs +21 -21
- package/dist/server.js +1 -1
- package/package.json +4 -4
|
@@ -38,7 +38,9 @@ function bindingsOf(node, registry) {
|
|
|
38
38
|
function collectBindings(doc, registry) {
|
|
39
39
|
const found = /* @__PURE__ */ new Map();
|
|
40
40
|
_builderschema.walkNodes.call(void 0, doc, (node) => {
|
|
41
|
-
if (node.type === "section" || node.type === "inner-section" || node.type === "column")
|
|
41
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column" || node.type === "saved-section") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
42
44
|
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
43
45
|
const key = bindingKey(binding);
|
|
44
46
|
if (!found.has(key)) found.set(key, binding);
|
|
@@ -1089,7 +1091,9 @@ function collect(doc, registry, assets, mediaOrigin) {
|
|
|
1089
1091
|
}
|
|
1090
1092
|
});
|
|
1091
1093
|
};
|
|
1092
|
-
doc.sections
|
|
1094
|
+
for (const root of doc.sections) {
|
|
1095
|
+
if (root.type === "section") section(root);
|
|
1096
|
+
}
|
|
1093
1097
|
return nodes;
|
|
1094
1098
|
}
|
|
1095
1099
|
var block = (id, decls) => {
|
|
@@ -1194,7 +1198,11 @@ function registryFor(doc, base) {
|
|
|
1194
1198
|
let registry = perDocument.get(snapshots);
|
|
1195
1199
|
if (registry === void 0) {
|
|
1196
1200
|
try {
|
|
1197
|
-
registry = base.withCustom(
|
|
1201
|
+
registry = base.withCustom(
|
|
1202
|
+
Object.values(snapshots).filter(
|
|
1203
|
+
(snapshot) => snapshot.kind !== "code"
|
|
1204
|
+
)
|
|
1205
|
+
);
|
|
1198
1206
|
} catch (error) {
|
|
1199
1207
|
warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
|
|
1200
1208
|
registry = base;
|
|
@@ -1364,15 +1372,22 @@ function BuilderRenderer(props) {
|
|
|
1364
1372
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
|
|
1365
1373
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
1366
1374
|
css === "" ? null : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { children: css }),
|
|
1367
|
-
doc.sections.map(
|
|
1375
|
+
doc.sections.map(
|
|
1376
|
+
(section) => section.type === "section" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: renderSection(section, ctx, registry) }, section.id) : null
|
|
1377
|
+
)
|
|
1368
1378
|
] });
|
|
1369
1379
|
}
|
|
1370
1380
|
|
|
1381
|
+
// src/context.ts
|
|
1382
|
+
|
|
1383
|
+
var BuilderContext = typeof _react.createContext === "function" ? _react.createContext.call(void 0, null) : null;
|
|
1384
|
+
var useBuilder = () => _react.useContext.call(void 0, BuilderContext);
|
|
1385
|
+
|
|
1371
1386
|
// src/part-view.tsx
|
|
1372
1387
|
|
|
1373
1388
|
var BoundaryBase = _nullishCoalesce(_react.Component, () => ( class {
|
|
1374
1389
|
}));
|
|
1375
|
-
var
|
|
1390
|
+
var Boundary = class extends BoundaryBase {
|
|
1376
1391
|
constructor() {
|
|
1377
1392
|
super(...arguments);
|
|
1378
1393
|
__publicField(this, "state", { failed: false });
|
|
@@ -1382,11 +1397,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
1382
1397
|
}
|
|
1383
1398
|
componentDidCatch(error, _info) {
|
|
1384
1399
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
1400
|
+
try {
|
|
1401
|
+
_optionalChain([this, 'access', _47 => _47.props, 'access', _48 => _48.onError, 'optionalCall', _49 => _49(error, { part: this.props.label })]);
|
|
1402
|
+
} catch (e5) {
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
componentDidUpdate(previous) {
|
|
1406
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
1407
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
1385
1408
|
}
|
|
1386
1409
|
render() {
|
|
1387
1410
|
return this.state.failed ? null : this.props.children;
|
|
1388
1411
|
}
|
|
1389
1412
|
};
|
|
1413
|
+
function PartBoundary({
|
|
1414
|
+
label,
|
|
1415
|
+
resetKey,
|
|
1416
|
+
children
|
|
1417
|
+
}) {
|
|
1418
|
+
const builder = useBuilder();
|
|
1419
|
+
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 });
|
|
1420
|
+
}
|
|
1390
1421
|
|
|
1391
1422
|
// src/custom/template-widget.tsx
|
|
1392
1423
|
|
|
@@ -1499,7 +1530,7 @@ var ROLES = new Set(_builderschema.ALLOWED_ROLES);
|
|
|
1499
1530
|
function attrAllowed(tag, name) {
|
|
1500
1531
|
if (_builderschema.DATA_ATTR_RE.test(name)) return !name.startsWith(_builderschema.RESERVED_DATA_PREFIX);
|
|
1501
1532
|
const own = Object.hasOwn(_builderschema.ALLOWED_ATTRS, tag) ? _builderschema.ALLOWED_ATTRS[tag] : void 0;
|
|
1502
|
-
return (_nullishCoalesce(_optionalChain([_builderschema.ALLOWED_ATTRS, 'access',
|
|
1533
|
+
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)));
|
|
1503
1534
|
}
|
|
1504
1535
|
function attrText(attr, env, scope) {
|
|
1505
1536
|
return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
|
|
@@ -1622,14 +1653,14 @@ function compile(snapshot, registry) {
|
|
|
1622
1653
|
const source = snapshot.template;
|
|
1623
1654
|
if (typeof source !== "string") return refuse("no template source");
|
|
1624
1655
|
const parsed = _builderschema.parseTemplate.call(void 0, source);
|
|
1625
|
-
if (!parsed.ok) return refuse(`template does not parse: ${_nullishCoalesce(_optionalChain([parsed, 'access',
|
|
1656
|
+
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"))}`);
|
|
1626
1657
|
const data = snapshot.data;
|
|
1627
1658
|
const issues = _builderschema.validateTemplate.call(void 0, parsed.ast, {
|
|
1628
1659
|
settings: snapshot.settings,
|
|
1629
1660
|
data: typeof data === "object" && data !== null ? data : {},
|
|
1630
1661
|
sources: registry.sources()
|
|
1631
1662
|
});
|
|
1632
|
-
if (issues.length > 0) return refuse(`template does not validate: ${_nullishCoalesce(_optionalChain([issues, 'access',
|
|
1663
|
+
if (issues.length > 0) return refuse(`template does not validate: ${_nullishCoalesce(_optionalChain([issues, 'access', _60 => _60[0], 'optionalAccess', _61 => _61.message]), () => ( "invalid"))}`);
|
|
1633
1664
|
if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(_builderschema.MAX_TEMPLATE_WEIGHT)} nodes`);
|
|
1634
1665
|
const css = scopedCss(snapshot.css, snapshot.type);
|
|
1635
1666
|
if (css === null) return refuse("its css does not pass the sanitiser");
|
|
@@ -1661,16 +1692,17 @@ function parseBody(raw) {
|
|
|
1661
1692
|
const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
|
|
1662
1693
|
if (columns === void 0 === (stack === void 0)) return null;
|
|
1663
1694
|
const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : _nullishCoalesce(stack, () => ( []));
|
|
1664
|
-
if (_optionalChain([stack, 'optionalAccess',
|
|
1695
|
+
if (_optionalChain([stack, 'optionalAccess', _62 => _62.some, 'call', _63 => _63((node) => isRecord3(node) && node.type === "inner-section")])) return null;
|
|
1665
1696
|
const parsed = _builderschema.pageDocumentSchema.safeParse({
|
|
1666
1697
|
schemaVersion: 1,
|
|
1667
1698
|
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1668
1699
|
});
|
|
1669
1700
|
if (!parsed.success) return null;
|
|
1670
|
-
const
|
|
1701
|
+
const wrapper = parsed.data.sections[0];
|
|
1702
|
+
const first = _nullishCoalesce((_optionalChain([wrapper, 'optionalAccess', _64 => _64.type]) === "section" ? _optionalChain([wrapper, 'access', _65 => _65.columns, 'access', _66 => _66[0], 'optionalAccess', _67 => _67.children]) : void 0), () => ( []));
|
|
1671
1703
|
if (columns !== void 0) {
|
|
1672
1704
|
const inner = first[0];
|
|
1673
|
-
return _optionalChain([inner, 'optionalAccess',
|
|
1705
|
+
return _optionalChain([inner, 'optionalAccess', _68 => _68.type]) === "inner-section" ? { columns: inner.columns } : null;
|
|
1674
1706
|
}
|
|
1675
1707
|
return { stack: first.filter((node) => node.type !== "inner-section") };
|
|
1676
1708
|
}
|
|
@@ -1724,7 +1756,7 @@ var DEVICES3 = ["tablet", "phone"];
|
|
|
1724
1756
|
function withoutAnchor(node) {
|
|
1725
1757
|
delete node.props.anchor;
|
|
1726
1758
|
const responsive = node.responsive;
|
|
1727
|
-
for (const device of DEVICES3) if (_optionalChain([responsive, 'optionalAccess',
|
|
1759
|
+
for (const device of DEVICES3) if (_optionalChain([responsive, 'optionalAccess', _69 => _69[device]]) !== void 0) delete responsive[device].anchor;
|
|
1728
1760
|
}
|
|
1729
1761
|
function instanceId(outer, inner) {
|
|
1730
1762
|
let a = 3735928559;
|
|
@@ -1744,9 +1776,9 @@ function build(input) {
|
|
|
1744
1776
|
const assets = {};
|
|
1745
1777
|
const hrefs = /* @__PURE__ */ new Map();
|
|
1746
1778
|
const innerData = {};
|
|
1747
|
-
const keep = (child) => _optionalChain([registry, 'access',
|
|
1748
|
-
const columns = _optionalChain([body, 'access',
|
|
1749
|
-
const stack = _optionalChain([body, 'access',
|
|
1779
|
+
const keep = (child) => _optionalChain([registry, 'access', _70 => _70.widget, 'call', _71 => _71(child.type, child.v), 'optionalAccess', _72 => _72.kind]) !== "composite";
|
|
1780
|
+
const columns = _optionalChain([body, 'access', _73 => _73.columns, 'optionalAccess', _74 => _74.map, 'call', _75 => _75((column2) => ({ ...column2, children: column2.children.filter(keep) }))]);
|
|
1781
|
+
const stack = _optionalChain([body, 'access', _76 => _76.stack, 'optionalAccess', _77 => _77.filter, 'call', _78 => _78(keep)]);
|
|
1750
1782
|
const widgets2 = columns !== void 0 ? columns.flatMap((column2) => column2.children) : _nullishCoalesce(stack, () => ( []));
|
|
1751
1783
|
for (const widget of widgets2) {
|
|
1752
1784
|
withoutAnchor(widget);
|
|
@@ -1781,15 +1813,15 @@ function build(input) {
|
|
|
1781
1813
|
const value = props[binding.setting];
|
|
1782
1814
|
for (const target of binding.targets) {
|
|
1783
1815
|
const inner = byId.get(target.node);
|
|
1784
|
-
const innerField = inner === void 0 ? void 0 : _optionalChain([registry, 'access',
|
|
1816
|
+
const innerField = inner === void 0 ? void 0 : _optionalChain([registry, 'access', _79 => _79.widget, 'call', _80 => _80(inner.type, inner.v), 'optionalAccess', _81 => _81.settings, 'access', _82 => _82.find, 'call', _83 => _83((f) => f.key === target.prop)]);
|
|
1785
1817
|
if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
|
|
1786
1818
|
const converted = convert(field, value);
|
|
1787
1819
|
if (_builderschema.validateSettingValue.call(void 0, innerField, converted) !== null) continue;
|
|
1788
1820
|
inner.props[target.prop] = converted;
|
|
1789
1821
|
const responsive = inner.responsive;
|
|
1790
1822
|
for (const device of DEVICES3) {
|
|
1791
|
-
if (_optionalChain([responsive, 'optionalAccess',
|
|
1792
|
-
const raw = _optionalChain([outer, 'access',
|
|
1823
|
+
if (_optionalChain([responsive, 'optionalAccess', _84 => _84[device]]) !== void 0) delete responsive[device][target.prop];
|
|
1824
|
+
const raw = _optionalChain([outer, 'access', _85 => _85.responsive, 'optionalAccess', _86 => _86[device]]);
|
|
1793
1825
|
const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
|
|
1794
1826
|
if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && _builderschema.validateSettingValue.call(void 0, innerField, raw[binding.setting]) === null) {
|
|
1795
1827
|
const target$ = _nullishCoalesce(inner.responsive, () => ( (inner.responsive = {})));
|
|
@@ -1804,7 +1836,7 @@ function build(input) {
|
|
|
1804
1836
|
for (const target of input$.targets) {
|
|
1805
1837
|
const inner = byId.get(target.node);
|
|
1806
1838
|
const def = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v);
|
|
1807
|
-
if (inner === void 0 || _optionalChain([def, 'optionalAccess',
|
|
1839
|
+
if (inner === void 0 || _optionalChain([def, 'optionalAccess', _87 => _87.data]) === void 0 || !Object.hasOwn(def.data, target.input)) continue;
|
|
1808
1840
|
inner.data = { ..._nullishCoalesce(inner.data, () => ( {})), [target.input]: { source: key } };
|
|
1809
1841
|
innerData[key] = data[name];
|
|
1810
1842
|
}
|
|
@@ -1822,7 +1854,7 @@ function build(input) {
|
|
|
1822
1854
|
schemaVersion: 1,
|
|
1823
1855
|
sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
|
|
1824
1856
|
};
|
|
1825
|
-
let weight = 2 + (_nullishCoalesce(_optionalChain([columns, 'optionalAccess',
|
|
1857
|
+
let weight = 2 + (_nullishCoalesce(_optionalChain([columns, 'optionalAccess', _88 => _88.length]), () => ( 0))) + (columns === void 0 ? 0 : 1);
|
|
1826
1858
|
for (const widget of widgets2) {
|
|
1827
1859
|
const component = registry.component(widget);
|
|
1828
1860
|
weight += 1 + (component === void 0 ? 0 : _nullishCoalesce(componentWeights.get(component), () => ( 0)));
|
|
@@ -1847,7 +1879,7 @@ function CompositeBody(props) {
|
|
|
1847
1879
|
locale,
|
|
1848
1880
|
assets: built.assets,
|
|
1849
1881
|
mediaOrigin,
|
|
1850
|
-
resolveLink: (target) => _nullishCoalesce(_nullishCoalesce(built.hrefs.get(JSON.stringify(target)), () => ( _optionalChain([resolveLink, 'optionalCall',
|
|
1882
|
+
resolveLink: (target) => _nullishCoalesce(_nullishCoalesce(built.hrefs.get(JSON.stringify(target)), () => ( _optionalChain([resolveLink, 'optionalCall', _89 => _89(target)]))), () => ( null))
|
|
1851
1883
|
}
|
|
1852
1884
|
);
|
|
1853
1885
|
}
|
|
@@ -1972,7 +2004,7 @@ function pagePathOf(settings, page, resolve) {
|
|
|
1972
2004
|
return _nullishCoalesce(_builderschema.safeUrl.call(void 0, resolve({ ...page, path }), "href", { mediaOrigin: "" }), () => ( path));
|
|
1973
2005
|
}
|
|
1974
2006
|
function originOf(storeUrl) {
|
|
1975
|
-
const origin = _optionalChain([storeUrl, 'optionalAccess',
|
|
2007
|
+
const origin = _optionalChain([storeUrl, 'optionalAccess', _90 => _90.replace, 'call', _91 => _91(/\/+$/u, "")]);
|
|
1976
2008
|
return origin !== void 0 && ORIGIN_RE.test(origin) ? origin : void 0;
|
|
1977
2009
|
}
|
|
1978
2010
|
function siteLocales(settings) {
|
|
@@ -38,7 +38,9 @@ function bindingsOf(node, registry) {
|
|
|
38
38
|
function collectBindings(doc, registry) {
|
|
39
39
|
const found = /* @__PURE__ */ new Map();
|
|
40
40
|
walkNodes(doc, (node) => {
|
|
41
|
-
if (node.type === "section" || node.type === "inner-section" || node.type === "column")
|
|
41
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column" || node.type === "saved-section") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
42
44
|
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
43
45
|
const key = bindingKey(binding);
|
|
44
46
|
if (!found.has(key)) found.set(key, binding);
|
|
@@ -1089,7 +1091,9 @@ function collect(doc, registry, assets, mediaOrigin) {
|
|
|
1089
1091
|
}
|
|
1090
1092
|
});
|
|
1091
1093
|
};
|
|
1092
|
-
doc.sections
|
|
1094
|
+
for (const root of doc.sections) {
|
|
1095
|
+
if (root.type === "section") section(root);
|
|
1096
|
+
}
|
|
1093
1097
|
return nodes;
|
|
1094
1098
|
}
|
|
1095
1099
|
var block = (id, decls) => {
|
|
@@ -1194,7 +1198,11 @@ function registryFor(doc, base) {
|
|
|
1194
1198
|
let registry = perDocument.get(snapshots);
|
|
1195
1199
|
if (registry === void 0) {
|
|
1196
1200
|
try {
|
|
1197
|
-
registry = base.withCustom(
|
|
1201
|
+
registry = base.withCustom(
|
|
1202
|
+
Object.values(snapshots).filter(
|
|
1203
|
+
(snapshot) => snapshot.kind !== "code"
|
|
1204
|
+
)
|
|
1205
|
+
);
|
|
1198
1206
|
} catch (error) {
|
|
1199
1207
|
warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
|
|
1200
1208
|
registry = base;
|
|
@@ -1364,15 +1372,22 @@ function BuilderRenderer(props) {
|
|
|
1364
1372
|
return /* @__PURE__ */ jsxs13("div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
|
|
1365
1373
|
/* @__PURE__ */ jsx17("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
1366
1374
|
css === "" ? null : /* @__PURE__ */ jsx17("style", { children: css }),
|
|
1367
|
-
doc.sections.map(
|
|
1375
|
+
doc.sections.map(
|
|
1376
|
+
(section) => section.type === "section" ? /* @__PURE__ */ jsx17(Fragment13, { children: renderSection(section, ctx, registry) }, section.id) : null
|
|
1377
|
+
)
|
|
1368
1378
|
] });
|
|
1369
1379
|
}
|
|
1370
1380
|
|
|
1381
|
+
// src/context.ts
|
|
1382
|
+
import { createContext, useContext } from "react";
|
|
1383
|
+
var BuilderContext = typeof createContext === "function" ? createContext(null) : null;
|
|
1384
|
+
var useBuilder = () => useContext(BuilderContext);
|
|
1385
|
+
|
|
1371
1386
|
// src/part-view.tsx
|
|
1372
1387
|
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
1373
1388
|
var BoundaryBase = Component ?? class {
|
|
1374
1389
|
};
|
|
1375
|
-
var
|
|
1390
|
+
var Boundary = class extends BoundaryBase {
|
|
1376
1391
|
constructor() {
|
|
1377
1392
|
super(...arguments);
|
|
1378
1393
|
__publicField(this, "state", { failed: false });
|
|
@@ -1382,11 +1397,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
1382
1397
|
}
|
|
1383
1398
|
componentDidCatch(error, _info) {
|
|
1384
1399
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
1400
|
+
try {
|
|
1401
|
+
this.props.onError?.(error, { part: this.props.label });
|
|
1402
|
+
} catch {
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
componentDidUpdate(previous) {
|
|
1406
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
1407
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
1385
1408
|
}
|
|
1386
1409
|
render() {
|
|
1387
1410
|
return this.state.failed ? null : this.props.children;
|
|
1388
1411
|
}
|
|
1389
1412
|
};
|
|
1413
|
+
function PartBoundary({
|
|
1414
|
+
label,
|
|
1415
|
+
resetKey,
|
|
1416
|
+
children
|
|
1417
|
+
}) {
|
|
1418
|
+
const builder = useBuilder();
|
|
1419
|
+
return /* @__PURE__ */ jsx18(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
1420
|
+
}
|
|
1390
1421
|
|
|
1391
1422
|
// src/custom/template-widget.tsx
|
|
1392
1423
|
import { Suspense } from "react";
|
|
@@ -1667,7 +1698,8 @@ function parseBody(raw) {
|
|
|
1667
1698
|
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1668
1699
|
});
|
|
1669
1700
|
if (!parsed.success) return null;
|
|
1670
|
-
const
|
|
1701
|
+
const wrapper = parsed.data.sections[0];
|
|
1702
|
+
const first = (wrapper?.type === "section" ? wrapper.columns[0]?.children : void 0) ?? [];
|
|
1671
1703
|
if (columns !== void 0) {
|
|
1672
1704
|
const inner = first[0];
|
|
1673
1705
|
return inner?.type === "inner-section" ? { columns: inner.columns } : null;
|
package/dist/index.cjs
CHANGED
|
@@ -294,7 +294,9 @@ function collect(doc, registry, assets, mediaOrigin) {
|
|
|
294
294
|
}
|
|
295
295
|
});
|
|
296
296
|
};
|
|
297
|
-
doc.sections
|
|
297
|
+
for (const root of doc.sections) {
|
|
298
|
+
if (root.type === "section") section(root);
|
|
299
|
+
}
|
|
298
300
|
return nodes;
|
|
299
301
|
}
|
|
300
302
|
var block = (id, decls) => {
|
|
@@ -339,7 +341,9 @@ function bindingsOf(node, registry) {
|
|
|
339
341
|
function collectBindings(doc, registry) {
|
|
340
342
|
const found = /* @__PURE__ */ new Map();
|
|
341
343
|
(0, import_builder_schema3.walkNodes)(doc, (node) => {
|
|
342
|
-
if (node.type === "section" || node.type === "inner-section" || node.type === "column")
|
|
344
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column" || node.type === "saved-section") {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
343
347
|
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
344
348
|
const key = bindingKey(binding);
|
|
345
349
|
if (!found.has(key)) found.set(key, binding);
|
|
@@ -455,7 +459,11 @@ function registryFor(doc, base) {
|
|
|
455
459
|
let registry = perDocument.get(snapshots);
|
|
456
460
|
if (registry === void 0) {
|
|
457
461
|
try {
|
|
458
|
-
registry = base.withCustom(
|
|
462
|
+
registry = base.withCustom(
|
|
463
|
+
Object.values(snapshots).filter(
|
|
464
|
+
(snapshot) => snapshot.kind !== "code"
|
|
465
|
+
)
|
|
466
|
+
);
|
|
459
467
|
} catch (error) {
|
|
460
468
|
warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
|
|
461
469
|
registry = base;
|
|
@@ -625,7 +633,9 @@ function BuilderRenderer(props) {
|
|
|
625
633
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
|
|
626
634
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
627
635
|
css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: css }),
|
|
628
|
-
doc.sections.map(
|
|
636
|
+
doc.sections.map(
|
|
637
|
+
(section) => section.type === "section" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderSection(section, ctx, registry) }, section.id) : null
|
|
638
|
+
)
|
|
629
639
|
] });
|
|
630
640
|
}
|
|
631
641
|
function validateRender(doc) {
|
|
@@ -684,7 +694,7 @@ var import_ui6 = require("@usethrottle/ui");
|
|
|
684
694
|
|
|
685
695
|
// src/context.ts
|
|
686
696
|
var import_react2 = require("react");
|
|
687
|
-
var BuilderContext = (0, import_react2.createContext)(null);
|
|
697
|
+
var BuilderContext = typeof import_react2.createContext === "function" ? (0, import_react2.createContext)(null) : null;
|
|
688
698
|
var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
|
|
689
699
|
|
|
690
700
|
// src/page.tsx
|
|
@@ -833,7 +843,7 @@ var import_react5 = require("react");
|
|
|
833
843
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
834
844
|
var BoundaryBase = import_react5.Component ?? class {
|
|
835
845
|
};
|
|
836
|
-
var
|
|
846
|
+
var Boundary = class extends BoundaryBase {
|
|
837
847
|
constructor() {
|
|
838
848
|
super(...arguments);
|
|
839
849
|
__publicField(this, "state", { failed: false });
|
|
@@ -843,11 +853,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
843
853
|
}
|
|
844
854
|
componentDidCatch(error, _info) {
|
|
845
855
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
856
|
+
try {
|
|
857
|
+
this.props.onError?.(error, { part: this.props.label });
|
|
858
|
+
} catch {
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
componentDidUpdate(previous) {
|
|
862
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
863
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
846
864
|
}
|
|
847
865
|
render() {
|
|
848
866
|
return this.state.failed ? null : this.props.children;
|
|
849
867
|
}
|
|
850
868
|
};
|
|
869
|
+
function PartBoundary({
|
|
870
|
+
label,
|
|
871
|
+
resetKey,
|
|
872
|
+
children
|
|
873
|
+
}) {
|
|
874
|
+
const builder = useBuilder();
|
|
875
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
876
|
+
}
|
|
851
877
|
function contextData(context) {
|
|
852
878
|
if (typeof context !== "object" || context === null) return {};
|
|
853
879
|
return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
|
|
@@ -1800,7 +1826,8 @@ function parseBody(raw) {
|
|
|
1800
1826
|
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1801
1827
|
});
|
|
1802
1828
|
if (!parsed.success) return null;
|
|
1803
|
-
const
|
|
1829
|
+
const wrapper = parsed.data.sections[0];
|
|
1830
|
+
const first = (wrapper?.type === "section" ? wrapper.columns[0]?.children : void 0) ?? [];
|
|
1804
1831
|
if (columns !== void 0) {
|
|
1805
1832
|
const inner = first[0];
|
|
1806
1833
|
return inner?.type === "inner-section" ? { columns: inner.columns } : null;
|
|
@@ -2059,6 +2086,14 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
2059
2086
|
// src/slot.tsx
|
|
2060
2087
|
var import_react14 = require("react");
|
|
2061
2088
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2089
|
+
function contextKey(context) {
|
|
2090
|
+
if (typeof context !== "object" || context === null) return "";
|
|
2091
|
+
return Object.values(context).map((value) => {
|
|
2092
|
+
const record = typeof value === "object" && value !== null ? value : {};
|
|
2093
|
+
const id = record["id"] ?? record["handle"] ?? record["slug"];
|
|
2094
|
+
return typeof id === "string" || typeof id === "number" ? String(id) : "";
|
|
2095
|
+
}).join("|");
|
|
2096
|
+
}
|
|
2062
2097
|
function BuilderSlot({ name, context }) {
|
|
2063
2098
|
const builder = useBuilder();
|
|
2064
2099
|
if (builder === null || builder.site.status !== "ok") return null;
|
|
@@ -2066,7 +2101,7 @@ function BuilderSlot({ name, context }) {
|
|
|
2066
2101
|
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2067
2102
|
return (
|
|
2068
2103
|
// Suspense inside the boundary: see parts.tsx.
|
|
2069
|
-
/* @__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 }) }) }) })
|
|
2104
|
+
/* @__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 }) }) }) })
|
|
2070
2105
|
);
|
|
2071
2106
|
}
|
|
2072
2107
|
|
|
@@ -2256,7 +2291,7 @@ var EMPTY = {};
|
|
|
2256
2291
|
function useParentFont() {
|
|
2257
2292
|
return (0, import_react15.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
|
|
2258
2293
|
}
|
|
2259
|
-
function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
2294
|
+
function BuilderProvider({ builderKey, client, packs, site, onError, children }) {
|
|
2260
2295
|
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2261
2296
|
const registryRef = (0, import_react15.useRef)(null);
|
|
2262
2297
|
if (registryRef.current?.key !== packsKey) {
|
|
@@ -2298,8 +2333,8 @@ function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
|
2298
2333
|
[site]
|
|
2299
2334
|
);
|
|
2300
2335
|
const value = (0, import_react15.useMemo)(
|
|
2301
|
-
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, resolveLink }),
|
|
2302
|
-
[builder, packs, registry, site, mediaOrigin, resolveLink]
|
|
2336
|
+
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink }),
|
|
2337
|
+
[builder, packs, registry, site, mediaOrigin, onError, resolveLink]
|
|
2303
2338
|
);
|
|
2304
2339
|
const design = (0, import_react15.useMemo)(
|
|
2305
2340
|
() => 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
|
@@ -248,7 +248,9 @@ function collect(doc, registry, assets, mediaOrigin) {
|
|
|
248
248
|
}
|
|
249
249
|
});
|
|
250
250
|
};
|
|
251
|
-
doc.sections
|
|
251
|
+
for (const root of doc.sections) {
|
|
252
|
+
if (root.type === "section") section(root);
|
|
253
|
+
}
|
|
252
254
|
return nodes;
|
|
253
255
|
}
|
|
254
256
|
var block = (id, decls) => {
|
|
@@ -293,7 +295,9 @@ function bindingsOf(node, registry) {
|
|
|
293
295
|
function collectBindings(doc, registry) {
|
|
294
296
|
const found = /* @__PURE__ */ new Map();
|
|
295
297
|
walkNodes(doc, (node) => {
|
|
296
|
-
if (node.type === "section" || node.type === "inner-section" || node.type === "column")
|
|
298
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column" || node.type === "saved-section") {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
297
301
|
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
298
302
|
const key = bindingKey(binding);
|
|
299
303
|
if (!found.has(key)) found.set(key, binding);
|
|
@@ -409,7 +413,11 @@ function registryFor(doc, base) {
|
|
|
409
413
|
let registry = perDocument.get(snapshots);
|
|
410
414
|
if (registry === void 0) {
|
|
411
415
|
try {
|
|
412
|
-
registry = base.withCustom(
|
|
416
|
+
registry = base.withCustom(
|
|
417
|
+
Object.values(snapshots).filter(
|
|
418
|
+
(snapshot) => snapshot.kind !== "code"
|
|
419
|
+
)
|
|
420
|
+
);
|
|
413
421
|
} catch (error) {
|
|
414
422
|
warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
|
|
415
423
|
registry = base;
|
|
@@ -579,7 +587,9 @@ function BuilderRenderer(props) {
|
|
|
579
587
|
return /* @__PURE__ */ jsxs("div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
|
|
580
588
|
/* @__PURE__ */ jsx2("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
581
589
|
css === "" ? null : /* @__PURE__ */ jsx2("style", { children: css }),
|
|
582
|
-
doc.sections.map(
|
|
590
|
+
doc.sections.map(
|
|
591
|
+
(section) => section.type === "section" ? /* @__PURE__ */ jsx2(Fragment, { children: renderSection(section, ctx, registry) }, section.id) : null
|
|
592
|
+
)
|
|
583
593
|
] });
|
|
584
594
|
}
|
|
585
595
|
function validateRender(doc) {
|
|
@@ -638,7 +648,7 @@ import { AppearanceContext, SiteDesignProvider, SlotOutletProvider, ThrottleUIPr
|
|
|
638
648
|
|
|
639
649
|
// src/context.ts
|
|
640
650
|
import { createContext, useContext } from "react";
|
|
641
|
-
var BuilderContext = createContext(null);
|
|
651
|
+
var BuilderContext = typeof createContext === "function" ? createContext(null) : null;
|
|
642
652
|
var useBuilder = () => useContext(BuilderContext);
|
|
643
653
|
|
|
644
654
|
// src/page.tsx
|
|
@@ -787,7 +797,7 @@ import { Component } from "react";
|
|
|
787
797
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
788
798
|
var BoundaryBase = Component ?? class {
|
|
789
799
|
};
|
|
790
|
-
var
|
|
800
|
+
var Boundary = class extends BoundaryBase {
|
|
791
801
|
constructor() {
|
|
792
802
|
super(...arguments);
|
|
793
803
|
__publicField(this, "state", { failed: false });
|
|
@@ -797,11 +807,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
797
807
|
}
|
|
798
808
|
componentDidCatch(error, _info) {
|
|
799
809
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
810
|
+
try {
|
|
811
|
+
this.props.onError?.(error, { part: this.props.label });
|
|
812
|
+
} catch {
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
componentDidUpdate(previous) {
|
|
816
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
817
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
800
818
|
}
|
|
801
819
|
render() {
|
|
802
820
|
return this.state.failed ? null : this.props.children;
|
|
803
821
|
}
|
|
804
822
|
};
|
|
823
|
+
function PartBoundary({
|
|
824
|
+
label,
|
|
825
|
+
resetKey,
|
|
826
|
+
children
|
|
827
|
+
}) {
|
|
828
|
+
const builder = useBuilder();
|
|
829
|
+
return /* @__PURE__ */ jsx6(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
830
|
+
}
|
|
805
831
|
function contextData(context) {
|
|
806
832
|
if (typeof context !== "object" || context === null) return {};
|
|
807
833
|
return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
|
|
@@ -1765,7 +1791,8 @@ function parseBody(raw) {
|
|
|
1765
1791
|
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1766
1792
|
});
|
|
1767
1793
|
if (!parsed.success) return null;
|
|
1768
|
-
const
|
|
1794
|
+
const wrapper = parsed.data.sections[0];
|
|
1795
|
+
const first = (wrapper?.type === "section" ? wrapper.columns[0]?.children : void 0) ?? [];
|
|
1769
1796
|
if (columns !== void 0) {
|
|
1770
1797
|
const inner = first[0];
|
|
1771
1798
|
return inner?.type === "inner-section" ? { columns: inner.columns } : null;
|
|
@@ -2024,6 +2051,14 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
2024
2051
|
// src/slot.tsx
|
|
2025
2052
|
import { Suspense as Suspense3 } from "react";
|
|
2026
2053
|
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
2054
|
+
function contextKey(context) {
|
|
2055
|
+
if (typeof context !== "object" || context === null) return "";
|
|
2056
|
+
return Object.values(context).map((value) => {
|
|
2057
|
+
const record = typeof value === "object" && value !== null ? value : {};
|
|
2058
|
+
const id = record["id"] ?? record["handle"] ?? record["slug"];
|
|
2059
|
+
return typeof id === "string" || typeof id === "number" ? String(id) : "";
|
|
2060
|
+
}).join("|");
|
|
2061
|
+
}
|
|
2027
2062
|
function BuilderSlot({ name, context }) {
|
|
2028
2063
|
const builder = useBuilder();
|
|
2029
2064
|
if (builder === null || builder.site.status !== "ok") return null;
|
|
@@ -2031,7 +2066,7 @@ function BuilderSlot({ name, context }) {
|
|
|
2031
2066
|
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2032
2067
|
return (
|
|
2033
2068
|
// Suspense inside the boundary: see parts.tsx.
|
|
2034
|
-
/* @__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 }) }) }) })
|
|
2069
|
+
/* @__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 }) }) }) })
|
|
2035
2070
|
);
|
|
2036
2071
|
}
|
|
2037
2072
|
|
|
@@ -2221,7 +2256,7 @@ var EMPTY = {};
|
|
|
2221
2256
|
function useParentFont() {
|
|
2222
2257
|
return useContext2(AppearanceContext)?.variables?.fontFamily;
|
|
2223
2258
|
}
|
|
2224
|
-
function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
2259
|
+
function BuilderProvider({ builderKey, client, packs, site, onError, children }) {
|
|
2225
2260
|
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2226
2261
|
const registryRef = useRef2(null);
|
|
2227
2262
|
if (registryRef.current?.key !== packsKey) {
|
|
@@ -2263,8 +2298,8 @@ function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
|
2263
2298
|
[site]
|
|
2264
2299
|
);
|
|
2265
2300
|
const value = useMemo(
|
|
2266
|
-
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, resolveLink }),
|
|
2267
|
-
[builder, packs, registry, site, mediaOrigin, resolveLink]
|
|
2301
|
+
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink }),
|
|
2302
|
+
[builder, packs, registry, site, mediaOrigin, onError, resolveLink]
|
|
2268
2303
|
);
|
|
2269
2304
|
const design = useMemo(
|
|
2270
2305
|
() => 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 _chunkIDGSPYRHcjs = require('./chunk-IDGSPYRH.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
|
|
58
|
+
const loaded = await _chunkIDGSPYRHcjs.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 =
|
|
78
|
+
const client = _chunkIDGSPYRHcjs.clientOf.call(void 0, options);
|
|
79
79
|
try {
|
|
80
|
-
const bundle = await
|
|
80
|
+
const bundle = await _chunkIDGSPYRHcjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
|
|
81
81
|
const page = bundle.page;
|
|
82
|
-
if (page === void 0 ||
|
|
83
|
-
return
|
|
82
|
+
if (page === void 0 || _chunkIDGSPYRHcjs.isRedirect.call(void 0, page)) return {};
|
|
83
|
+
return _chunkIDGSPYRHcjs.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.js
CHANGED
package/dist/server.cjs
CHANGED
|
@@ -12,25 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkIDGSPYRHcjs = require('./chunk-IDGSPYRH.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 =
|
|
21
|
+
const client = _chunkIDGSPYRHcjs.clientOf.call(void 0, options);
|
|
22
22
|
let bundle;
|
|
23
23
|
try {
|
|
24
|
-
bundle = await
|
|
24
|
+
bundle = await _chunkIDGSPYRHcjs.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
|
+
_chunkIDGSPYRHcjs.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 = _chunkIDGSPYRHcjs.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 _chunkIDGSPYRHcjs.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: _chunkIDGSPYRHcjs.partOf.call(void 0, bundle.header, data),
|
|
42
|
+
footer: _chunkIDGSPYRHcjs.partOf.call(void 0, bundle.footer, data),
|
|
43
|
+
slots: Object.fromEntries(names.map((name) => [name, _chunkIDGSPYRHcjs.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
|
+
_chunkIDGSPYRHcjs.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 = _chunkIDGSPYRHcjs.clientOf.call(void 0, options);
|
|
55
|
+
const origin = _chunkIDGSPYRHcjs.originOf.call(void 0, options.storeUrl);
|
|
56
56
|
if (origin === void 0) {
|
|
57
|
-
|
|
57
|
+
_chunkIDGSPYRHcjs.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 } = _chunkIDGSPYRHcjs.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 = _chunkIDGSPYRHcjs.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}${_chunkIDGSPYRHcjs.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
|
+
_chunkIDGSPYRHcjs.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
|
+
_chunkIDGSPYRHcjs.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 && (_chunkIDGSPYRHcjs.isRedirect.call(void 0, answer) || _chunkIDGSPYRHcjs.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 = _chunkIDGSPYRHcjs.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 = _chunkIDGSPYRHcjs.getBundle; exports.loadBuilderPage = _chunkIDGSPYRHcjs.loadBuilderPage; exports.loadSite = loadSite;
|
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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
|
|
61
|
-
"@usethrottle/
|
|
62
|
-
"@usethrottle/
|
|
60
|
+
"@usethrottle/builder": "^0.4.1",
|
|
61
|
+
"@usethrottle/builder-schema": "^0.2.0",
|
|
62
|
+
"@usethrottle/ui": "^0.1.2"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"next": ">=15",
|