@usethrottle/builder-react 0.0.0-stage → 0.1.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/CLAUDE.md +178 -0
- package/dist/bundle-x5Vxd-xE.d.cts +136 -0
- package/dist/bundle-x5Vxd-xE.d.ts +136 -0
- package/dist/chunk-DRQNR5GN.js +1929 -0
- package/dist/chunk-RWDLDDSF.cjs +1929 -0
- package/dist/index.cjs +2315 -0
- package/dist/index.d.cts +446 -0
- package/dist/index.d.ts +446 -0
- package/dist/index.js +2318 -0
- package/dist/next.cjs +95 -0
- package/dist/next.d.cts +41 -0
- package/dist/next.d.ts +41 -0
- package/dist/next.js +95 -0
- package/dist/server.cjs +74 -0
- package/dist/server.d.cts +59 -0
- package/dist/server.d.ts +59 -0
- package/dist/server.js +74 -0
- package/package.json +95 -3
- package/README.md +0 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2315 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
|
|
23
|
+
// src/index.ts
|
|
24
|
+
var src_exports = {};
|
|
25
|
+
__export(src_exports, {
|
|
26
|
+
AssetImage: () => AssetImage,
|
|
27
|
+
BASE_CSS: () => BASE_CSS,
|
|
28
|
+
BASIC_COMPONENTS: () => BASIC_COMPONENTS,
|
|
29
|
+
BuilderContext: () => BuilderContext,
|
|
30
|
+
BuilderFooter: () => BuilderFooter,
|
|
31
|
+
BuilderHeader: () => BuilderHeader,
|
|
32
|
+
BuilderNotFoundError: () => import_builder3.BuilderNotFoundError,
|
|
33
|
+
BuilderPage: () => BuilderPage,
|
|
34
|
+
BuilderPageView: () => BuilderPageView,
|
|
35
|
+
BuilderProvider: () => BuilderProvider,
|
|
36
|
+
BuilderRenderer: () => BuilderRenderer,
|
|
37
|
+
BuilderSlot: () => BuilderSlot,
|
|
38
|
+
BuilderUnavailableError: () => import_builder3.BuilderUnavailableError,
|
|
39
|
+
CUSTOM_WIDGET_CONTAINMENT: () => CUSTOM_WIDGET_CONTAINMENT,
|
|
40
|
+
CompositeWidget: () => CompositeWidget,
|
|
41
|
+
MAX_RENDERED_NODES: () => MAX_RENDERED_NODES,
|
|
42
|
+
NodeWrapper: () => NodeWrapper,
|
|
43
|
+
RenderBudget: () => RenderBudget,
|
|
44
|
+
RichText: () => RichText,
|
|
45
|
+
TemplateWidget: () => TemplateWidget,
|
|
46
|
+
WidgetStyle: () => WidgetStyle,
|
|
47
|
+
basicPack: () => basicPack,
|
|
48
|
+
bindingKey: () => bindingKey,
|
|
49
|
+
bindingsOf: () => bindingsOf,
|
|
50
|
+
collectBindings: () => collectBindings,
|
|
51
|
+
compileResponsiveCss: () => compileResponsiveCss,
|
|
52
|
+
createRendererRegistry: () => createRendererRegistry,
|
|
53
|
+
cssValue: () => cssValue,
|
|
54
|
+
customWidgetFactory: () => customWidgetFactory,
|
|
55
|
+
embedSrc: () => embedSrc,
|
|
56
|
+
fitsBudget: () => fitsBudget,
|
|
57
|
+
isFrozenAsset: () => isFrozenAsset,
|
|
58
|
+
parseRichText: () => parseRichText,
|
|
59
|
+
parseVideoUrl: () => parseVideoUrl,
|
|
60
|
+
pickLocale: () => pickLocale,
|
|
61
|
+
resolveBindings: () => resolveBindings,
|
|
62
|
+
useBuilder: () => useBuilder,
|
|
63
|
+
validateRender: () => validateRender
|
|
64
|
+
});
|
|
65
|
+
module.exports = __toCommonJS(src_exports);
|
|
66
|
+
|
|
67
|
+
// src/renderer.tsx
|
|
68
|
+
var import_react = require("react");
|
|
69
|
+
var import_builder_schema5 = require("@usethrottle/builder-schema");
|
|
70
|
+
|
|
71
|
+
// src/budget.ts
|
|
72
|
+
var import_builder_schema = require("@usethrottle/builder-schema");
|
|
73
|
+
var MAX_RENDERED_NODES = import_builder_schema.MAX_TEMPLATE_WEIGHT;
|
|
74
|
+
var RenderBudget = class {
|
|
75
|
+
constructor(limit = MAX_RENDERED_NODES) {
|
|
76
|
+
this.limit = limit;
|
|
77
|
+
__publicField(this, "spent", 0);
|
|
78
|
+
}
|
|
79
|
+
/** Takes `count` nodes. False, and nothing taken, when that would pass the limit. */
|
|
80
|
+
take(count = 1) {
|
|
81
|
+
if (this.spent + count > this.limit) return false;
|
|
82
|
+
this.spent += count;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
get used() {
|
|
86
|
+
return this.spent;
|
|
87
|
+
}
|
|
88
|
+
get exhausted() {
|
|
89
|
+
return this.spent >= this.limit;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var fitsBudget = (ast, limit = MAX_RENDERED_NODES) => (0, import_builder_schema.templateWeight)(ast) <= limit;
|
|
93
|
+
|
|
94
|
+
// src/css-compiler.ts
|
|
95
|
+
var import_builder_schema2 = require("@usethrottle/builder-schema");
|
|
96
|
+
|
|
97
|
+
// src/warn.ts
|
|
98
|
+
var seen = /* @__PURE__ */ new Set();
|
|
99
|
+
function warnOnce(key, message) {
|
|
100
|
+
if (seen.has(key)) return;
|
|
101
|
+
seen.add(key);
|
|
102
|
+
console.warn(`[throttle-builder] ${message}`);
|
|
103
|
+
}
|
|
104
|
+
var isDevelopment = () => typeof process === "undefined" || process.env?.NODE_ENV !== "production";
|
|
105
|
+
|
|
106
|
+
// src/css-compiler.ts
|
|
107
|
+
var TABLET_QUERY = "(max-width:1024px)";
|
|
108
|
+
var PHONE_QUERY = "(max-width:767px)";
|
|
109
|
+
var SAFE_VALUE = /^[A-Za-z0-9#%.,()\-+*/_: ]{1,200}$/;
|
|
110
|
+
var URL_QUOTE_SAFE = /^[^\s"'\\()<>{};]+$/;
|
|
111
|
+
var ID_RE = /^[a-z0-9]{8,24}$/;
|
|
112
|
+
var PROPERTY_RE = /^--(?:b|w|tb)-[A-Za-z][A-Za-z0-9-]{0,39}$/;
|
|
113
|
+
var COLOR_TOKEN = /* @__PURE__ */ new Set([
|
|
114
|
+
"primary",
|
|
115
|
+
"primary-foreground",
|
|
116
|
+
"background",
|
|
117
|
+
"surface",
|
|
118
|
+
"foreground",
|
|
119
|
+
"muted",
|
|
120
|
+
"muted-foreground",
|
|
121
|
+
"border",
|
|
122
|
+
"border-control",
|
|
123
|
+
"accent",
|
|
124
|
+
"sale",
|
|
125
|
+
"success",
|
|
126
|
+
"warning",
|
|
127
|
+
"danger"
|
|
128
|
+
]);
|
|
129
|
+
var SPACING_TOKEN = /* @__PURE__ */ new Set(["xs", "s", "m", "l", "xl", "2xl"]);
|
|
130
|
+
var SIZE_TOKEN = /* @__PURE__ */ new Set(["xs", "s", "m", "l", "xl", "2xl", "3xl"]);
|
|
131
|
+
var ALIGN = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]);
|
|
132
|
+
var SELECT_OPTION = /^[a-z0-9][a-z0-9:-]{0,39}$/;
|
|
133
|
+
var px = (value) => `${String(Math.round(value * 100) / 100)}px`;
|
|
134
|
+
function colour(value) {
|
|
135
|
+
if (typeof value !== "string") return null;
|
|
136
|
+
if (value.startsWith("token:")) {
|
|
137
|
+
const name = value.slice(6);
|
|
138
|
+
return COLOR_TOKEN.has(name) ? `var(--tb-color-${name})` : null;
|
|
139
|
+
}
|
|
140
|
+
return /^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/.test(value) ? value : null;
|
|
141
|
+
}
|
|
142
|
+
function spacing(value) {
|
|
143
|
+
if (value === "none") return "0px";
|
|
144
|
+
if (typeof value === "string") return SPACING_TOKEN.has(value) ? `var(--tb-space-${value})` : null;
|
|
145
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 400 ? px(value) : null;
|
|
146
|
+
}
|
|
147
|
+
function fontSize(value) {
|
|
148
|
+
if (typeof value === "string") return SIZE_TOKEN.has(value) ? `var(--tb-text-${value})` : null;
|
|
149
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 8 && value <= 200 ? px(value) : null;
|
|
150
|
+
}
|
|
151
|
+
function cssValue(control, value) {
|
|
152
|
+
switch (control) {
|
|
153
|
+
case "color":
|
|
154
|
+
return colour(value);
|
|
155
|
+
case "spacing":
|
|
156
|
+
return spacing(value);
|
|
157
|
+
case "font-size":
|
|
158
|
+
return fontSize(value);
|
|
159
|
+
case "alignment":
|
|
160
|
+
return typeof value === "string" && ALIGN.has(value) ? value : null;
|
|
161
|
+
case "number":
|
|
162
|
+
return typeof value === "number" && Number.isFinite(value) ? String(value) : null;
|
|
163
|
+
case "toggle":
|
|
164
|
+
return typeof value === "boolean" ? value ? "1" : "0" : null;
|
|
165
|
+
case "select":
|
|
166
|
+
return typeof value === "string" && SELECT_OPTION.test(value) ? value : null;
|
|
167
|
+
default:
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function put(out, property, value) {
|
|
172
|
+
if (value === null) return;
|
|
173
|
+
if (!PROPERTY_RE.test(property) || !SAFE_VALUE.test(value)) {
|
|
174
|
+
if (isDevelopment()) warnOnce(`css:${property}`, `Dropped an unsafe value for ${property}`);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
out.set(property, value);
|
|
178
|
+
}
|
|
179
|
+
var COMMON_BY_KEY = new Map(import_builder_schema2.COMMON_WIDGET_SETTINGS.map((field) => [field.key, field]));
|
|
180
|
+
function widgetDecls(node, device, registry) {
|
|
181
|
+
const out = /* @__PURE__ */ new Map();
|
|
182
|
+
const def = registry.widget(node.type, node.v);
|
|
183
|
+
if (def === void 0) return out;
|
|
184
|
+
const fields = new Map([...COMMON_BY_KEY, ...def.settings.map((f) => [f.key, f])]);
|
|
185
|
+
const defaults = {};
|
|
186
|
+
for (const field of fields.values()) if (field.output === "css") defaults[field.key] = field.default;
|
|
187
|
+
const resolved = (0, import_builder_schema2.resolveResponsive)({ ...defaults, ...node.props }, node.responsive, device);
|
|
188
|
+
const prefix = node.type.startsWith("custom.") ? "--w-" : "--b-";
|
|
189
|
+
for (const field of fields.values()) {
|
|
190
|
+
if (field.output !== "css") continue;
|
|
191
|
+
const value = resolved[field.key];
|
|
192
|
+
if (value === null || value === void 0) continue;
|
|
193
|
+
if (field.key === "hidden") {
|
|
194
|
+
if (value === true) put(out, "--tb-hide", "none");
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
put(out, `${prefix}${field.key}`, cssValue(field.control, value));
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
var ALIGN_ITEMS = { top: "flex-start", center: "center", bottom: "flex-end", stretch: "stretch" };
|
|
202
|
+
var BG_POSITION = /* @__PURE__ */ new Set(["center", "top", "bottom", "left", "right", "top left", "top right", "bottom left", "bottom right"]);
|
|
203
|
+
var BG_SIZE = /* @__PURE__ */ new Set(["cover", "contain", "auto"]);
|
|
204
|
+
function backgroundDecls(out, bg, assets, mediaOrigin) {
|
|
205
|
+
if (bg === void 0) return;
|
|
206
|
+
put(out, "--tb-bg", bg.color === void 0 ? null : colour(bg.color));
|
|
207
|
+
put(out, "--tb-overlay", bg.overlay === void 0 ? null : colour(bg.overlay));
|
|
208
|
+
if (bg.position !== void 0 && BG_POSITION.has(bg.position)) put(out, "--tb-bgpos", bg.position);
|
|
209
|
+
if (bg.size !== void 0 && BG_SIZE.has(bg.size)) put(out, "--tb-bgsize", bg.size);
|
|
210
|
+
const asset = bg.image === void 0 || assets === void 0 || !Object.hasOwn(assets, bg.image) ? void 0 : assets[bg.image];
|
|
211
|
+
if (asset !== void 0 && (0, import_builder_schema2.safeUrl)(asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
|
|
212
|
+
out.set("--tb-bgimg", `url("${asset.url}")`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function sectionDecls(section, device, assets, mediaOrigin) {
|
|
216
|
+
const out = /* @__PURE__ */ new Map();
|
|
217
|
+
const p = (0, import_builder_schema2.resolveResponsive)(section.props, section.responsive, device);
|
|
218
|
+
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
219
|
+
const full = p.width === "full";
|
|
220
|
+
put(out, "--tb-maxw", full ? "none" : px(typeof p.contentWidth === "number" ? p.contentWidth : 1200));
|
|
221
|
+
put(out, "--tb-gap", p.gap === void 0 ? null : spacing(p.gap));
|
|
222
|
+
put(out, "--tb-pady", p.paddingY === void 0 ? null : spacing(p.paddingY));
|
|
223
|
+
put(out, "--tb-padx", p.paddingX === void 0 ? null : spacing(p.paddingX));
|
|
224
|
+
if (typeof p.minHeight === "number" && p.minHeight > 0 && p.minHeight <= 2e3) put(out, "--tb-minh", px(p.minHeight));
|
|
225
|
+
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-valign", ALIGN_ITEMS[p.verticalAlign]);
|
|
226
|
+
backgroundDecls(out, p.background, assets, mediaOrigin);
|
|
227
|
+
const widths = (0, import_builder_schema2.resolveColumnWidths)(section, device);
|
|
228
|
+
const rows = (0, import_builder_schema2.wrapColumnRows)(widths);
|
|
229
|
+
const stacked = rows.every((row) => row.length === 1);
|
|
230
|
+
put(out, "--tb-flow", stacked && p.stackOrder === "reverse" ? "column-reverse nowrap" : "row wrap");
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
function columnWidthDecls(section, device) {
|
|
234
|
+
const widths = (0, import_builder_schema2.resolveColumnWidths)(section, device);
|
|
235
|
+
const result = section.columns.map(() => /* @__PURE__ */ new Map());
|
|
236
|
+
for (const row of (0, import_builder_schema2.wrapColumnRows)(widths)) {
|
|
237
|
+
for (const index of row) {
|
|
238
|
+
put(result[index], "--tb-cw", String(Math.round(widths[index] / 100 * 1e4) / 1e4));
|
|
239
|
+
put(result[index], "--tb-cn", String(row.length - 1));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
function columnDecls(section, index, device, assets, mediaOrigin, widths) {
|
|
245
|
+
const column = section.columns[index];
|
|
246
|
+
const out = new Map(widths);
|
|
247
|
+
const p = (0, import_builder_schema2.resolveColumnProps)(column.props, column.responsive, device);
|
|
248
|
+
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
249
|
+
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-self", ALIGN_ITEMS[p.verticalAlign]);
|
|
250
|
+
put(out, "--tb-pad", p.padding === void 0 ? null : spacing(p.padding));
|
|
251
|
+
backgroundDecls(out, p.background, assets, mediaOrigin);
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
function collect(doc, registry, assets, mediaOrigin) {
|
|
255
|
+
const nodes = [];
|
|
256
|
+
const widget = (node) => {
|
|
257
|
+
if (!ID_RE.test(node.id)) return;
|
|
258
|
+
nodes.push({
|
|
259
|
+
id: node.id,
|
|
260
|
+
decls: {
|
|
261
|
+
desktop: widgetDecls(node, "desktop", registry),
|
|
262
|
+
tablet: widgetDecls(node, "tablet", registry),
|
|
263
|
+
phone: widgetDecls(node, "phone", registry)
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
const section = (node) => {
|
|
268
|
+
if (ID_RE.test(node.id)) {
|
|
269
|
+
nodes.push({
|
|
270
|
+
id: node.id,
|
|
271
|
+
decls: {
|
|
272
|
+
desktop: sectionDecls(node, "desktop", assets, mediaOrigin),
|
|
273
|
+
tablet: sectionDecls(node, "tablet", assets, mediaOrigin),
|
|
274
|
+
phone: sectionDecls(node, "phone", assets, mediaOrigin)
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
const widths = { desktop: columnWidthDecls(node, "desktop"), tablet: columnWidthDecls(node, "tablet"), phone: columnWidthDecls(node, "phone") };
|
|
279
|
+
node.columns.forEach((column, index) => {
|
|
280
|
+
if (ID_RE.test(column.id)) {
|
|
281
|
+
nodes.push({
|
|
282
|
+
id: column.id,
|
|
283
|
+
decls: {
|
|
284
|
+
desktop: columnDecls(node, index, "desktop", assets, mediaOrigin, widths.desktop[index]),
|
|
285
|
+
tablet: columnDecls(node, index, "tablet", assets, mediaOrigin, widths.tablet[index]),
|
|
286
|
+
phone: columnDecls(node, index, "phone", assets, mediaOrigin, widths.phone[index])
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
for (const child of column.children) {
|
|
291
|
+
if (child.type === "inner-section") section(child);
|
|
292
|
+
else widget(child);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
doc.sections.forEach(section);
|
|
297
|
+
return nodes;
|
|
298
|
+
}
|
|
299
|
+
var block = (id, decls) => {
|
|
300
|
+
const body = [...decls].map(([property, value]) => `${property}:${value}`).join(";");
|
|
301
|
+
return body === "" ? "" : `[data-b-id="${id}"]{${body}}`;
|
|
302
|
+
};
|
|
303
|
+
function changed(prev, next) {
|
|
304
|
+
const out = [...next].filter(([property, value]) => prev.get(property) !== value);
|
|
305
|
+
for (const property of prev.keys()) if (!next.has(property)) out.push([property, "initial"]);
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
function compileResponsiveCss(doc, registry, assets = doc.assets, mediaOrigin = "") {
|
|
309
|
+
const nodes = collect(doc, registry, assets, mediaOrigin);
|
|
310
|
+
const base = nodes.map((n) => block(n.id, n.decls.desktop)).join("");
|
|
311
|
+
const tablet = nodes.map((n) => block(n.id, changed(n.decls.desktop, n.decls.tablet))).join("");
|
|
312
|
+
const phone = nodes.map((n) => block(n.id, changed(n.decls.tablet, n.decls.phone))).join("");
|
|
313
|
+
return base + (tablet === "" ? "" : `@media ${TABLET_QUERY}{${tablet}}`) + (phone === "" ? "" : `@media ${PHONE_QUERY}{${phone}}`);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/data.ts
|
|
317
|
+
var import_builder_schema3 = require("@usethrottle/builder-schema");
|
|
318
|
+
function stable(value) {
|
|
319
|
+
if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
|
|
320
|
+
if (typeof value === "object" && value !== null) {
|
|
321
|
+
const entries2 = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
322
|
+
return `{${entries2.map(([k, v]) => `${JSON.stringify(k)}:${stable(v)}`).join(",")}}`;
|
|
323
|
+
}
|
|
324
|
+
return JSON.stringify(value) ?? "null";
|
|
325
|
+
}
|
|
326
|
+
function bindingKey(binding) {
|
|
327
|
+
return "params" in binding ? `${binding.source}?${stable(binding.params)}` : binding.source;
|
|
328
|
+
}
|
|
329
|
+
var isContextBinding = (binding) => binding.source.startsWith("context.");
|
|
330
|
+
function bindingsOf(node, registry) {
|
|
331
|
+
const def = registry.widget(node.type, node.v);
|
|
332
|
+
const out = {};
|
|
333
|
+
for (const [name, input] of Object.entries(def?.data ?? {})) {
|
|
334
|
+
if (input.default !== void 0) out[name] = input.default;
|
|
335
|
+
}
|
|
336
|
+
return { ...out, ...node.data ?? {} };
|
|
337
|
+
}
|
|
338
|
+
function collectBindings(doc, registry) {
|
|
339
|
+
const found = /* @__PURE__ */ new Map();
|
|
340
|
+
(0, import_builder_schema3.walkNodes)(doc, (node) => {
|
|
341
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column") return;
|
|
342
|
+
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
343
|
+
const key = bindingKey(binding);
|
|
344
|
+
if (!found.has(key)) found.set(key, binding);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
return found;
|
|
348
|
+
}
|
|
349
|
+
async function resolveBindings(bindings, registry, ctx, options) {
|
|
350
|
+
const jobs = [];
|
|
351
|
+
for (const [key, binding] of bindings) {
|
|
352
|
+
if (isContextBinding(binding) || !("params" in binding)) continue;
|
|
353
|
+
const descriptor = registry.source(binding.source);
|
|
354
|
+
const resolve = registry.resolver(binding.source);
|
|
355
|
+
if (descriptor === void 0 || resolve === void 0) continue;
|
|
356
|
+
if (options.include === "static" && descriptor.perShopper) continue;
|
|
357
|
+
if (options.include === "shopper" && !descriptor.perShopper) continue;
|
|
358
|
+
jobs.push(
|
|
359
|
+
resolve(binding.params, ctx).then(
|
|
360
|
+
(value) => [key, value],
|
|
361
|
+
(error) => {
|
|
362
|
+
warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
)
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
const settled = await Promise.all(jobs);
|
|
369
|
+
return Object.fromEntries(settled.filter((entry) => entry !== null));
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/node-wrapper.tsx
|
|
373
|
+
var import_builder_schema4 = require("@usethrottle/builder-schema");
|
|
374
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
375
|
+
var CUSTOM_WIDGET_CONTAINMENT = {
|
|
376
|
+
contain: "layout paint",
|
|
377
|
+
isolation: "isolate",
|
|
378
|
+
overflow: "clip"
|
|
379
|
+
};
|
|
380
|
+
var PART_NAME = {
|
|
381
|
+
section: "builder-section",
|
|
382
|
+
column: "builder-column",
|
|
383
|
+
widget: "builder-widget"
|
|
384
|
+
};
|
|
385
|
+
function NodeWrapper(props) {
|
|
386
|
+
const { id, part, type, className, anchor, custom, missing, edit, children } = props;
|
|
387
|
+
const Tag = props.as ?? "div";
|
|
388
|
+
const handlers = edit === void 0 ? {} : {
|
|
389
|
+
onClickCapture: (event) => {
|
|
390
|
+
const target = event.target;
|
|
391
|
+
if (target?.closest?.("a[href]") != null) event.preventDefault();
|
|
392
|
+
},
|
|
393
|
+
onClick: (event) => {
|
|
394
|
+
event.stopPropagation();
|
|
395
|
+
edit.onSelect(id);
|
|
396
|
+
},
|
|
397
|
+
onMouseOver: (event) => {
|
|
398
|
+
event.stopPropagation();
|
|
399
|
+
edit.onHover(id);
|
|
400
|
+
},
|
|
401
|
+
onMouseLeave: () => edit.onHover(null)
|
|
402
|
+
};
|
|
403
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
404
|
+
Tag,
|
|
405
|
+
{
|
|
406
|
+
className,
|
|
407
|
+
"data-b-id": id,
|
|
408
|
+
"data-throttle-part": PART_NAME[part],
|
|
409
|
+
...type === void 0 ? {} : { "data-b-type": type },
|
|
410
|
+
...custom === true && type !== void 0 ? { "data-b-w": type } : {},
|
|
411
|
+
...missing === true ? { "data-b-missing": "" } : {},
|
|
412
|
+
...typeof anchor === "string" && import_builder_schema4.ANCHOR_RE.test(anchor) ? { id: anchor } : {},
|
|
413
|
+
...custom === true ? { style: CUSTOM_WIDGET_CONTAINMENT } : {},
|
|
414
|
+
...handlers,
|
|
415
|
+
children
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/styles.ts
|
|
421
|
+
var BASE_CSS = `@layer throttle{
|
|
422
|
+
:root{--tb-scale:1;--tb-space-xs:calc(.25rem*var(--tb-scale));--tb-space-s:calc(.5rem*var(--tb-scale));--tb-space-m:calc(1rem*var(--tb-scale));--tb-space-l:calc(1.5rem*var(--tb-scale));--tb-space-xl:calc(2.5rem*var(--tb-scale));--tb-space-2xl:calc(4rem*var(--tb-scale));
|
|
423
|
+
--tb-text-xs:.75rem;--tb-text-s:.875rem;--tb-text-m:1rem;--tb-text-l:1.25rem;--tb-text-xl:1.5rem;--tb-text-2xl:2rem;--tb-text-3xl:2.75rem}
|
|
424
|
+
.tb-root{display:block;inline-size:100%}
|
|
425
|
+
.tb-section,.tb-col,.tb-w{--tb-hide:initial}
|
|
426
|
+
.tb-section,.tb-col{--tb-bg:initial;--tb-bgimg:initial;--tb-bgpos:initial;--tb-bgsize:initial;--tb-overlay:initial}
|
|
427
|
+
.tb-section{--tb-valign:initial;--tb-minh:initial;--tb-pady:initial;--tb-padx:initial;--tb-gap:initial;--tb-maxw:initial;--tb-flow:initial}
|
|
428
|
+
.tb-col{--tb-pad:initial;--tb-self:initial}
|
|
429
|
+
.tb-section{box-sizing:border-box;position:relative;display:var(--tb-hide,flex);flex-direction:column;justify-content:var(--tb-valign,flex-start);min-block-size:var(--tb-minh,0px);padding-block:var(--tb-pady,0px);padding-inline:var(--tb-padx,0px);background-color:var(--tb-bg,transparent);background-image:var(--tb-bgimg,none);background-position:var(--tb-bgpos,center);background-size:var(--tb-bgsize,cover);background-repeat:no-repeat}
|
|
430
|
+
.tb-section::before{content:"";position:absolute;inset:0;background:var(--tb-overlay,transparent);pointer-events:none}
|
|
431
|
+
.tb-inner{box-sizing:border-box;position:relative;inline-size:100%;max-inline-size:var(--tb-maxw,1200px);margin-inline:auto}
|
|
432
|
+
.tb-row{display:flex;flex-flow:var(--tb-flow,row wrap);gap:var(--tb-gap,0px);align-items:stretch}
|
|
433
|
+
.tb-col{box-sizing:border-box;display:var(--tb-hide,flex);flex-direction:column;flex:0 0 auto;inline-size:calc((100% - var(--tb-cn,0)*var(--tb-gap,0px))*var(--tb-cw,1));min-inline-size:0;align-self:var(--tb-self,stretch);padding:var(--tb-pad,0px);background-color:var(--tb-bg,transparent);background-image:var(--tb-bgimg,none);background-position:var(--tb-bgpos,center);background-size:var(--tb-bgsize,cover);background-repeat:no-repeat}
|
|
434
|
+
.tb-w{display:var(--tb-hide,block);min-inline-size:0;margin-block-start:var(--b-spacingTop,var(--w-spacingTop,0px));margin-block-end:var(--b-spacingBottom,var(--w-spacingBottom,0px))}
|
|
435
|
+
.tb-missing{padding:var(--tb-space-s);border:1px dashed var(--tb-color-border-control,currentColor);font-size:var(--tb-text-s)}
|
|
436
|
+
@media (min-width:1025px){.tb-v:not(.tb-only-desktop){display:none!important}}
|
|
437
|
+
@media (min-width:768px) and (max-width:1024px){.tb-v:not(.tb-only-tablet){display:none!important}}
|
|
438
|
+
@media (max-width:767px){.tb-v:not(.tb-only-phone){display:none!important}}
|
|
439
|
+
}`;
|
|
440
|
+
|
|
441
|
+
// src/renderer.tsx
|
|
442
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
443
|
+
var DEVICES = ["desktop", "tablet", "phone"];
|
|
444
|
+
var COMMON_BY_KEY2 = new Map(import_builder_schema5.COMMON_WIDGET_SETTINGS.map((f) => [f.key, f]));
|
|
445
|
+
var withCustomCache = /* @__PURE__ */ new WeakMap();
|
|
446
|
+
function registryFor(doc, base) {
|
|
447
|
+
const snapshots = doc.customWidgets;
|
|
448
|
+
if (snapshots === void 0) return base;
|
|
449
|
+
let perDocument = withCustomCache.get(base);
|
|
450
|
+
if (perDocument === void 0) {
|
|
451
|
+
perDocument = /* @__PURE__ */ new WeakMap();
|
|
452
|
+
withCustomCache.set(base, perDocument);
|
|
453
|
+
}
|
|
454
|
+
let registry = perDocument.get(snapshots);
|
|
455
|
+
if (registry === void 0) {
|
|
456
|
+
try {
|
|
457
|
+
registry = base.withCustom(Object.values(snapshots));
|
|
458
|
+
} catch (error) {
|
|
459
|
+
warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
|
|
460
|
+
registry = base;
|
|
461
|
+
}
|
|
462
|
+
perDocument.set(snapshots, registry);
|
|
463
|
+
}
|
|
464
|
+
return registry;
|
|
465
|
+
}
|
|
466
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
467
|
+
function pickLocale(value, locale) {
|
|
468
|
+
const lang = locale.split("-")[0] ?? locale;
|
|
469
|
+
for (const key of [locale, lang, "en"]) {
|
|
470
|
+
const text = Object.hasOwn(value, key) ? value[key] : void 0;
|
|
471
|
+
if (typeof text === "string" && text !== "") return text;
|
|
472
|
+
}
|
|
473
|
+
for (const text of Object.values(value)) if (typeof text === "string" && text !== "") return text;
|
|
474
|
+
return "";
|
|
475
|
+
}
|
|
476
|
+
function onOrigin(asset, mediaOrigin) {
|
|
477
|
+
if ((0, import_builder_schema5.safeUrl)(asset.url, "src", { mediaOrigin }) === null) return null;
|
|
478
|
+
return { ...asset, variants: asset.variants.filter((v) => (0, import_builder_schema5.safeUrl)(v.url, "src", { mediaOrigin }) !== null) };
|
|
479
|
+
}
|
|
480
|
+
function prepare(field, value, ctx) {
|
|
481
|
+
if (field === void 0 || value === null) return value;
|
|
482
|
+
if (field.translatable === true && isRecord(value)) return pickLocale(value, ctx.locale);
|
|
483
|
+
if (field.control === "image" && typeof value === "string") {
|
|
484
|
+
const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
|
|
485
|
+
return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
|
|
486
|
+
}
|
|
487
|
+
if (field.control === "link" && isRecord(value) && typeof value.kind === "string") {
|
|
488
|
+
const target = value;
|
|
489
|
+
const raw = ctx.resolveLink?.(target) ?? (target.kind === "url" ? target.href : null);
|
|
490
|
+
return { ...value, href: (0, import_builder_schema5.safeUrl)(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
|
|
491
|
+
}
|
|
492
|
+
return value;
|
|
493
|
+
}
|
|
494
|
+
function settingsAt(node, fields, device, ctx) {
|
|
495
|
+
const base = {};
|
|
496
|
+
for (const field of fields.values()) base[field.key] = field.default;
|
|
497
|
+
const resolved = (0, import_builder_schema5.resolveResponsive)({ ...base, ...node.props }, node.responsive, device);
|
|
498
|
+
const out = {};
|
|
499
|
+
for (const [key, value] of Object.entries(resolved)) out[key] = prepare(fields.get(key), value, ctx);
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
function variantsOf(node, def, fields, ctx) {
|
|
503
|
+
const markup = [...fields.values()].filter((f) => f.output === "markup").map((f) => f.key);
|
|
504
|
+
const groups = /* @__PURE__ */ new Map();
|
|
505
|
+
for (const device of DEVICES) {
|
|
506
|
+
const props = settingsAt(node, fields, device, ctx);
|
|
507
|
+
const signature = stable(markup.map((key) => props[key] ?? null));
|
|
508
|
+
const group = groups.get(signature);
|
|
509
|
+
if (group === void 0) groups.set(signature, { devices: [device], props });
|
|
510
|
+
else group.devices.push(device);
|
|
511
|
+
}
|
|
512
|
+
void def;
|
|
513
|
+
return [...groups.values()];
|
|
514
|
+
}
|
|
515
|
+
function hiddenEverywhere(props, responsive) {
|
|
516
|
+
return DEVICES.every(
|
|
517
|
+
(device) => (0, import_builder_schema5.resolveResponsive)({ hidden: props.hidden ?? false }, responsive, device).hidden === true
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
var variantClass = (variant) => `tb-v ${variant.devices.map((d) => `tb-only-${d}`).join(" ")}`;
|
|
521
|
+
function renderWidget(node, ctx, registry) {
|
|
522
|
+
const def = registry.widget(node.type, node.v);
|
|
523
|
+
const Component2 = def === void 0 ? void 0 : registry.component(node);
|
|
524
|
+
if (def === void 0 || Component2 === void 0) {
|
|
525
|
+
if (isDevelopment()) {
|
|
526
|
+
warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
|
|
527
|
+
}
|
|
528
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
|
|
529
|
+
}
|
|
530
|
+
if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
|
|
531
|
+
const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
|
|
532
|
+
const variants = variantsOf(node, def, fields, ctx);
|
|
533
|
+
const data = {};
|
|
534
|
+
for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
|
|
535
|
+
const key = bindingKey(binding);
|
|
536
|
+
const value = Object.hasOwn(ctx.data, key) ? ctx.data[key] : void 0;
|
|
537
|
+
if (value !== void 0) data[name] = value;
|
|
538
|
+
}
|
|
539
|
+
const custom = node.type.startsWith("custom.");
|
|
540
|
+
const edit = ctx.edit;
|
|
541
|
+
return variants.map((variant, index) => {
|
|
542
|
+
const anchor = variant.props.anchor;
|
|
543
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
544
|
+
NodeWrapper,
|
|
545
|
+
{
|
|
546
|
+
id: node.id,
|
|
547
|
+
part: "widget",
|
|
548
|
+
type: node.type,
|
|
549
|
+
custom,
|
|
550
|
+
edit,
|
|
551
|
+
className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
|
|
552
|
+
anchor: index === 0 && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
553
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
554
|
+
Component2,
|
|
555
|
+
{
|
|
556
|
+
node,
|
|
557
|
+
props: variant.props,
|
|
558
|
+
data,
|
|
559
|
+
editMode: edit !== void 0,
|
|
560
|
+
locale: ctx.locale,
|
|
561
|
+
mediaOrigin: ctx.mediaOrigin,
|
|
562
|
+
resolveLink: ctx.resolveLink,
|
|
563
|
+
inlineEdit: edit === void 0 ? void 0 : (key) => edit.inlineEdit(node.id, key),
|
|
564
|
+
budget: custom ? new RenderBudget() : void 0
|
|
565
|
+
}
|
|
566
|
+
)
|
|
567
|
+
},
|
|
568
|
+
variant.devices.join("-")
|
|
569
|
+
);
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
function renderColumn(column, ctx, registry) {
|
|
573
|
+
if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
|
|
574
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
575
|
+
NodeWrapper,
|
|
576
|
+
{
|
|
577
|
+
id: column.id,
|
|
578
|
+
part: "column",
|
|
579
|
+
className: "tb-col",
|
|
580
|
+
anchor: column.props.anchor,
|
|
581
|
+
edit: ctx.edit,
|
|
582
|
+
children: column.children.map(
|
|
583
|
+
(child) => child.type === "inner-section" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderWidget(child, ctx, registry) }, child.id)
|
|
584
|
+
)
|
|
585
|
+
},
|
|
586
|
+
column.id
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
function renderSection(section, ctx, registry, nested = false) {
|
|
590
|
+
if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
|
|
591
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
592
|
+
NodeWrapper,
|
|
593
|
+
{
|
|
594
|
+
id: section.id,
|
|
595
|
+
part: "section",
|
|
596
|
+
as: nested ? "div" : "section",
|
|
597
|
+
className: nested ? "tb-section tb-nested" : "tb-section",
|
|
598
|
+
anchor: section.props.anchor,
|
|
599
|
+
edit: ctx.edit,
|
|
600
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "tb-inner", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "tb-row", children: section.columns.map((column) => renderColumn(column, ctx, registry)) }) })
|
|
601
|
+
}
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
function BuilderRenderer(props) {
|
|
605
|
+
const { document: source, registry: base, data, editMode, locale, assets, resolveLink } = props;
|
|
606
|
+
const registry = registryFor(source, base);
|
|
607
|
+
const { doc } = (0, import_builder_schema5.upgradeNodes)(source, registry);
|
|
608
|
+
const mediaOrigin = props.mediaOrigin ?? "";
|
|
609
|
+
const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, edit: editMode };
|
|
610
|
+
const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
|
|
611
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
|
|
612
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
613
|
+
css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: css }),
|
|
614
|
+
doc.sections.map((section) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderSection(section, ctx, registry) }, section.id))
|
|
615
|
+
] });
|
|
616
|
+
}
|
|
617
|
+
function validateRender(doc) {
|
|
618
|
+
const h1 = [];
|
|
619
|
+
(0, import_builder_schema5.walkNodes)(doc, (node) => {
|
|
620
|
+
if (node.type === "basic.heading" && node.props.level === "h1") h1.push(node.id);
|
|
621
|
+
});
|
|
622
|
+
return h1.length > 1 ? [{ code: "MULTIPLE_H1", message: `The page has ${String(h1.length)} level 1 headings; use one`, nodeIds: h1 }] : [];
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// src/asset-image.tsx
|
|
626
|
+
var import_builder_schema6 = require("@usethrottle/builder-schema");
|
|
627
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
628
|
+
function isFrozenAsset(value) {
|
|
629
|
+
if (typeof value !== "object" || value === null) return false;
|
|
630
|
+
const v = value;
|
|
631
|
+
return typeof v.url === "string" && typeof v.width === "number" && typeof v.height === "number" && Array.isArray(v.variants);
|
|
632
|
+
}
|
|
633
|
+
function AssetImage(props) {
|
|
634
|
+
const { asset, alt, sizes, className, loading = "lazy", style, mediaOrigin } = props;
|
|
635
|
+
const href = (url) => (0, import_builder_schema6.safeUrl)(url, "src", { mediaOrigin });
|
|
636
|
+
if (!isFrozenAsset(asset)) return null;
|
|
637
|
+
const src = href(asset.url);
|
|
638
|
+
if (src === null) return null;
|
|
639
|
+
const srcSet = asset.variants.flatMap((variant) => {
|
|
640
|
+
const url = href(variant.url);
|
|
641
|
+
return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
|
|
642
|
+
}).join(", ");
|
|
643
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
644
|
+
"img",
|
|
645
|
+
{
|
|
646
|
+
src,
|
|
647
|
+
...srcSet === "" ? {} : { srcSet, sizes: sizes ?? "100vw" },
|
|
648
|
+
width: asset.width,
|
|
649
|
+
height: asset.height,
|
|
650
|
+
alt,
|
|
651
|
+
loading,
|
|
652
|
+
decoding: "async",
|
|
653
|
+
...className === void 0 ? {} : { className },
|
|
654
|
+
style: { aspectRatio: `${String(asset.width)} / ${String(asset.height)}`, ...style }
|
|
655
|
+
}
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// src/widget-style.tsx
|
|
660
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
661
|
+
function WidgetStyle({ css }) {
|
|
662
|
+
if (css === "" || css.includes("<")) return null;
|
|
663
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: css });
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/provider.tsx
|
|
667
|
+
var import_react15 = require("react");
|
|
668
|
+
var import_builder2 = require("@usethrottle/builder");
|
|
669
|
+
var import_ui6 = require("@usethrottle/ui");
|
|
670
|
+
|
|
671
|
+
// src/context.ts
|
|
672
|
+
var import_react2 = require("react");
|
|
673
|
+
var BuilderContext = (0, import_react2.createContext)(null);
|
|
674
|
+
var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
|
|
675
|
+
|
|
676
|
+
// src/page.tsx
|
|
677
|
+
var import_react4 = require("react");
|
|
678
|
+
var import_builder = require("@usethrottle/builder");
|
|
679
|
+
|
|
680
|
+
// src/load.ts
|
|
681
|
+
function pageOf(raw, initialData) {
|
|
682
|
+
const { document, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, ...meta } = raw;
|
|
683
|
+
return {
|
|
684
|
+
kind: "page",
|
|
685
|
+
slug,
|
|
686
|
+
title,
|
|
687
|
+
path,
|
|
688
|
+
generation,
|
|
689
|
+
document,
|
|
690
|
+
assets: document.assets ?? {},
|
|
691
|
+
initialData,
|
|
692
|
+
meta
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
var isRedirect = (raw) => typeof raw.redirectTo === "string";
|
|
696
|
+
|
|
697
|
+
// src/safe-path.ts
|
|
698
|
+
var import_builder_schema7 = require("@usethrottle/builder-schema");
|
|
699
|
+
var UNSAFE = /[\x00-\x20\x7f-\xa0\\\u1680\u2000-\u200f\u2028\u2029\u202f\u205f\u3000\ufeff]/;
|
|
700
|
+
var LEADING = /^\/(?![/\\])/;
|
|
701
|
+
function plainPath(path) {
|
|
702
|
+
return !UNSAFE.test(path) && (path === "/" || LEADING.test(path));
|
|
703
|
+
}
|
|
704
|
+
function sitePath(to) {
|
|
705
|
+
if (typeof to !== "string" || !plainPath(to)) return null;
|
|
706
|
+
let decoded;
|
|
707
|
+
try {
|
|
708
|
+
decoded = decodeURIComponent(to);
|
|
709
|
+
} catch {
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
if (!plainPath(decoded)) return null;
|
|
713
|
+
return (0, import_builder_schema7.safeUrl)(to, "href", { mediaOrigin: "" });
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// src/shopper-data.ts
|
|
717
|
+
var import_react3 = require("react");
|
|
718
|
+
function useResolvedData(document, registry, locale, include, context) {
|
|
719
|
+
const [data, setData] = (0, import_react3.useState)({});
|
|
720
|
+
(0, import_react3.useEffect)(() => {
|
|
721
|
+
const controller = new AbortController();
|
|
722
|
+
const bindings = collectBindings(document, registry);
|
|
723
|
+
if (bindings.size === 0) return void 0;
|
|
724
|
+
void resolveBindings(
|
|
725
|
+
bindings,
|
|
726
|
+
registry,
|
|
727
|
+
{ locale, preview: false, context, signal: controller.signal },
|
|
728
|
+
{ include }
|
|
729
|
+
).then((resolved) => {
|
|
730
|
+
if (!controller.signal.aborted && Object.keys(resolved).length > 0) setData(resolved);
|
|
731
|
+
});
|
|
732
|
+
return () => controller.abort();
|
|
733
|
+
}, [document, registry, locale, include, context]);
|
|
734
|
+
return data;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/page.tsx
|
|
738
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
739
|
+
function BuilderPageView({ page, resolve = "shopper" }) {
|
|
740
|
+
const builder = useBuilder();
|
|
741
|
+
if (builder === null) throw new Error("A Builder page needs a BuilderProvider above it");
|
|
742
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PageBody, { page, resolve, builder });
|
|
743
|
+
}
|
|
744
|
+
function PageBody({
|
|
745
|
+
page,
|
|
746
|
+
resolve,
|
|
747
|
+
builder
|
|
748
|
+
}) {
|
|
749
|
+
const resolved = useResolvedData(page.document, builder.registry, builder.locale, resolve);
|
|
750
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
751
|
+
BuilderRenderer,
|
|
752
|
+
{
|
|
753
|
+
document: page.document,
|
|
754
|
+
registry: builder.registry,
|
|
755
|
+
data: { ...page.initialData, ...resolved },
|
|
756
|
+
locale: builder.locale,
|
|
757
|
+
assets: page.assets,
|
|
758
|
+
mediaOrigin: builder.mediaOrigin,
|
|
759
|
+
resolveLink: builder.resolveLink
|
|
760
|
+
}
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
var entries = /* @__PURE__ */ new WeakMap();
|
|
764
|
+
var ENTRY_MS = 5e3;
|
|
765
|
+
function read(client, slug, locale) {
|
|
766
|
+
let perClient = entries.get(client);
|
|
767
|
+
if (perClient === void 0) {
|
|
768
|
+
perClient = /* @__PURE__ */ new Map();
|
|
769
|
+
entries.set(client, perClient);
|
|
770
|
+
}
|
|
771
|
+
const key = `${locale}|${slug}`;
|
|
772
|
+
let entry = perClient.get(key);
|
|
773
|
+
if (entry === void 0) {
|
|
774
|
+
const made = { status: "pending", promise: Promise.resolve() };
|
|
775
|
+
made.promise = client.pages.get(slug, { locale }).then(
|
|
776
|
+
(raw) => {
|
|
777
|
+
made.status = "done";
|
|
778
|
+
made.value = isRedirect(raw) ? raw : pageOf(raw, {});
|
|
779
|
+
},
|
|
780
|
+
(error) => {
|
|
781
|
+
made.status = "failed";
|
|
782
|
+
made.error = error;
|
|
783
|
+
}
|
|
784
|
+
);
|
|
785
|
+
entry = made;
|
|
786
|
+
const map = perClient;
|
|
787
|
+
map.set(key, made);
|
|
788
|
+
const timer = setTimeout(() => map.delete(key), ENTRY_MS);
|
|
789
|
+
timer.unref?.();
|
|
790
|
+
}
|
|
791
|
+
if (entry.status === "pending") throw entry.promise;
|
|
792
|
+
if (entry.status === "failed") throw entry.error;
|
|
793
|
+
return entry.value;
|
|
794
|
+
}
|
|
795
|
+
function BuilderPage({ slug, initial }) {
|
|
796
|
+
const builder = useBuilder();
|
|
797
|
+
if (builder === null) throw new Error("BuilderPage needs a BuilderProvider above it");
|
|
798
|
+
if (initial !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BuilderPageView, { page: initial });
|
|
799
|
+
if (builder.site.status === "unavailable") {
|
|
800
|
+
throw new import_builder.BuilderUnavailableError("network", "The Builder is unavailable and has no last good answer");
|
|
801
|
+
}
|
|
802
|
+
if (builder.client === null) {
|
|
803
|
+
throw new Error("BuilderPage reads the page itself: give BuilderProvider a builderKey or a client, or pass `initial`");
|
|
804
|
+
}
|
|
805
|
+
const found = read(builder.client, slug, builder.locale);
|
|
806
|
+
if ("redirectTo" in found) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Redirect, { to: found.redirectTo });
|
|
807
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BuilderPageView, { page: found, resolve: "all" });
|
|
808
|
+
}
|
|
809
|
+
function Redirect({ to }) {
|
|
810
|
+
(0, import_react4.useEffect)(() => {
|
|
811
|
+
const path = sitePath(to);
|
|
812
|
+
if (path !== null) window.location.replace(path);
|
|
813
|
+
}, [to]);
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// src/part-view.tsx
|
|
818
|
+
var import_react5 = require("react");
|
|
819
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
820
|
+
var PartBoundary = class extends import_react5.Component {
|
|
821
|
+
constructor() {
|
|
822
|
+
super(...arguments);
|
|
823
|
+
__publicField(this, "state", { failed: false });
|
|
824
|
+
}
|
|
825
|
+
static getDerivedStateFromError() {
|
|
826
|
+
return { failed: true };
|
|
827
|
+
}
|
|
828
|
+
componentDidCatch(error, _info) {
|
|
829
|
+
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
830
|
+
}
|
|
831
|
+
render() {
|
|
832
|
+
return this.state.failed ? null : this.props.children;
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
function contextData(context) {
|
|
836
|
+
if (typeof context !== "object" || context === null) return {};
|
|
837
|
+
return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
|
|
838
|
+
}
|
|
839
|
+
function PartView({ part, context }) {
|
|
840
|
+
const builder = useBuilder();
|
|
841
|
+
if (builder === null) return null;
|
|
842
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PartBody, { part, context, builder });
|
|
843
|
+
}
|
|
844
|
+
function PartBody({
|
|
845
|
+
part,
|
|
846
|
+
context,
|
|
847
|
+
builder
|
|
848
|
+
}) {
|
|
849
|
+
const shopper = useResolvedData(part.document, builder.registry, builder.locale, "shopper", context);
|
|
850
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
851
|
+
BuilderRenderer,
|
|
852
|
+
{
|
|
853
|
+
document: part.document,
|
|
854
|
+
registry: builder.registry,
|
|
855
|
+
data: { ...part.initialData, ...contextData(context), ...shopper },
|
|
856
|
+
locale: builder.locale,
|
|
857
|
+
assets: part.assets,
|
|
858
|
+
mediaOrigin: builder.mediaOrigin,
|
|
859
|
+
resolveLink: builder.resolveLink
|
|
860
|
+
}
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// src/registry.ts
|
|
865
|
+
var import_builder_schema20 = require("@usethrottle/builder-schema");
|
|
866
|
+
|
|
867
|
+
// src/basics/index.ts
|
|
868
|
+
var import_builder_schema15 = require("@usethrottle/builder-schema");
|
|
869
|
+
|
|
870
|
+
// src/basics/announcement.tsx
|
|
871
|
+
var import_react6 = require("react");
|
|
872
|
+
var import_ui = require("@usethrottle/ui");
|
|
873
|
+
var import_builder_schema9 = require("@usethrottle/builder-schema");
|
|
874
|
+
|
|
875
|
+
// src/basics/util.tsx
|
|
876
|
+
var import_builder_schema8 = require("@usethrottle/builder-schema");
|
|
877
|
+
|
|
878
|
+
// src/basics/styles.ts
|
|
879
|
+
var BASICS_CSS = `@layer throttle{
|
|
880
|
+
.tb-b-heading{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
|
|
881
|
+
.tb-b-text{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6;overflow-wrap:anywhere}
|
|
882
|
+
.tb-b-text>:first-child{margin-block-start:0}
|
|
883
|
+
.tb-b-text>:last-child{margin-block-end:0}
|
|
884
|
+
.tb-b-text h2,.tb-b-text h3,.tb-b-text h4{line-height:1.25}
|
|
885
|
+
.tb-b-text blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
|
|
886
|
+
.tb-b-text code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
|
|
887
|
+
.tb-b-link{color:var(--tb-color-primary,currentColor);text-decoration:underline}
|
|
888
|
+
.tb-b-image{text-align:var(--b-align,left);line-height:0}
|
|
889
|
+
.tb-b-image-box{display:inline-block;max-inline-size:100%;inline-size:calc(var(--b-width,100)*1%);vertical-align:top}
|
|
890
|
+
.tb-b-image-box a{display:block}
|
|
891
|
+
.tb-b-img{display:block;inline-size:100%;max-inline-size:100%;block-size:calc(var(--b-height)*1px);object-fit:var(--bx-fit,cover);border-radius:var(--bx-radius,0)}
|
|
892
|
+
.tb-b-empty{padding:var(--tb-space-m);border:1px dashed var(--tb-color-border-control,currentColor);color:var(--tb-color-muted-foreground,inherit);font-size:var(--tb-text-s);line-height:1.4;text-align:center}
|
|
893
|
+
.tb-b-button-wrap{text-align:var(--b-align,left)}
|
|
894
|
+
.tb-b-button{display:inline-block;box-sizing:border-box;min-inline-size:calc(100%*var(--b-fullWidth,0));max-inline-size:100%;border:1px solid transparent;border-radius:var(--throttle-radius,8px);font:inherit;font-weight:600;line-height:1.2;text-align:center;text-decoration:none;cursor:pointer}
|
|
895
|
+
.tb-b-button--s{padding:.4rem .9rem;font-size:var(--tb-text-s)}
|
|
896
|
+
.tb-b-button--m{padding:.65rem 1.25rem;font-size:var(--tb-text-m)}
|
|
897
|
+
.tb-b-button--l{padding:.9rem 1.75rem;font-size:var(--tb-text-l)}
|
|
898
|
+
.tb-b-button--primary{background:var(--tb-color-primary,#111);color:var(--tb-color-primary-foreground,#fff)}
|
|
899
|
+
.tb-b-button--secondary{background:var(--tb-color-muted,#eee);color:var(--tb-color-foreground,#111)}
|
|
900
|
+
.tb-b-button--outline{background:transparent;border-color:var(--tb-color-border-control,currentColor);color:var(--tb-color-foreground,#111)}
|
|
901
|
+
.tb-b-button--link{padding-inline:0;background:transparent;color:var(--tb-color-primary,#111);text-decoration:underline}
|
|
902
|
+
.tb-b-button:hover{filter:brightness(.92)}
|
|
903
|
+
.tb-b-button:focus-visible,.tb-b-menu a:focus-visible,.tb-b-menu-toggle:focus-visible,.tb-b-play:focus-visible,.tb-b-dismiss:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
|
|
904
|
+
.tb-b-spacer{block-size:var(--b-height,var(--tb-space-l))}
|
|
905
|
+
.tb-b-divider{box-sizing:border-box;inline-size:calc(var(--b-width,100)*1%);margin:0 auto;border:0;border-block-start:calc(var(--b-thickness,1)*1px) var(--bx-style,solid) var(--b-color,var(--tb-color-border,currentColor))}
|
|
906
|
+
.tb-b-video{position:relative;inline-size:100%;aspect-ratio:var(--bx-ratio,16/9);background:var(--tb-color-foreground,#111);border-radius:var(--throttle-radius,8px);overflow:hidden}
|
|
907
|
+
.tb-b-video iframe,.tb-b-play{position:absolute;inset:0;inline-size:100%;block-size:100%;border:0}
|
|
908
|
+
.tb-b-play{display:flex;align-items:center;justify-content:center;padding:0;background:transparent;color:var(--tb-color-background,#fff);cursor:pointer}
|
|
909
|
+
.tb-b-play span{display:grid;place-items:center;inline-size:4rem;block-size:4rem;border-radius:50%;background:rgba(0,0,0,.55)}
|
|
910
|
+
.tb-b-play:hover span{background:rgba(0,0,0,.75)}
|
|
911
|
+
.tb-b-logo{text-align:var(--b-align,left);line-height:0}
|
|
912
|
+
.tb-b-logo a{display:inline-block;color:inherit;text-decoration:none}
|
|
913
|
+
.tb-b-logo img{display:block;block-size:calc(var(--b-height,40)*1px);inline-size:auto;max-inline-size:100%}
|
|
914
|
+
.tb-b-logo-name{display:inline-block;font-size:var(--tb-text-xl);font-weight:700;line-height:calc(var(--b-height,40)*1px)}
|
|
915
|
+
.tb-b-menu{position:relative;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m))}
|
|
916
|
+
.tb-b-menu ul{margin:0;padding:0;list-style:none}
|
|
917
|
+
.tb-b-menu a{display:block;padding:var(--tb-space-xs) var(--tb-space-s);color:inherit;text-decoration:none}
|
|
918
|
+
.tb-b-menu a:hover{text-decoration:underline}
|
|
919
|
+
.tb-b-menu li{position:relative}
|
|
920
|
+
.tb-b-menu--vertical li li{padding-inline-start:var(--tb-space-m)}
|
|
921
|
+
.tb-b-menu--h>ul>li{display:inline-block}
|
|
922
|
+
.tb-b-menu--h li>ul{display:none;position:absolute;inset-block-start:100%;inset-inline-start:0;z-index:20;min-inline-size:12rem;padding:var(--tb-space-xs);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);border:1px solid var(--tb-color-border,#ddd);border-radius:var(--throttle-radius,8px)}
|
|
923
|
+
.tb-b-menu--h li:hover>ul,.tb-b-menu--h li:focus-within>ul{display:block}
|
|
924
|
+
.tb-b-menu-toggle{display:none;align-items:center;justify-content:center;min-inline-size:44px;min-block-size:44px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
|
|
925
|
+
@media (max-width:767px){
|
|
926
|
+
.tb-b-menu--drawer-on-phone .tb-b-menu-toggle{display:inline-flex;position:relative;z-index:61}
|
|
927
|
+
.tb-b-menu--drawer-on-phone[data-open=true] .tb-b-menu-toggle{position:fixed;inset-block-start:var(--tb-space-s);inset-inline-end:var(--tb-space-s)}
|
|
928
|
+
.tb-b-menu--drawer-on-phone>ul{display:none}
|
|
929
|
+
.tb-b-menu--drawer-on-phone[data-open=true]>ul{display:block;position:fixed;inset:0;z-index:60;overflow:auto;padding:4.5rem var(--tb-space-m) var(--tb-space-m);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);font-size:var(--tb-text-l)}
|
|
930
|
+
.tb-b-menu--drawer-on-phone>ul>li{display:block}
|
|
931
|
+
.tb-b-menu--drawer-on-phone li>ul{display:block;position:static;min-inline-size:0;padding:0;border:0;padding-inline-start:var(--tb-space-m)}
|
|
932
|
+
}
|
|
933
|
+
.tb-b-announcement{display:flex;align-items:center;justify-content:center;gap:var(--tb-space-s);box-sizing:border-box;padding:var(--tb-space-s) var(--tb-space-m);text-align:var(--b-align,center);background:var(--b-background,var(--tb-color-primary,#111));color:var(--b-color,var(--tb-color-primary-foreground,#fff));font-size:var(--tb-text-s)}
|
|
934
|
+
.tb-b-announcement-text{flex:1 1 auto}
|
|
935
|
+
.tb-b-announcement a{color:inherit;text-decoration:underline}
|
|
936
|
+
.tb-b-dismiss{display:inline-grid;place-items:center;flex:0 0 auto;min-inline-size:32px;min-block-size:32px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
|
|
937
|
+
.tb-b-copyright{margin:0;text-align:var(--b-align,center);color:var(--b-color,var(--tb-color-muted-foreground,inherit));font-size:var(--b-size,var(--tb-text-s))}
|
|
938
|
+
}`;
|
|
939
|
+
|
|
940
|
+
// src/basics/util.tsx
|
|
941
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
942
|
+
function BasicStyles() {
|
|
943
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
|
|
944
|
+
}
|
|
945
|
+
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
946
|
+
var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
947
|
+
function oneOf(value, allowed, fallback) {
|
|
948
|
+
return allowed.find((candidate) => candidate === value) ?? fallback;
|
|
949
|
+
}
|
|
950
|
+
function hrefOf(link, mediaOrigin) {
|
|
951
|
+
if (!isRecord2(link)) return null;
|
|
952
|
+
return (0, import_builder_schema8.safeUrl)(link.href, "href", { mediaOrigin });
|
|
953
|
+
}
|
|
954
|
+
function Placeholder({ editMode, children }) {
|
|
955
|
+
return editMode ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "tb-b-empty", children }) : null;
|
|
956
|
+
}
|
|
957
|
+
var ID_RE2 = /^[a-z0-9]{8,24}$/;
|
|
958
|
+
var DEVICES2 = ["desktop", "tablet", "phone"];
|
|
959
|
+
function defaultOf(type, key) {
|
|
960
|
+
const def = import_builder_schema8.BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
|
|
961
|
+
return def?.settings.find((f) => f.key === key)?.default ?? null;
|
|
962
|
+
}
|
|
963
|
+
function enumCss(node, rules) {
|
|
964
|
+
if (!ID_RE2.test(node.id)) return "";
|
|
965
|
+
const per = { desktop: /* @__PURE__ */ new Map(), tablet: /* @__PURE__ */ new Map(), phone: /* @__PURE__ */ new Map() };
|
|
966
|
+
for (const device of DEVICES2) {
|
|
967
|
+
const settings = { ...Object.fromEntries(rules.map((r) => [r.key, defaultOf(node.type, r.key)])), ...node.props };
|
|
968
|
+
const resolved = (0, import_builder_schema8.resolveResponsive)(settings, node.responsive, device);
|
|
969
|
+
for (const rule of rules) {
|
|
970
|
+
const value = resolved[rule.key];
|
|
971
|
+
const fallback = defaultOf(node.type, rule.key);
|
|
972
|
+
const pick = typeof value === "string" && Object.hasOwn(rule.values, value) ? value : String(fallback);
|
|
973
|
+
const css = Object.hasOwn(rule.values, pick) ? rule.values[pick] : void 0;
|
|
974
|
+
if (css !== void 0) per[device].set(rule.property, css);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
const block2 = (decls) => decls.length === 0 ? "" : `[data-b-id="${node.id}"]{${decls.map(([p, v]) => `${p}:${v}`).join(";")}}`;
|
|
978
|
+
const diff = (prev, next) => [...next].filter(([p, v]) => prev.get(p) !== v);
|
|
979
|
+
const tablet = block2(diff(per.desktop, per.tablet));
|
|
980
|
+
const phone = block2(diff(per.tablet, per.phone));
|
|
981
|
+
return block2([...per.desktop]) + (tablet === "" ? "" : `@media (max-width:1024px){${tablet}}`) + (phone === "" ? "" : `@media (max-width:767px){${phone}}`);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// src/basics/announcement.tsx
|
|
985
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
986
|
+
var KEY = "tb-announcement-dismissed";
|
|
987
|
+
function read2(message) {
|
|
988
|
+
try {
|
|
989
|
+
return window.sessionStorage.getItem(KEY) === message;
|
|
990
|
+
} catch {
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
function write(message) {
|
|
995
|
+
try {
|
|
996
|
+
window.sessionStorage.setItem(KEY, message);
|
|
997
|
+
} catch {
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function Announcement({ props, mediaOrigin, editMode }) {
|
|
1001
|
+
const design = (0, import_ui.useSiteDesign)();
|
|
1002
|
+
const message = design?.announcement?.message;
|
|
1003
|
+
const [dismissed, setDismissed] = (0, import_react6.useState)(false);
|
|
1004
|
+
(0, import_react6.useEffect)(() => {
|
|
1005
|
+
if (message !== void 0 && read2(message)) setDismissed(true);
|
|
1006
|
+
}, [message]);
|
|
1007
|
+
if (message === void 0) {
|
|
1008
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
1009
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BasicStyles, {}),
|
|
1010
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
|
|
1011
|
+
] });
|
|
1012
|
+
}
|
|
1013
|
+
if (dismissed && !editMode) return null;
|
|
1014
|
+
const href = (0, import_builder_schema9.safeUrl)(design?.announcement?.href, "href", { mediaOrigin });
|
|
1015
|
+
const strings = design?.strings;
|
|
1016
|
+
const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? import_builder_schema9.SITE_STRING_DEFAULTS["announcement.dismiss"];
|
|
1017
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
1018
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BasicStyles, {}),
|
|
1019
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
|
|
1020
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("a", { href, children: message }) }),
|
|
1021
|
+
props.dismissible === true && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1022
|
+
"button",
|
|
1023
|
+
{
|
|
1024
|
+
type: "button",
|
|
1025
|
+
className: "tb-b-dismiss",
|
|
1026
|
+
onClick: () => {
|
|
1027
|
+
write(message);
|
|
1028
|
+
setDismissed(true);
|
|
1029
|
+
},
|
|
1030
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui.Icon, { name: "close", size: 16, label: dismissLabel })
|
|
1031
|
+
}
|
|
1032
|
+
)
|
|
1033
|
+
] })
|
|
1034
|
+
] });
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// src/basics/button.tsx
|
|
1038
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1039
|
+
var STYLES = ["primary", "secondary", "outline", "link"];
|
|
1040
|
+
var SIZES = ["s", "m", "l"];
|
|
1041
|
+
function Button({ props, mediaOrigin, inlineEdit }) {
|
|
1042
|
+
const href = hrefOf(props.link, mediaOrigin);
|
|
1043
|
+
const className = `tb-b-button tb-b-button--${oneOf(props.style, STYLES, "primary")} tb-b-button--${oneOf(props.size, SIZES, "m")}`;
|
|
1044
|
+
const label = inlineEdit?.("label") ?? str(props.label) ?? "";
|
|
1045
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
1046
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(BasicStyles, {}),
|
|
1047
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("a", { className, ...href === null ? {} : { href }, children: label }) })
|
|
1048
|
+
] });
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// src/basics/copyright.tsx
|
|
1052
|
+
var import_ui2 = require("@usethrottle/ui");
|
|
1053
|
+
var import_builder_schema10 = require("@usethrottle/builder-schema");
|
|
1054
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1055
|
+
function Copyright(_) {
|
|
1056
|
+
const design = (0, import_ui2.useSiteDesign)();
|
|
1057
|
+
const strings = design?.strings;
|
|
1058
|
+
const template = strings !== void 0 && Object.hasOwn(strings, "footer.copyright") ? str(strings["footer.copyright"]) : void 0;
|
|
1059
|
+
const line = (template ?? import_builder_schema10.SITE_STRING_DEFAULTS["footer.copyright"]).replace("{year}", () => String((/* @__PURE__ */ new Date()).getFullYear())).replace("{store}", () => str(design?.brand?.storeName) ?? "").replace(/\s{2,}/g, " ").replace(/\s+([.,])/g, "$1");
|
|
1060
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
1061
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(BasicStyles, {}),
|
|
1062
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "tb-b-copyright", children: line })
|
|
1063
|
+
] });
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// src/basics/divider.tsx
|
|
1067
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1068
|
+
var RULES = [{ key: "style", property: "--bx-style", values: { solid: "solid", dashed: "dashed", dotted: "dotted" } }];
|
|
1069
|
+
function Divider({ node }) {
|
|
1070
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
1071
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(BasicStyles, {}),
|
|
1072
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(WidgetStyle, { css: enumCss(node, RULES) }),
|
|
1073
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("hr", { className: "tb-b-divider" })
|
|
1074
|
+
] });
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// src/basics/heading.tsx
|
|
1078
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1079
|
+
var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
1080
|
+
function Heading({ props, inlineEdit }) {
|
|
1081
|
+
const Tag = oneOf(props.level, LEVELS, "h2");
|
|
1082
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
|
|
1083
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(BasicStyles, {}),
|
|
1084
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" })
|
|
1085
|
+
] });
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// src/basics/image.tsx
|
|
1089
|
+
var import_builder_schema11 = require("@usethrottle/builder-schema");
|
|
1090
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1091
|
+
var RULES2 = [
|
|
1092
|
+
{ key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
|
|
1093
|
+
{ key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
|
|
1094
|
+
];
|
|
1095
|
+
function Image({ node, props, mediaOrigin, editMode }) {
|
|
1096
|
+
const href = hrefOf(props.link, mediaOrigin);
|
|
1097
|
+
const decorative = props.decorative === true;
|
|
1098
|
+
const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
|
|
1099
|
+
const asset = isFrozenAsset(props.image) ? props.image : void 0;
|
|
1100
|
+
const image = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
|
|
1101
|
+
const shown = asset !== void 0 && (0, import_builder_schema11.safeUrl)(asset.url, "src", { mediaOrigin }) !== null;
|
|
1102
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
1103
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(BasicStyles, {}),
|
|
1104
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(WidgetStyle, { css: enumCss(node, RULES2) }),
|
|
1105
|
+
shown ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "tb-b-image", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("a", { href, children: image }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
|
|
1106
|
+
] });
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// src/basics/logo.tsx
|
|
1110
|
+
var import_ui3 = require("@usethrottle/ui");
|
|
1111
|
+
var import_builder_schema12 = require("@usethrottle/builder-schema");
|
|
1112
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1113
|
+
function Logo({ props, mediaOrigin, editMode }) {
|
|
1114
|
+
const design = (0, import_ui3.useSiteDesign)();
|
|
1115
|
+
const scheme = design?.theme?.colorScheme ?? "auto";
|
|
1116
|
+
const src = (url) => url === void 0 ? void 0 : (0, import_builder_schema12.safeUrl)(url, "src", { mediaOrigin }) ?? void 0;
|
|
1117
|
+
const light = src(design?.brand?.logo?.light);
|
|
1118
|
+
const dark = src(design?.brand?.logo?.dark);
|
|
1119
|
+
const main = scheme === "dark" ? dark ?? light : light ?? dark;
|
|
1120
|
+
const name = str(design?.brand?.storeName);
|
|
1121
|
+
const href = hrefOf(props.link, mediaOrigin) ?? "/";
|
|
1122
|
+
const alt = name ?? "";
|
|
1123
|
+
let content = null;
|
|
1124
|
+
if (main !== void 0) {
|
|
1125
|
+
const img = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("img", { src: main, alt, decoding: "async" });
|
|
1126
|
+
content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("picture", { children: [
|
|
1127
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
|
|
1128
|
+
img
|
|
1129
|
+
] }) : img;
|
|
1130
|
+
} else if (name !== void 0) {
|
|
1131
|
+
content = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "tb-b-logo-name", children: name });
|
|
1132
|
+
}
|
|
1133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
1134
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BasicStyles, {}),
|
|
1135
|
+
content === null ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-b-logo", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("a", { href, children: content }) })
|
|
1136
|
+
] });
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// src/basics/menu.tsx
|
|
1140
|
+
var import_react7 = require("react");
|
|
1141
|
+
var import_ui4 = require("@usethrottle/ui");
|
|
1142
|
+
var import_builder_schema13 = require("@usethrottle/builder-schema");
|
|
1143
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1144
|
+
var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
|
|
1145
|
+
var MAX_DEPTH = 3;
|
|
1146
|
+
function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
|
|
1147
|
+
const shown = items.flatMap((item) => {
|
|
1148
|
+
const href = (0, import_builder_schema13.safeUrl)(item.href, "href", { mediaOrigin });
|
|
1149
|
+
return href === null ? [] : [{ item, href }];
|
|
1150
|
+
});
|
|
1151
|
+
if (shown.length === 0) return null;
|
|
1152
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown.map(({ item, href }, index) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("li", { children: [
|
|
1153
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("a", { href, children: item.label }),
|
|
1154
|
+
depth + 1 < MAX_DEPTH && item.children !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(List, { items: item.children, mediaOrigin, depth: depth + 1 })
|
|
1155
|
+
] }, `${String(index)}:${href}`)) });
|
|
1156
|
+
}
|
|
1157
|
+
function Menu({ props, mediaOrigin, editMode }) {
|
|
1158
|
+
const design = (0, import_ui4.useSiteDesign)();
|
|
1159
|
+
const listId = (0, import_react7.useId)();
|
|
1160
|
+
const toggle = (0, import_react7.useRef)(null);
|
|
1161
|
+
const [open, setOpen] = (0, import_react7.useState)(false);
|
|
1162
|
+
const name = str(props.menu) ?? "header";
|
|
1163
|
+
const layout = oneOf(props.layout, LAYOUTS, "horizontal");
|
|
1164
|
+
const menus = design?.menus;
|
|
1165
|
+
const items = menus !== void 0 && Object.hasOwn(menus, name) ? menus[name] : void 0;
|
|
1166
|
+
const strings = design?.strings;
|
|
1167
|
+
const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? import_builder_schema13.SITE_STRING_DEFAULTS["nav.menu"];
|
|
1168
|
+
if (items === void 0 || items.length === 0) {
|
|
1169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
|
|
1170
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BasicStyles, {}),
|
|
1171
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
|
|
1172
|
+
] });
|
|
1173
|
+
}
|
|
1174
|
+
const drawer = layout === "drawer-on-phone";
|
|
1175
|
+
const onKeyDown = (event) => {
|
|
1176
|
+
if (event.key === "Escape" && open) {
|
|
1177
|
+
setOpen(false);
|
|
1178
|
+
toggle.current?.focus();
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
|
|
1182
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BasicStyles, {}),
|
|
1183
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
1184
|
+
"nav",
|
|
1185
|
+
{
|
|
1186
|
+
className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
|
|
1187
|
+
"aria-label": label,
|
|
1188
|
+
"data-open": drawer ? String(open) : void 0,
|
|
1189
|
+
onKeyDown: drawer ? onKeyDown : void 0,
|
|
1190
|
+
children: [
|
|
1191
|
+
drawer && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1192
|
+
"button",
|
|
1193
|
+
{
|
|
1194
|
+
ref: toggle,
|
|
1195
|
+
type: "button",
|
|
1196
|
+
className: "tb-b-menu-toggle",
|
|
1197
|
+
"aria-expanded": open,
|
|
1198
|
+
"aria-controls": listId,
|
|
1199
|
+
onClick: () => setOpen((value) => !value),
|
|
1200
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui4.Icon, { name: open ? "close" : "menu", size: 24, label })
|
|
1201
|
+
}
|
|
1202
|
+
),
|
|
1203
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
|
|
1204
|
+
]
|
|
1205
|
+
}
|
|
1206
|
+
)
|
|
1207
|
+
] });
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// src/basics/spacer.tsx
|
|
1211
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1212
|
+
function Spacer() {
|
|
1213
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
|
|
1214
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(BasicStyles, {}),
|
|
1215
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "tb-b-spacer", "aria-hidden": "true" })
|
|
1216
|
+
] });
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// src/basics/rich-text.tsx
|
|
1220
|
+
var import_react8 = require("react");
|
|
1221
|
+
var import_builder_schema14 = require("@usethrottle/builder-schema");
|
|
1222
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1223
|
+
var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
|
|
1224
|
+
var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
|
|
1225
|
+
var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
1226
|
+
"script",
|
|
1227
|
+
"style",
|
|
1228
|
+
"iframe",
|
|
1229
|
+
"object",
|
|
1230
|
+
"embed",
|
|
1231
|
+
"noscript",
|
|
1232
|
+
"template",
|
|
1233
|
+
"textarea",
|
|
1234
|
+
"title",
|
|
1235
|
+
"head",
|
|
1236
|
+
"xml",
|
|
1237
|
+
"svg",
|
|
1238
|
+
"math",
|
|
1239
|
+
"noembed",
|
|
1240
|
+
"noframes",
|
|
1241
|
+
"xmp"
|
|
1242
|
+
]);
|
|
1243
|
+
var VOID = /* @__PURE__ */ new Set(["br"]);
|
|
1244
|
+
var BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote"]);
|
|
1245
|
+
var TEXT_BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4"]);
|
|
1246
|
+
var MAX_LENGTH = 2e4;
|
|
1247
|
+
var MAX_DEPTH2 = 24;
|
|
1248
|
+
var MAX_NODES = 4e3;
|
|
1249
|
+
var NAMED = {
|
|
1250
|
+
amp: "&",
|
|
1251
|
+
lt: "<",
|
|
1252
|
+
gt: ">",
|
|
1253
|
+
quot: '"',
|
|
1254
|
+
apos: "'",
|
|
1255
|
+
nbsp: "\xA0",
|
|
1256
|
+
copy: "\xA9",
|
|
1257
|
+
reg: "\xAE",
|
|
1258
|
+
trade: "\u2122",
|
|
1259
|
+
mdash: "\u2014",
|
|
1260
|
+
ndash: "\u2013",
|
|
1261
|
+
hellip: "\u2026",
|
|
1262
|
+
lsquo: "\u2018",
|
|
1263
|
+
rsquo: "\u2019",
|
|
1264
|
+
ldquo: "\u201C",
|
|
1265
|
+
rdquo: "\u201D",
|
|
1266
|
+
euro: "\u20AC",
|
|
1267
|
+
pound: "\xA3"
|
|
1268
|
+
};
|
|
1269
|
+
function decode(value) {
|
|
1270
|
+
return value.replace(/&(?:#x([0-9a-f]{1,6})|#(\d{1,7})|([a-z]{2,8}));/gi, (whole, hex, dec, name) => {
|
|
1271
|
+
if (name !== void 0) return Object.hasOwn(NAMED, name.toLowerCase()) ? NAMED[name.toLowerCase()] : whole;
|
|
1272
|
+
const code = hex !== void 0 ? Number.parseInt(hex, 16) : Number.parseInt(dec ?? "", 10);
|
|
1273
|
+
return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : "";
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
var TAG_NAME = /[a-z][a-z0-9:_-]*/iy;
|
|
1277
|
+
function readTag(html, start) {
|
|
1278
|
+
const attrs = /* @__PURE__ */ new Map();
|
|
1279
|
+
let i = start;
|
|
1280
|
+
for (; ; ) {
|
|
1281
|
+
while (i < html.length && /[\s/]/.test(html[i])) i += 1;
|
|
1282
|
+
if (i >= html.length) return null;
|
|
1283
|
+
if (html[i] === ">") return { attrs, end: i + 1, selfClosing: /\/\s*$/.test(html.slice(start, i)) };
|
|
1284
|
+
let name = "";
|
|
1285
|
+
while (i < html.length && !/[\s=/>]/.test(html[i])) name += html[i++];
|
|
1286
|
+
while (i < html.length && /\s/.test(html[i])) i += 1;
|
|
1287
|
+
let value = "";
|
|
1288
|
+
if (html[i] === "=") {
|
|
1289
|
+
i += 1;
|
|
1290
|
+
while (i < html.length && /\s/.test(html[i])) i += 1;
|
|
1291
|
+
const quote = html[i];
|
|
1292
|
+
if (quote === '"' || quote === "'") {
|
|
1293
|
+
const close = html.indexOf(quote, i + 1);
|
|
1294
|
+
if (close === -1) return null;
|
|
1295
|
+
value = html.slice(i + 1, close);
|
|
1296
|
+
i = close + 1;
|
|
1297
|
+
} else {
|
|
1298
|
+
while (i < html.length && !/[\s>]/.test(html[i])) value += html[i++];
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
const key = name.toLowerCase();
|
|
1302
|
+
if (key !== "" && !attrs.has(key)) attrs.set(key, value);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
function parseRichText(source, mediaOrigin) {
|
|
1306
|
+
const html = source.slice(0, MAX_LENGTH);
|
|
1307
|
+
const root = { tag: "#root", children: [], ...source.length > MAX_LENGTH ? { truncated: true } : {} };
|
|
1308
|
+
const stack = [root];
|
|
1309
|
+
const top = () => stack[stack.length - 1];
|
|
1310
|
+
let nodes = 0;
|
|
1311
|
+
const text = (value) => {
|
|
1312
|
+
if (value === "" || nodes > MAX_NODES) return;
|
|
1313
|
+
nodes += 1;
|
|
1314
|
+
const parent = top();
|
|
1315
|
+
const last = parent.children[parent.children.length - 1];
|
|
1316
|
+
if (typeof last === "string") parent.children[parent.children.length - 1] = last + value;
|
|
1317
|
+
else parent.children.push(value);
|
|
1318
|
+
};
|
|
1319
|
+
const closeTo = (tag) => {
|
|
1320
|
+
const at = stack.map((e) => e.tag).lastIndexOf(tag);
|
|
1321
|
+
if (at > 0) stack.length = at;
|
|
1322
|
+
};
|
|
1323
|
+
let i = 0;
|
|
1324
|
+
while (i < html.length && nodes <= MAX_NODES) {
|
|
1325
|
+
const lt = html.indexOf("<", i);
|
|
1326
|
+
if (lt === -1) {
|
|
1327
|
+
text(decode(html.slice(i)));
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
text(decode(html.slice(i, lt)));
|
|
1331
|
+
i = lt;
|
|
1332
|
+
if (html.startsWith("<!--", i)) {
|
|
1333
|
+
const close = html.indexOf("-->", i + 4);
|
|
1334
|
+
i = close === -1 ? html.length : close + 3;
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
const closing = html[i + 1] === "/";
|
|
1338
|
+
const nameStart = i + (closing ? 2 : 1);
|
|
1339
|
+
TAG_NAME.lastIndex = nameStart;
|
|
1340
|
+
const raw = TAG_NAME.exec(html)?.[0]?.toLowerCase();
|
|
1341
|
+
if (raw === void 0) {
|
|
1342
|
+
if (html[i + 1] === "!" || html[i + 1] === "?") {
|
|
1343
|
+
const close = html.indexOf(">", i);
|
|
1344
|
+
i = close === -1 ? html.length : close + 1;
|
|
1345
|
+
} else {
|
|
1346
|
+
text("<");
|
|
1347
|
+
i += 1;
|
|
1348
|
+
}
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
const tag = readTag(html, nameStart + raw.length);
|
|
1352
|
+
if (tag === null) {
|
|
1353
|
+
root.truncated = true;
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
i = tag.end;
|
|
1357
|
+
const name = Object.hasOwn(ALIAS, raw) ? ALIAS[raw] : raw;
|
|
1358
|
+
if (closing) {
|
|
1359
|
+
if (ALLOWED.has(name)) closeTo(name);
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
if (DROP_WITH_CONTENT.has(raw)) {
|
|
1363
|
+
if (!tag.selfClosing) {
|
|
1364
|
+
const close = new RegExp(`</${raw}\\s*>`, "ig");
|
|
1365
|
+
close.lastIndex = i;
|
|
1366
|
+
const found = close.exec(html);
|
|
1367
|
+
i = found === null ? html.length : found.index + found[0].length;
|
|
1368
|
+
}
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
if (!ALLOWED.has(name)) continue;
|
|
1372
|
+
if (BLOCK.has(name)) {
|
|
1373
|
+
for (let at = stack.length - 1; at > 0; at -= 1) {
|
|
1374
|
+
if (TEXT_BLOCK.has(stack[at].tag)) {
|
|
1375
|
+
stack.length = at;
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
if (name === "li") {
|
|
1381
|
+
let list = stack.length - 1;
|
|
1382
|
+
while (list > 0 && stack[list].tag !== "ul" && stack[list].tag !== "ol") list -= 1;
|
|
1383
|
+
if (list === 0) list = -1;
|
|
1384
|
+
if (list === -1) continue;
|
|
1385
|
+
stack.length = list + 1;
|
|
1386
|
+
}
|
|
1387
|
+
if (name === "a") closeTo("a");
|
|
1388
|
+
const el = { tag: name, children: [] };
|
|
1389
|
+
if (name === "a") {
|
|
1390
|
+
const href = tag.attrs.get("href");
|
|
1391
|
+
el.href = href === void 0 ? null : (0, import_builder_schema14.safeUrl)(decode(href).trim(), "href", { mediaOrigin });
|
|
1392
|
+
}
|
|
1393
|
+
nodes += 1;
|
|
1394
|
+
top().children.push(el);
|
|
1395
|
+
if (!VOID.has(name) && stack.length < MAX_DEPTH2) stack.push(el);
|
|
1396
|
+
}
|
|
1397
|
+
if (nodes > MAX_NODES) root.truncated = true;
|
|
1398
|
+
return root;
|
|
1399
|
+
}
|
|
1400
|
+
function toReact(el, key) {
|
|
1401
|
+
const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
|
|
1402
|
+
if (el.tag === "br") return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("br", {}, key);
|
|
1403
|
+
if (el.tag === "a") {
|
|
1404
|
+
if (el.href === null || el.href === void 0) return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react8.Fragment, { children }, key);
|
|
1405
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
|
|
1406
|
+
}
|
|
1407
|
+
return (0, import_react8.createElement)(el.tag, { key }, ...children);
|
|
1408
|
+
}
|
|
1409
|
+
function RichText({
|
|
1410
|
+
html,
|
|
1411
|
+
mediaOrigin,
|
|
1412
|
+
className,
|
|
1413
|
+
editMode = false
|
|
1414
|
+
}) {
|
|
1415
|
+
const tree = parseRichText(html, mediaOrigin);
|
|
1416
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className, children: [
|
|
1417
|
+
tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
|
|
1418
|
+
editMode && tree.truncated === true && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "tb-b-empty", role: "alert", children: "Part of this text was not shown: a tag is not closed (check the quotes in links), or the text is too long." })
|
|
1419
|
+
] });
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// src/basics/text.tsx
|
|
1423
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1424
|
+
function Text({ props, mediaOrigin, editMode, inlineEdit }) {
|
|
1425
|
+
const editor = inlineEdit?.("html") ?? null;
|
|
1426
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
|
|
1427
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicStyles, {}),
|
|
1428
|
+
editor === null ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "tb-b-text", children: editor })
|
|
1429
|
+
] });
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// src/basics/video.tsx
|
|
1433
|
+
var import_react9 = require("react");
|
|
1434
|
+
var import_ui5 = require("@usethrottle/ui");
|
|
1435
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1436
|
+
var RULES3 = [
|
|
1437
|
+
{ key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
|
|
1438
|
+
];
|
|
1439
|
+
var YOUTUBE_ID = /^[A-Za-z0-9_-]{11}$/;
|
|
1440
|
+
var VIMEO_ID = /^\d{5,12}$/;
|
|
1441
|
+
var YOUTUBE_HOSTS = /* @__PURE__ */ new Set(["youtube.com", "www.youtube.com", "m.youtube.com", "youtube-nocookie.com", "www.youtube-nocookie.com"]);
|
|
1442
|
+
var VIMEO_HOSTS = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com", "player.vimeo.com"]);
|
|
1443
|
+
function parseVideoUrl(input) {
|
|
1444
|
+
let url;
|
|
1445
|
+
try {
|
|
1446
|
+
url = new URL(input.trim());
|
|
1447
|
+
} catch {
|
|
1448
|
+
return null;
|
|
1449
|
+
}
|
|
1450
|
+
if (url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" && url.port !== "443") return null;
|
|
1451
|
+
const host = url.hostname.toLowerCase();
|
|
1452
|
+
const parts = url.pathname.split("/").filter((part) => part !== "");
|
|
1453
|
+
if (host === "youtu.be") {
|
|
1454
|
+
const id = parts[0];
|
|
1455
|
+
return parts.length === 1 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
|
|
1456
|
+
}
|
|
1457
|
+
if (YOUTUBE_HOSTS.has(host)) {
|
|
1458
|
+
if (parts[0] === "watch" && parts.length === 1) {
|
|
1459
|
+
const id2 = url.searchParams.get("v");
|
|
1460
|
+
return id2 !== null && YOUTUBE_ID.test(id2) ? { provider: "youtube", id: id2 } : null;
|
|
1461
|
+
}
|
|
1462
|
+
const id = parts[1];
|
|
1463
|
+
return (parts[0] === "embed" || parts[0] === "shorts" || parts[0] === "live") && parts.length === 2 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
|
|
1464
|
+
}
|
|
1465
|
+
if (VIMEO_HOSTS.has(host)) {
|
|
1466
|
+
const id = host === "player.vimeo.com" ? parts[0] === "video" && parts.length === 2 ? parts[1] : void 0 : parts.length === 1 ? parts[0] : void 0;
|
|
1467
|
+
return id !== void 0 && VIMEO_ID.test(id) ? { provider: "vimeo", id } : null;
|
|
1468
|
+
}
|
|
1469
|
+
return null;
|
|
1470
|
+
}
|
|
1471
|
+
function embedSrc(video, muted) {
|
|
1472
|
+
return video.provider === "youtube" ? `https://www.youtube-nocookie.com/embed/${video.id}?autoplay=1&rel=0&playsinline=1${muted ? "&mute=1" : ""}` : `https://player.vimeo.com/video/${video.id}?autoplay=1&dnt=1${muted ? "&muted=1" : ""}`;
|
|
1473
|
+
}
|
|
1474
|
+
function Video({ node, props, editMode }) {
|
|
1475
|
+
const [loaded, setLoaded] = (0, import_react9.useState)(false);
|
|
1476
|
+
const video = parseVideoUrl(str(props.url) ?? "");
|
|
1477
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
|
|
1478
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BasicStyles, {}),
|
|
1479
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(WidgetStyle, { css: enumCss(node, RULES3) }),
|
|
1480
|
+
video === null ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
1481
|
+
"iframe",
|
|
1482
|
+
{
|
|
1483
|
+
src: embedSrc(video, props.autoplayMuted === true),
|
|
1484
|
+
title: "Video",
|
|
1485
|
+
allow: "autoplay; encrypted-media; picture-in-picture; fullscreen",
|
|
1486
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
1487
|
+
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
|
|
1488
|
+
}
|
|
1489
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui5.Icon, { name: "play", size: 28 }) }) }) })
|
|
1490
|
+
] });
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// src/basics/index.ts
|
|
1494
|
+
var BASIC_COMPONENTS = {
|
|
1495
|
+
"basic.heading": Heading,
|
|
1496
|
+
"basic.text": Text,
|
|
1497
|
+
"basic.image": Image,
|
|
1498
|
+
"basic.button": Button,
|
|
1499
|
+
"basic.spacer": Spacer,
|
|
1500
|
+
"basic.divider": Divider,
|
|
1501
|
+
"basic.video": Video,
|
|
1502
|
+
"basic.logo": Logo,
|
|
1503
|
+
"basic.menu": Menu,
|
|
1504
|
+
"basic.announcement": Announcement,
|
|
1505
|
+
"basic.copyright": Copyright
|
|
1506
|
+
};
|
|
1507
|
+
var widgets = import_builder_schema15.BASIC_WIDGET_DEFINITIONS.flatMap(
|
|
1508
|
+
(definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
|
|
1509
|
+
);
|
|
1510
|
+
var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
|
|
1511
|
+
|
|
1512
|
+
// src/custom/factory.ts
|
|
1513
|
+
var import_react13 = require("react");
|
|
1514
|
+
|
|
1515
|
+
// src/custom/composite-widget.tsx
|
|
1516
|
+
var import_react12 = require("react");
|
|
1517
|
+
var import_builder_schema19 = require("@usethrottle/builder-schema");
|
|
1518
|
+
|
|
1519
|
+
// src/custom/template-widget.tsx
|
|
1520
|
+
var import_react11 = require("react");
|
|
1521
|
+
var import_builder_schema18 = require("@usethrottle/builder-schema");
|
|
1522
|
+
|
|
1523
|
+
// src/custom/custom-css.tsx
|
|
1524
|
+
var import_builder_schema16 = require("@usethrottle/builder-schema");
|
|
1525
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
1526
|
+
function scopedCss(source, type) {
|
|
1527
|
+
if (source === void 0 || source === "") return "";
|
|
1528
|
+
if (typeof source !== "string") return null;
|
|
1529
|
+
const result = (0, import_builder_schema16.sanitizeWidgetCss)(source, type);
|
|
1530
|
+
return result.ok ? result.css : null;
|
|
1531
|
+
}
|
|
1532
|
+
function CustomCss({ css }) {
|
|
1533
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(WidgetStyle, { css });
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
// src/custom/interpreter.tsx
|
|
1537
|
+
var import_react10 = require("react");
|
|
1538
|
+
var import_builder_schema17 = require("@usethrottle/builder-schema");
|
|
1539
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
1540
|
+
var MAX_OUTPUT_CHARS = 1e6;
|
|
1541
|
+
var MAX_ATTR_CHARS = 2e3;
|
|
1542
|
+
var MAX_DEPTH3 = 24;
|
|
1543
|
+
function newEnv(env) {
|
|
1544
|
+
return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
|
|
1545
|
+
}
|
|
1546
|
+
var BLOCKED = /* @__PURE__ */ new Set([
|
|
1547
|
+
"__proto__",
|
|
1548
|
+
"constructor",
|
|
1549
|
+
"prototype",
|
|
1550
|
+
...Object.getOwnPropertyNames(Object.prototype)
|
|
1551
|
+
]);
|
|
1552
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1553
|
+
function step(value, key) {
|
|
1554
|
+
if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
|
|
1555
|
+
return value[key];
|
|
1556
|
+
}
|
|
1557
|
+
function lookup(path, env, scope) {
|
|
1558
|
+
const [root, ...rest] = path;
|
|
1559
|
+
if (root === void 0) return void 0;
|
|
1560
|
+
if (root === "locale") return rest.length === 0 ? env.locale : void 0;
|
|
1561
|
+
let value;
|
|
1562
|
+
if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
|
|
1563
|
+
else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
|
|
1564
|
+
else if (scope.has(root)) value = scope.get(root);
|
|
1565
|
+
else return void 0;
|
|
1566
|
+
for (const key of rest) {
|
|
1567
|
+
value = step(value, key);
|
|
1568
|
+
if (value === void 0) return void 0;
|
|
1569
|
+
}
|
|
1570
|
+
return value;
|
|
1571
|
+
}
|
|
1572
|
+
function truthy(value) {
|
|
1573
|
+
if (value === null || value === void 0 || value === false || value === "") return false;
|
|
1574
|
+
if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
|
|
1575
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
1576
|
+
return true;
|
|
1577
|
+
}
|
|
1578
|
+
function asText(value) {
|
|
1579
|
+
if (typeof value === "string") return value;
|
|
1580
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
1581
|
+
return "";
|
|
1582
|
+
}
|
|
1583
|
+
function filtered(value, filters) {
|
|
1584
|
+
let text = asText(value);
|
|
1585
|
+
for (const filter of filters) {
|
|
1586
|
+
switch (filter.name) {
|
|
1587
|
+
case "upper":
|
|
1588
|
+
text = text.toUpperCase();
|
|
1589
|
+
break;
|
|
1590
|
+
case "lower":
|
|
1591
|
+
text = text.toLowerCase();
|
|
1592
|
+
break;
|
|
1593
|
+
case "truncate": {
|
|
1594
|
+
const chars = Array.from(text);
|
|
1595
|
+
if (chars.length > filter.n) text = `${chars.slice(0, filter.n).join("")}\u2026`;
|
|
1596
|
+
break;
|
|
1597
|
+
}
|
|
1598
|
+
case "default":
|
|
1599
|
+
if (text === "") text = filter.text;
|
|
1600
|
+
break;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
return text;
|
|
1604
|
+
}
|
|
1605
|
+
function spend(env, count) {
|
|
1606
|
+
if (count > env.charsLeft) {
|
|
1607
|
+
env.stopped = true;
|
|
1608
|
+
return false;
|
|
1609
|
+
}
|
|
1610
|
+
env.charsLeft -= count;
|
|
1611
|
+
return true;
|
|
1612
|
+
}
|
|
1613
|
+
var ELEMENTS = new Set(import_builder_schema17.ALLOWED_ELEMENTS);
|
|
1614
|
+
var VOIDS = new Set(import_builder_schema17.VOID_ELEMENTS);
|
|
1615
|
+
var ROLES = new Set(import_builder_schema17.ALLOWED_ROLES);
|
|
1616
|
+
function attrAllowed(tag, name) {
|
|
1617
|
+
if (import_builder_schema17.DATA_ATTR_RE.test(name)) return !name.startsWith(import_builder_schema17.RESERVED_DATA_PREFIX);
|
|
1618
|
+
const own = Object.hasOwn(import_builder_schema17.ALLOWED_ATTRS, tag) ? import_builder_schema17.ALLOWED_ATTRS[tag] : void 0;
|
|
1619
|
+
return (import_builder_schema17.ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
|
|
1620
|
+
}
|
|
1621
|
+
function attrText(attr, env, scope) {
|
|
1622
|
+
return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
|
|
1623
|
+
}
|
|
1624
|
+
function urlSource(attr, env, scope) {
|
|
1625
|
+
const [only] = attr.value;
|
|
1626
|
+
if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
|
|
1627
|
+
const value = lookup(only.path, env, scope);
|
|
1628
|
+
if (isPlainObject(value)) {
|
|
1629
|
+
if (typeof value.href === "string") return value.href;
|
|
1630
|
+
if (typeof value.url === "string") return value.url;
|
|
1631
|
+
return null;
|
|
1632
|
+
}
|
|
1633
|
+
return value;
|
|
1634
|
+
}
|
|
1635
|
+
function attrProp(tag, attr, env, scope) {
|
|
1636
|
+
const { name } = attr;
|
|
1637
|
+
if (!attrAllowed(tag, name)) return null;
|
|
1638
|
+
if (name === "href" || name === "src") {
|
|
1639
|
+
const safe = (0, import_builder_schema17.safeUrl)(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
|
|
1640
|
+
return safe === null || !spend(env, safe.length) ? null : [name, safe];
|
|
1641
|
+
}
|
|
1642
|
+
const text = attrText(attr, env, scope);
|
|
1643
|
+
if (text === "" || text.length > MAX_ATTR_CHARS) return null;
|
|
1644
|
+
let value = text;
|
|
1645
|
+
if (name === "class") {
|
|
1646
|
+
const tokens = text.split(/\s+/).filter((token) => import_builder_schema17.CLASS_TOKEN_RE.test(token) && !(0, import_builder_schema17.isReservedClass)(token));
|
|
1647
|
+
if (tokens.length === 0) return null;
|
|
1648
|
+
value = tokens.join(" ");
|
|
1649
|
+
} else if (name === "role") {
|
|
1650
|
+
if (!ROLES.has(text)) return null;
|
|
1651
|
+
} else if (name === "aria-hidden") {
|
|
1652
|
+
if (text !== "true" && text !== "false") return null;
|
|
1653
|
+
}
|
|
1654
|
+
if (!spend(env, value.length)) return null;
|
|
1655
|
+
return [name === "class" ? "className" : name, value];
|
|
1656
|
+
}
|
|
1657
|
+
function renderElement(node, env, scope, depth, key) {
|
|
1658
|
+
const tag = node.tag;
|
|
1659
|
+
if (!ELEMENTS.has(tag)) return null;
|
|
1660
|
+
const props = { key };
|
|
1661
|
+
for (const attr of node.attrs) {
|
|
1662
|
+
const prop = attrProp(tag, attr, env, scope);
|
|
1663
|
+
if (prop !== null) props[prop[0]] = prop[1];
|
|
1664
|
+
}
|
|
1665
|
+
if (VOIDS.has(tag)) return (0, import_react10.createElement)(tag, props);
|
|
1666
|
+
return (0, import_react10.createElement)(tag, props, renderNodes(node.children, env, scope, depth + 1));
|
|
1667
|
+
}
|
|
1668
|
+
function renderNodes(nodes, env, scope, depth) {
|
|
1669
|
+
const out = [];
|
|
1670
|
+
if (depth > MAX_DEPTH3) return out;
|
|
1671
|
+
for (const node of nodes) {
|
|
1672
|
+
if (env.stopped) break;
|
|
1673
|
+
if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
|
|
1674
|
+
env.stopped = true;
|
|
1675
|
+
break;
|
|
1676
|
+
}
|
|
1677
|
+
switch (node.type) {
|
|
1678
|
+
case "text":
|
|
1679
|
+
if (spend(env, node.value.length)) out.push(node.value);
|
|
1680
|
+
break;
|
|
1681
|
+
case "output": {
|
|
1682
|
+
const text = filtered(lookup(node.path, env, scope), node.filters);
|
|
1683
|
+
if (text !== "" && spend(env, text.length)) out.push(text);
|
|
1684
|
+
break;
|
|
1685
|
+
}
|
|
1686
|
+
case "if": {
|
|
1687
|
+
const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
|
|
1688
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
case "unless":
|
|
1692
|
+
if (!truthy(lookup(node.path, env, scope))) {
|
|
1693
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
|
|
1694
|
+
}
|
|
1695
|
+
break;
|
|
1696
|
+
case "each": {
|
|
1697
|
+
const list = lookup(node.path, env, scope);
|
|
1698
|
+
if (!Array.isArray(list)) break;
|
|
1699
|
+
const count = Math.min(list.length, import_builder_schema17.EACH_ITERATION_CAP);
|
|
1700
|
+
for (let i = 0; i < count && !env.stopped; i += 1) {
|
|
1701
|
+
const inner = new Map(scope).set(node.as, list[i]);
|
|
1702
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
|
|
1703
|
+
}
|
|
1704
|
+
break;
|
|
1705
|
+
}
|
|
1706
|
+
case "element":
|
|
1707
|
+
out.push(renderElement(node, env, scope, depth, out.length));
|
|
1708
|
+
break;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
return out;
|
|
1712
|
+
}
|
|
1713
|
+
function renderTemplate(ast, env) {
|
|
1714
|
+
return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
// src/custom/template-widget.tsx
|
|
1718
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
1719
|
+
var componentWeights = /* @__PURE__ */ new WeakMap();
|
|
1720
|
+
var compiled = /* @__PURE__ */ new WeakMap();
|
|
1721
|
+
function compileTemplate(snapshot, registry) {
|
|
1722
|
+
let perRegistry = compiled.get(snapshot);
|
|
1723
|
+
if (perRegistry === void 0) {
|
|
1724
|
+
perRegistry = /* @__PURE__ */ new WeakMap();
|
|
1725
|
+
compiled.set(snapshot, perRegistry);
|
|
1726
|
+
}
|
|
1727
|
+
if (perRegistry.has(registry)) return perRegistry.get(registry) ?? null;
|
|
1728
|
+
const result = compile(snapshot, registry);
|
|
1729
|
+
perRegistry.set(registry, result);
|
|
1730
|
+
return result;
|
|
1731
|
+
}
|
|
1732
|
+
function compile(snapshot, registry) {
|
|
1733
|
+
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
1734
|
+
const refuse = (why) => {
|
|
1735
|
+
warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
1736
|
+
return null;
|
|
1737
|
+
};
|
|
1738
|
+
if (snapshot.kind !== "template") return refuse("not a template widget");
|
|
1739
|
+
const source = snapshot.template;
|
|
1740
|
+
if (typeof source !== "string") return refuse("no template source");
|
|
1741
|
+
const parsed = (0, import_builder_schema18.parseTemplate)(source);
|
|
1742
|
+
if (!parsed.ok) return refuse(`template does not parse: ${parsed.issues[0]?.message ?? "invalid"}`);
|
|
1743
|
+
const data = snapshot.data;
|
|
1744
|
+
const issues = (0, import_builder_schema18.validateTemplate)(parsed.ast, {
|
|
1745
|
+
settings: snapshot.settings,
|
|
1746
|
+
data: typeof data === "object" && data !== null ? data : {},
|
|
1747
|
+
sources: registry.sources()
|
|
1748
|
+
});
|
|
1749
|
+
if (issues.length > 0) return refuse(`template does not validate: ${issues[0]?.message ?? "invalid"}`);
|
|
1750
|
+
if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(import_builder_schema18.MAX_TEMPLATE_WEIGHT)} nodes`);
|
|
1751
|
+
const css = scopedCss(snapshot.css, snapshot.type);
|
|
1752
|
+
if (css === null) return refuse("its css does not pass the sanitiser");
|
|
1753
|
+
return { ast: parsed.ast, css, weight: (0, import_builder_schema18.templateWeight)(parsed.ast) };
|
|
1754
|
+
}
|
|
1755
|
+
function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
|
|
1756
|
+
const template = compileTemplate(snapshot, registry);
|
|
1757
|
+
if (template === null) return null;
|
|
1758
|
+
const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
|
|
1759
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
|
|
1760
|
+
template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CustomCss, { css: template.css }),
|
|
1761
|
+
renderTemplate(template.ast, env)
|
|
1762
|
+
] });
|
|
1763
|
+
}
|
|
1764
|
+
function TemplateWidget(props) {
|
|
1765
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react11.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(TemplateBody, { ...props }) }) });
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
// src/custom/composite-widget.tsx
|
|
1769
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
1770
|
+
var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
|
|
1771
|
+
var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
|
|
1772
|
+
var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
|
|
1773
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1774
|
+
var compiled2 = /* @__PURE__ */ new WeakMap();
|
|
1775
|
+
function parseBody(raw) {
|
|
1776
|
+
if (!isRecord3(raw)) return null;
|
|
1777
|
+
const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
|
|
1778
|
+
const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
|
|
1779
|
+
if (columns === void 0 === (stack === void 0)) return null;
|
|
1780
|
+
const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : stack ?? [];
|
|
1781
|
+
if (stack?.some((node) => isRecord3(node) && node.type === "inner-section")) return null;
|
|
1782
|
+
const parsed = import_builder_schema19.pageDocumentSchema.safeParse({
|
|
1783
|
+
schemaVersion: 1,
|
|
1784
|
+
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1785
|
+
});
|
|
1786
|
+
if (!parsed.success) return null;
|
|
1787
|
+
const first = parsed.data.sections[0]?.columns[0]?.children ?? [];
|
|
1788
|
+
if (columns !== void 0) {
|
|
1789
|
+
const inner = first[0];
|
|
1790
|
+
return inner?.type === "inner-section" ? { columns: inner.columns } : null;
|
|
1791
|
+
}
|
|
1792
|
+
return { stack: first.filter((node) => node.type !== "inner-section") };
|
|
1793
|
+
}
|
|
1794
|
+
function compileComposite(snapshot) {
|
|
1795
|
+
if (compiled2.has(snapshot)) return compiled2.get(snapshot) ?? null;
|
|
1796
|
+
const result = compile2(snapshot);
|
|
1797
|
+
compiled2.set(snapshot, result);
|
|
1798
|
+
return result;
|
|
1799
|
+
}
|
|
1800
|
+
function compile2(snapshot) {
|
|
1801
|
+
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
1802
|
+
const refuse = (why) => {
|
|
1803
|
+
warnOnce(`composite:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
1804
|
+
return null;
|
|
1805
|
+
};
|
|
1806
|
+
if (snapshot.kind !== "composite") return refuse("not a composite widget");
|
|
1807
|
+
const extra = snapshot;
|
|
1808
|
+
const body = parseBody(extra.body);
|
|
1809
|
+
if (body === null) return refuse("its body does not pass the document grammar");
|
|
1810
|
+
const bindings = [];
|
|
1811
|
+
if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
|
|
1812
|
+
for (const raw of extra.bindings ?? []) {
|
|
1813
|
+
if (!isRecord3(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
|
|
1814
|
+
return refuse("a binding is malformed");
|
|
1815
|
+
}
|
|
1816
|
+
const targets = [];
|
|
1817
|
+
for (const target of raw.targets) {
|
|
1818
|
+
if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
|
|
1819
|
+
return refuse("a binding target is malformed");
|
|
1820
|
+
}
|
|
1821
|
+
targets.push({ node: target.node, prop: target.prop });
|
|
1822
|
+
}
|
|
1823
|
+
bindings.push({ setting: raw.setting, targets });
|
|
1824
|
+
}
|
|
1825
|
+
const data = [];
|
|
1826
|
+
if (extra.data !== void 0 && !isRecord3(extra.data)) return refuse("data is not a record");
|
|
1827
|
+
for (const [name, raw] of Object.entries(extra.data ?? {})) {
|
|
1828
|
+
if (!SETTING_KEY_RE.test(name) || !isRecord3(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
|
|
1829
|
+
const targets = [];
|
|
1830
|
+
for (const target of raw.targets) {
|
|
1831
|
+
if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
|
|
1832
|
+
return refuse("a data target is malformed");
|
|
1833
|
+
}
|
|
1834
|
+
targets.push({ node: target.node, input: target.input });
|
|
1835
|
+
}
|
|
1836
|
+
data.push([name, { targets }]);
|
|
1837
|
+
}
|
|
1838
|
+
return { body, bindings, data };
|
|
1839
|
+
}
|
|
1840
|
+
var DEVICES3 = ["tablet", "phone"];
|
|
1841
|
+
function withoutAnchor(node) {
|
|
1842
|
+
delete node.props.anchor;
|
|
1843
|
+
const responsive = node.responsive;
|
|
1844
|
+
for (const device of DEVICES3) if (responsive?.[device] !== void 0) delete responsive[device].anchor;
|
|
1845
|
+
}
|
|
1846
|
+
function instanceId(outer, inner) {
|
|
1847
|
+
let a = 3735928559;
|
|
1848
|
+
let b = 1103547991;
|
|
1849
|
+
for (const char of `${outer}:${inner}`) {
|
|
1850
|
+
const code = char.charCodeAt(0);
|
|
1851
|
+
a = Math.imul(a ^ code, 2654435761);
|
|
1852
|
+
b = Math.imul(b ^ code, 1597334677);
|
|
1853
|
+
}
|
|
1854
|
+
a = Math.imul(a ^ a >>> 16, 2246822507) ^ Math.imul(b ^ b >>> 13, 3266489909);
|
|
1855
|
+
b = Math.imul(b ^ b >>> 16, 2246822507) ^ Math.imul(a ^ a >>> 13, 3266489909);
|
|
1856
|
+
return `i${(a >>> 0).toString(36).padStart(7, "0")}${(b >>> 0).toString(36).padStart(7, "0")}${(outer.length + inner.length).toString(36)}`;
|
|
1857
|
+
}
|
|
1858
|
+
function build(input) {
|
|
1859
|
+
const { snapshot, registry, node: outer, props, data } = input;
|
|
1860
|
+
const body = structuredClone(input.compiled.body);
|
|
1861
|
+
const assets = {};
|
|
1862
|
+
const hrefs = /* @__PURE__ */ new Map();
|
|
1863
|
+
const innerData = {};
|
|
1864
|
+
const keep = (child) => registry.widget(child.type, child.v)?.kind !== "composite";
|
|
1865
|
+
const columns = body.columns?.map((column2) => ({ ...column2, children: column2.children.filter(keep) }));
|
|
1866
|
+
const stack = body.stack?.filter(keep);
|
|
1867
|
+
const widgets2 = columns !== void 0 ? columns.flatMap((column2) => column2.children) : stack ?? [];
|
|
1868
|
+
for (const widget of widgets2) {
|
|
1869
|
+
withoutAnchor(widget);
|
|
1870
|
+
delete widget.data;
|
|
1871
|
+
}
|
|
1872
|
+
for (const column2 of columns ?? []) withoutAnchor(column2);
|
|
1873
|
+
const byId = new Map(widgets2.map((widget) => [widget.id, widget]));
|
|
1874
|
+
const fields = new Map(snapshot.settings.map((field) => [field.key, field]));
|
|
1875
|
+
let assetCount = 0;
|
|
1876
|
+
const convert = (field, value) => {
|
|
1877
|
+
if (value === null) return null;
|
|
1878
|
+
if (field.translatable === true) return typeof value === "string" ? { en: value } : null;
|
|
1879
|
+
if (field.control === "image") {
|
|
1880
|
+
if (!isFrozenAsset(value)) return null;
|
|
1881
|
+
assetCount += 1;
|
|
1882
|
+
const id = `bound${String(assetCount)}`;
|
|
1883
|
+
assets[id] = value;
|
|
1884
|
+
return id;
|
|
1885
|
+
}
|
|
1886
|
+
if (field.control === "link") {
|
|
1887
|
+
if (!isRecord3(value) || typeof value.kind !== "string") return null;
|
|
1888
|
+
const { href, ...target } = value;
|
|
1889
|
+
if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
|
|
1890
|
+
hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
|
|
1891
|
+
return target;
|
|
1892
|
+
}
|
|
1893
|
+
return value;
|
|
1894
|
+
};
|
|
1895
|
+
for (const binding of input.compiled.bindings) {
|
|
1896
|
+
const field = fields.get(binding.setting);
|
|
1897
|
+
if (field === void 0 || !Object.hasOwn(props, binding.setting)) continue;
|
|
1898
|
+
const value = props[binding.setting];
|
|
1899
|
+
for (const target of binding.targets) {
|
|
1900
|
+
const inner = byId.get(target.node);
|
|
1901
|
+
const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target.prop);
|
|
1902
|
+
if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
|
|
1903
|
+
const converted = convert(field, value);
|
|
1904
|
+
if ((0, import_builder_schema19.validateSettingValue)(innerField, converted) !== null) continue;
|
|
1905
|
+
inner.props[target.prop] = converted;
|
|
1906
|
+
const responsive = inner.responsive;
|
|
1907
|
+
for (const device of DEVICES3) {
|
|
1908
|
+
if (responsive?.[device] !== void 0) delete responsive[device][target.prop];
|
|
1909
|
+
const raw = outer.responsive?.[device];
|
|
1910
|
+
const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
|
|
1911
|
+
if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && (0, import_builder_schema19.validateSettingValue)(innerField, raw[binding.setting]) === null) {
|
|
1912
|
+
const target$ = inner.responsive ?? (inner.responsive = {});
|
|
1913
|
+
(target$[device] ?? (target$[device] = {}))[target.prop] = raw[binding.setting];
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
for (const [name, input$] of input.compiled.data) {
|
|
1919
|
+
if (!Object.hasOwn(data, name) || data[name] === void 0) continue;
|
|
1920
|
+
const key = `composite.${name}`;
|
|
1921
|
+
for (const target of input$.targets) {
|
|
1922
|
+
const inner = byId.get(target.node);
|
|
1923
|
+
const def = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v);
|
|
1924
|
+
if (inner === void 0 || def?.data === void 0 || !Object.hasOwn(def.data, target.input)) continue;
|
|
1925
|
+
inner.data = { ...inner.data ?? {}, [target.input]: { source: key } };
|
|
1926
|
+
innerData[key] = data[name];
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
for (const widget of widgets2) widget.id = instanceId(outer.id, widget.id);
|
|
1930
|
+
for (const column2 of columns ?? []) column2.id = instanceId(outer.id, column2.id);
|
|
1931
|
+
const ids = { section: instanceId(outer.id, WRAP.section), column: instanceId(outer.id, WRAP.column), inner: instanceId(outer.id, WRAP.inner) };
|
|
1932
|
+
const column = {
|
|
1933
|
+
id: ids.column,
|
|
1934
|
+
type: "column",
|
|
1935
|
+
props: { width: 100 },
|
|
1936
|
+
children: columns !== void 0 ? [{ id: ids.inner, type: "inner-section", props: { width: "full" }, columns }] : stack ?? []
|
|
1937
|
+
};
|
|
1938
|
+
const document = {
|
|
1939
|
+
schemaVersion: 1,
|
|
1940
|
+
sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
|
|
1941
|
+
};
|
|
1942
|
+
let weight = 2 + (columns?.length ?? 0) + (columns === void 0 ? 0 : 1);
|
|
1943
|
+
for (const widget of widgets2) {
|
|
1944
|
+
const component = registry.component(widget);
|
|
1945
|
+
weight += 1 + (component === void 0 ? 0 : componentWeights.get(component) ?? 0);
|
|
1946
|
+
}
|
|
1947
|
+
return { document, assets, data: innerData, hrefs, weight };
|
|
1948
|
+
}
|
|
1949
|
+
function CompositeBody(props) {
|
|
1950
|
+
const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink } = props;
|
|
1951
|
+
const composite = compileComposite(snapshot);
|
|
1952
|
+
if (composite === null) return null;
|
|
1953
|
+
const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
|
|
1954
|
+
if (!(budget ?? new RenderBudget()).take(built.weight)) {
|
|
1955
|
+
warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
|
|
1956
|
+
return null;
|
|
1957
|
+
}
|
|
1958
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
1959
|
+
BuilderRenderer,
|
|
1960
|
+
{
|
|
1961
|
+
document: built.document,
|
|
1962
|
+
registry,
|
|
1963
|
+
data: built.data,
|
|
1964
|
+
locale,
|
|
1965
|
+
assets: built.assets,
|
|
1966
|
+
mediaOrigin,
|
|
1967
|
+
resolveLink: (target) => built.hrefs.get(JSON.stringify(target)) ?? resolveLink?.(target) ?? null
|
|
1968
|
+
}
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
function CompositeWidget(props) {
|
|
1972
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_react12.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(CompositeBody, { ...props }) }) });
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
// src/custom/factory.ts
|
|
1976
|
+
var isDisabled = (snapshot) => snapshot.status === "disabled";
|
|
1977
|
+
var Disabled = ({ editMode }) => editMode ? (0, import_react13.createElement)("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
|
|
1978
|
+
var customWidgetFactory = (snapshot, registry) => {
|
|
1979
|
+
if (isDisabled(snapshot)) return Disabled;
|
|
1980
|
+
if (snapshot.kind === "template") {
|
|
1981
|
+
const template = compileTemplate(snapshot, registry);
|
|
1982
|
+
if (template === null) return null;
|
|
1983
|
+
const Component2 = (props) => (0, import_react13.createElement)(TemplateWidget, { ...props, snapshot, registry });
|
|
1984
|
+
componentWeights.set(Component2, template.weight);
|
|
1985
|
+
return Component2;
|
|
1986
|
+
}
|
|
1987
|
+
if (compileComposite(snapshot) === null) return null;
|
|
1988
|
+
return (props) => (0, import_react13.createElement)(CompositeWidget, { ...props, snapshot, registry });
|
|
1989
|
+
};
|
|
1990
|
+
|
|
1991
|
+
// src/registry.ts
|
|
1992
|
+
var BUILTIN_PACKS = [basicPack];
|
|
1993
|
+
var DEFAULT_CUSTOM_WIDGET = customWidgetFactory;
|
|
1994
|
+
var customKey = (type, v) => `${type}@${String(v)}`;
|
|
1995
|
+
function createRendererRegistry(packs, options = {}) {
|
|
1996
|
+
const all = [...BUILTIN_PACKS, ...packs];
|
|
1997
|
+
const components = /* @__PURE__ */ new Map();
|
|
1998
|
+
const definitions = [];
|
|
1999
|
+
const sources = [];
|
|
2000
|
+
const resolvers = /* @__PURE__ */ new Map();
|
|
2001
|
+
for (const pack of all) {
|
|
2002
|
+
for (const { Component: Component2, ...definition } of pack.widgets) {
|
|
2003
|
+
const key = customKey(definition.type, definition.v);
|
|
2004
|
+
if (components.has(key)) continue;
|
|
2005
|
+
components.set(key, Component2);
|
|
2006
|
+
definitions.push(definition);
|
|
2007
|
+
}
|
|
2008
|
+
for (const { resolve, ...descriptor } of pack.dataSources) {
|
|
2009
|
+
if (resolvers.has(descriptor.id)) continue;
|
|
2010
|
+
resolvers.set(descriptor.id, resolve);
|
|
2011
|
+
sources.push(descriptor);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
const factory = options.customWidget ?? DEFAULT_CUSTOM_WIDGET;
|
|
2015
|
+
const build2 = (custom) => {
|
|
2016
|
+
const schema = (0, import_builder_schema20.createRegistry)(definitions, sources, custom);
|
|
2017
|
+
const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
|
|
2018
|
+
const built = /* @__PURE__ */ new Map();
|
|
2019
|
+
const registry = {
|
|
2020
|
+
widget: schema.widget,
|
|
2021
|
+
latest: schema.latest,
|
|
2022
|
+
source: schema.source,
|
|
2023
|
+
sources: schema.sources,
|
|
2024
|
+
all: schema.all,
|
|
2025
|
+
resolver: (id) => resolvers.get(id),
|
|
2026
|
+
component: (node) => {
|
|
2027
|
+
const key = customKey(node.type, node.v);
|
|
2028
|
+
const own = components.get(key);
|
|
2029
|
+
if (own !== void 0) return own;
|
|
2030
|
+
if (!node.type.startsWith("custom.") || factory === void 0) return void 0;
|
|
2031
|
+
const snapshot = snapshots.get(key);
|
|
2032
|
+
if (snapshot === void 0) return void 0;
|
|
2033
|
+
if (!built.has(key)) built.set(key, factory(snapshot, registry));
|
|
2034
|
+
return built.get(key) ?? void 0;
|
|
2035
|
+
},
|
|
2036
|
+
withCustom: (more) => build2([...custom, ...more])
|
|
2037
|
+
};
|
|
2038
|
+
return registry;
|
|
2039
|
+
};
|
|
2040
|
+
return build2([]);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// src/slot.tsx
|
|
2044
|
+
var import_react14 = require("react");
|
|
2045
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2046
|
+
function BuilderSlot({ name, context }) {
|
|
2047
|
+
const builder = useBuilder();
|
|
2048
|
+
if (builder === null || builder.site.status !== "ok") return null;
|
|
2049
|
+
const part = Object.hasOwn(builder.site.slots, name) ? builder.site.slots[name] : void 0;
|
|
2050
|
+
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2051
|
+
return (
|
|
2052
|
+
// Suspense inside the boundary: see parts.tsx.
|
|
2053
|
+
/* @__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 }) }) }) })
|
|
2054
|
+
);
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
// src/theme.ts
|
|
2058
|
+
var import_builder_schema21 = require("@usethrottle/builder-schema");
|
|
2059
|
+
var import_presets = require("@usethrottle/ui/presets");
|
|
2060
|
+
var isRecord4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2061
|
+
var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
2062
|
+
var HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
2063
|
+
var SCALE = { compact: 0.85, comfortable: 1, roomy: 1.25 };
|
|
2064
|
+
var PALETTE_KEYS = Object.keys(import_presets.PRESET_TOKENS.clean.light);
|
|
2065
|
+
function palette(base, over) {
|
|
2066
|
+
if (!isRecord4(over)) return base;
|
|
2067
|
+
const out = { ...base };
|
|
2068
|
+
for (const key of PALETTE_KEYS) {
|
|
2069
|
+
const value = over[key];
|
|
2070
|
+
if (typeof value === "string" && HEX.test(value)) out[key] = value;
|
|
2071
|
+
}
|
|
2072
|
+
return out;
|
|
2073
|
+
}
|
|
2074
|
+
function themeTokens(settings) {
|
|
2075
|
+
const theme = isRecord4(settings.theme) ? settings.theme : {};
|
|
2076
|
+
const preset = import_presets.PRESET_NAMES.includes(theme.preset) ? theme.preset : "clean";
|
|
2077
|
+
const customized = theme.customized === true;
|
|
2078
|
+
const base = import_presets.PRESET_TOKENS[preset];
|
|
2079
|
+
const colorScheme = theme.colorScheme === "light" || theme.colorScheme === "dark" ? theme.colorScheme : "auto";
|
|
2080
|
+
if (!customized) return { preset, customized, tokens: base, colorScheme };
|
|
2081
|
+
const fonts = isRecord4(theme.fonts) ? theme.fonts : {};
|
|
2082
|
+
return {
|
|
2083
|
+
preset,
|
|
2084
|
+
customized,
|
|
2085
|
+
colorScheme,
|
|
2086
|
+
tokens: {
|
|
2087
|
+
light: palette(base.light, theme.light),
|
|
2088
|
+
dark: palette(base.dark, theme.dark),
|
|
2089
|
+
fonts: {
|
|
2090
|
+
heading: str2(fonts.heading) ?? base.fonts.heading,
|
|
2091
|
+
body: str2(fonts.body) ?? base.fonts.body,
|
|
2092
|
+
mono: str2(fonts.mono) ?? base.fonts.mono
|
|
2093
|
+
},
|
|
2094
|
+
radius: typeof theme.radius === "number" && theme.radius >= 0 && theme.radius <= 32 ? theme.radius : base.radius,
|
|
2095
|
+
spacingScale: theme.spacingScale === "compact" || theme.spacingScale === "roomy" ? theme.spacingScale : base.spacingScale
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
var GENERIC = { serif: "serif", sans: "sans-serif", mono: "monospace", display: "sans-serif" };
|
|
2100
|
+
var SYSTEM_STACK = {
|
|
2101
|
+
"system-sans": 'system-ui, -apple-system, "Segoe UI", sans-serif',
|
|
2102
|
+
"system-serif": 'Georgia, "Times New Roman", serif',
|
|
2103
|
+
"system-mono": "ui-monospace, SFMono-Regular, Menlo, monospace"
|
|
2104
|
+
};
|
|
2105
|
+
function fontStack(family) {
|
|
2106
|
+
if (Object.hasOwn(SYSTEM_STACK, family)) return SYSTEM_STACK[family];
|
|
2107
|
+
const known = import_builder_schema21.SITE_FONTS.find((f) => f.family === family);
|
|
2108
|
+
if (known === void 0 || !/^[A-Za-z0-9 ]{1,60}$/.test(family)) return SYSTEM_STACK["system-sans"];
|
|
2109
|
+
return `"${family}", ${Object.hasOwn(GENERIC, known.category) ? GENERIC[known.category] : "sans-serif"}`;
|
|
2110
|
+
}
|
|
2111
|
+
function variables(p) {
|
|
2112
|
+
return {
|
|
2113
|
+
colorPrimary: p.colorPrimary,
|
|
2114
|
+
colorPrimaryForeground: p.colorPrimaryForeground,
|
|
2115
|
+
colorBackground: p.colorBackground,
|
|
2116
|
+
colorSurface: p.colorSurface,
|
|
2117
|
+
colorForeground: p.colorForeground,
|
|
2118
|
+
colorMuted: p.colorMuted,
|
|
2119
|
+
colorMutedForeground: p.colorMutedForeground,
|
|
2120
|
+
colorBorder: p.colorBorder,
|
|
2121
|
+
colorBorderControl: p.colorBorderControl,
|
|
2122
|
+
colorSuccess: p.colorSuccess,
|
|
2123
|
+
colorWarning: p.colorWarning,
|
|
2124
|
+
colorDanger: p.colorDanger
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
function appearanceOf(settings) {
|
|
2128
|
+
const { tokens, colorScheme } = themeTokens(settings);
|
|
2129
|
+
return {
|
|
2130
|
+
theme: colorScheme,
|
|
2131
|
+
variables: {
|
|
2132
|
+
...variables(tokens.light),
|
|
2133
|
+
fontFamily: fontStack(tokens.fonts.body),
|
|
2134
|
+
borderRadius: `${String(tokens.radius)}px`
|
|
2135
|
+
},
|
|
2136
|
+
darkVariables: variables(tokens.dark)
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
var kebab = (key) => key.replace(/^color/, "").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/^([A-Z])/, (c) => c.toLowerCase()).toLowerCase();
|
|
2140
|
+
function colourDecls(p) {
|
|
2141
|
+
return PALETTE_KEYS.map((key) => `--tb-color-${kebab(key)}:${p[key]}`).join(";");
|
|
2142
|
+
}
|
|
2143
|
+
function themeCss(settings) {
|
|
2144
|
+
const { tokens, colorScheme } = themeTokens(settings);
|
|
2145
|
+
const light = `:root{--tb-scale:${String(SCALE[tokens.spacingScale])};${colourDecls(tokens.light)}}`;
|
|
2146
|
+
const dark = colourDecls(tokens.dark);
|
|
2147
|
+
if (colorScheme === "light") return light;
|
|
2148
|
+
if (colorScheme === "dark") return `${light}:root{${dark}}`;
|
|
2149
|
+
return `${light}@media (prefers-color-scheme:dark){:root{${dark}}}`;
|
|
2150
|
+
}
|
|
2151
|
+
function makeResolveLink(settings, packs) {
|
|
2152
|
+
const routes = isRecord4(settings.routes) ? settings.routes : {};
|
|
2153
|
+
const pageRoute = str2(routes.page) ?? "/pages/{handle}";
|
|
2154
|
+
return (target) => {
|
|
2155
|
+
for (const pack of packs) {
|
|
2156
|
+
const href = pack.linkTargets?.resolve(target) ?? null;
|
|
2157
|
+
if (href !== null) return (0, import_builder_schema21.safeUrl)(href, "href", { mediaOrigin: "" });
|
|
2158
|
+
}
|
|
2159
|
+
if (target.kind === "url") return (0, import_builder_schema21.safeUrl)(target.href, "href", { mediaOrigin: "" });
|
|
2160
|
+
if (typeof target.href === "string") return (0, import_builder_schema21.safeUrl)(target.href, "href", { mediaOrigin: "" });
|
|
2161
|
+
if (target.kind === "page") {
|
|
2162
|
+
const slug = str2(target.slug) ?? str2(target.handle);
|
|
2163
|
+
if (slug !== void 0 && /^[A-Za-z0-9._~-]{1,200}$/.test(slug)) {
|
|
2164
|
+
return (0, import_builder_schema21.safeUrl)(pageRoute.replace("{handle}", slug), "href", { mediaOrigin: "" });
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
return null;
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
var MENU_KINDS = /* @__PURE__ */ new Set(["category", "collection", "product", "page", "search", "url"]);
|
|
2171
|
+
function menuItems(items, resolve, depth = 0) {
|
|
2172
|
+
if (!Array.isArray(items) || depth > 3) return [];
|
|
2173
|
+
const out = [];
|
|
2174
|
+
for (const item of items) {
|
|
2175
|
+
if (!isRecord4(item) || !isRecord4(item.target) || typeof item.target.kind !== "string") continue;
|
|
2176
|
+
const label = str2(item.label);
|
|
2177
|
+
const href = resolve(item.target);
|
|
2178
|
+
if (label === void 0 || href === null) continue;
|
|
2179
|
+
const kind = MENU_KINDS.has(item.target.kind) ? item.target.kind : void 0;
|
|
2180
|
+
const children = menuItems(item.children, resolve, depth + 1);
|
|
2181
|
+
out.push({
|
|
2182
|
+
label,
|
|
2183
|
+
href,
|
|
2184
|
+
...kind === void 0 ? {} : { kind },
|
|
2185
|
+
...children.length === 0 ? {} : { children }
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
return out;
|
|
2189
|
+
}
|
|
2190
|
+
var assetUrl = (v, mediaOrigin) => {
|
|
2191
|
+
const raw = typeof v === "string" ? v : isRecord4(v) ? v.url : void 0;
|
|
2192
|
+
return typeof raw === "string" ? (0, import_builder_schema21.safeUrl)(raw, "src", { mediaOrigin }) ?? void 0 : void 0;
|
|
2193
|
+
};
|
|
2194
|
+
function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
|
|
2195
|
+
const { preset, customized, tokens, colorScheme } = themeTokens(settings);
|
|
2196
|
+
const brand = isRecord4(settings.brand) ? settings.brand : {};
|
|
2197
|
+
const logo = isRecord4(brand.logo) ? brand.logo : {};
|
|
2198
|
+
const light = assetUrl(logo.light, mediaOrigin);
|
|
2199
|
+
const dark = assetUrl(logo.dark, mediaOrigin);
|
|
2200
|
+
const favicon = assetUrl(brand.favicon, mediaOrigin);
|
|
2201
|
+
const menus = isRecord4(settings.menus) ? Object.fromEntries(Object.entries(settings.menus).map(([name, items]) => [name, menuItems(items, resolve)])) : {};
|
|
2202
|
+
const announcement = isRecord4(settings.announcement) ? settings.announcement : null;
|
|
2203
|
+
const message = announcement === null ? void 0 : str2(announcement.message);
|
|
2204
|
+
const announcementHref = announcement !== null && isRecord4(announcement.target) && typeof announcement.target.kind === "string" ? resolve(announcement.target) : null;
|
|
2205
|
+
const strings = isRecord4(settings.strings) ? Object.fromEntries(Object.entries(settings.strings).filter((entry) => typeof entry[1] === "string")) : {};
|
|
2206
|
+
const seo = isRecord4(settings.seo) ? settings.seo : {};
|
|
2207
|
+
const routes = isRecord4(settings.routes) ? settings.routes : {};
|
|
2208
|
+
const connections = isRecord4(settings.connections) ? settings.connections : {};
|
|
2209
|
+
const shareImage = assetUrl(seo.shareImage, mediaOrigin);
|
|
2210
|
+
const titleTemplate = str2(seo.titleTemplate);
|
|
2211
|
+
const defaultDescription = str2(seo.defaultDescription);
|
|
2212
|
+
const pageRoute = str2(routes.page);
|
|
2213
|
+
return {
|
|
2214
|
+
source: "builder",
|
|
2215
|
+
theme: { preset, customized, colorScheme, ...customized ? { values: tokens } : {} },
|
|
2216
|
+
brand: {
|
|
2217
|
+
...str2(brand.storeName) === void 0 ? {} : { storeName: str2(brand.storeName) },
|
|
2218
|
+
logo: light === void 0 && dark === void 0 ? null : { ...light === void 0 ? {} : { light }, ...dark === void 0 ? {} : { dark } },
|
|
2219
|
+
favicon: favicon ?? null
|
|
2220
|
+
},
|
|
2221
|
+
menus,
|
|
2222
|
+
announcement: announcement !== null && announcement.enabled === true && message !== void 0 ? { message, ...announcementHref === null ? {} : { href: announcementHref } } : null,
|
|
2223
|
+
strings,
|
|
2224
|
+
seo: {
|
|
2225
|
+
...titleTemplate === void 0 ? {} : { titleTemplate },
|
|
2226
|
+
...defaultDescription === void 0 ? {} : { defaultDescription },
|
|
2227
|
+
...shareImage === void 0 ? {} : { shareImage }
|
|
2228
|
+
},
|
|
2229
|
+
...pageRoute === void 0 ? {} : { routes: { page: pageRoute } },
|
|
2230
|
+
connections: {
|
|
2231
|
+
throttlePublishableKey: typeof connections.throttlePublishableKey === "string" ? connections.throttlePublishableKey : null
|
|
2232
|
+
},
|
|
2233
|
+
...pageOutlet === void 0 ? {} : { pageOutlet }
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
// src/provider.tsx
|
|
2238
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2239
|
+
var EMPTY = {};
|
|
2240
|
+
function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
2241
|
+
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2242
|
+
const registryRef = (0, import_react15.useRef)(null);
|
|
2243
|
+
if (registryRef.current?.key !== packsKey) {
|
|
2244
|
+
registryRef.current = { key: packsKey, registry: createRendererRegistry(packs) };
|
|
2245
|
+
}
|
|
2246
|
+
const registry = registryRef.current.registry;
|
|
2247
|
+
const builder = (0, import_react15.useMemo)(
|
|
2248
|
+
() => client ?? (builderKey === void 0 ? null : (0, import_builder2.createBuilderClient)({ builderKey })),
|
|
2249
|
+
[client, builderKey]
|
|
2250
|
+
);
|
|
2251
|
+
const mediaOrigin = site.status === "ok" ? site.mediaOrigin : "";
|
|
2252
|
+
const settings = site.status === "ok" ? site.settings : EMPTY;
|
|
2253
|
+
const resolveLink = (0, import_react15.useMemo)(() => makeResolveLink(settings, packs), [settings, packs]);
|
|
2254
|
+
const outlets = (0, import_react15.useRef)(/* @__PURE__ */ new Map());
|
|
2255
|
+
const renderers = (0, import_react15.useRef)(/* @__PURE__ */ new Map());
|
|
2256
|
+
const pageOutlet = (0, import_react15.useCallback)((handle) => {
|
|
2257
|
+
let outlet = outlets.current.get(handle);
|
|
2258
|
+
if (outlet === void 0) {
|
|
2259
|
+
outlet = function PageOutlet() {
|
|
2260
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(PartBoundary, { label: `Builder page ${handle}`, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react15.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderPage, { slug: handle }) }) });
|
|
2261
|
+
};
|
|
2262
|
+
outlets.current.set(handle, outlet);
|
|
2263
|
+
}
|
|
2264
|
+
return outlet;
|
|
2265
|
+
}, []);
|
|
2266
|
+
const resolveSlot = (0, import_react15.useCallback)(
|
|
2267
|
+
(name) => {
|
|
2268
|
+
const part = site.status === "ok" && Object.hasOwn(site.slots, name) ? site.slots[name] : void 0;
|
|
2269
|
+
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2270
|
+
let renderer = renderers.current.get(name);
|
|
2271
|
+
if (renderer === void 0) {
|
|
2272
|
+
renderer = function SlotRenderer({ context }) {
|
|
2273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderSlot, { name, context });
|
|
2274
|
+
};
|
|
2275
|
+
renderers.current.set(name, renderer);
|
|
2276
|
+
}
|
|
2277
|
+
return renderer;
|
|
2278
|
+
},
|
|
2279
|
+
[site]
|
|
2280
|
+
);
|
|
2281
|
+
const value = (0, import_react15.useMemo)(
|
|
2282
|
+
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, resolveLink }),
|
|
2283
|
+
[builder, packs, registry, site, mediaOrigin, resolveLink]
|
|
2284
|
+
);
|
|
2285
|
+
const design = (0, import_react15.useMemo)(
|
|
2286
|
+
() => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
|
|
2287
|
+
[site, resolveLink, pageOutlet, mediaOrigin]
|
|
2288
|
+
);
|
|
2289
|
+
const appearance = (0, import_react15.useMemo)(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
|
|
2290
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_ui6.ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_ui6.SiteDesignProvider, { value: design, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_ui6.SlotOutletProvider, { resolve: resolveSlot, children: [
|
|
2291
|
+
site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("style", { children: themeCss(site.settings) }) : null,
|
|
2292
|
+
children
|
|
2293
|
+
] }) }) }) });
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
// src/parts.tsx
|
|
2297
|
+
var import_react16 = require("react");
|
|
2298
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
2299
|
+
function Part({ name, tag }) {
|
|
2300
|
+
const builder = useBuilder();
|
|
2301
|
+
if (builder === null || builder.site.status !== "ok") return null;
|
|
2302
|
+
const part = builder.site[name];
|
|
2303
|
+
if (part.document.sections.length === 0) return null;
|
|
2304
|
+
const Tag = tag;
|
|
2305
|
+
return (
|
|
2306
|
+
// Error boundaries do not catch on the server: the Suspense inside turns a throw
|
|
2307
|
+
// during SSR into "render nothing here" and the client retries under the boundary.
|
|
2308
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(PartBoundary, { label: `Builder ${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Tag, { "data-throttle-part": `builder-${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_react16.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(PartView, { part }) }) }) })
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
var BuilderHeader = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Part, { name: "header", tag: "header" });
|
|
2312
|
+
var BuilderFooter = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Part, { name: "footer", tag: "footer" });
|
|
2313
|
+
|
|
2314
|
+
// src/index.ts
|
|
2315
|
+
var import_builder3 = require("@usethrottle/builder");
|