@usethrottle/builder-react 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +31 -0
- package/dist/{chunk-IDGSPYRH.cjs → chunk-3HSHGY7M.cjs} +1381 -487
- package/dist/{chunk-LXBCOZP2.js → chunk-TS2WCTZ3.js} +1415 -521
- package/dist/index.cjs +1699 -750
- package/dist/index.d.cts +200 -38
- package/dist/index.d.ts +200 -38
- package/dist/index.js +1673 -720
- package/dist/interactions-runtime.cjs +207 -0
- package/dist/interactions-runtime.js +186 -0
- package/dist/next.cjs +6 -6
- package/dist/next.d.cts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +1 -1
- package/dist/{seo-Dz439Jlk.d.cts → seo-CNZ9DrlU.d.cts} +16 -1
- package/dist/{seo-Dz439Jlk.d.ts → seo-CNZ9DrlU.d.ts} +16 -1
- package/dist/server.cjs +26 -22
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +9 -5
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -5,9 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
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,
|
|
9
|
-
for (var name in
|
|
10
|
-
__defProp(target, name, { get:
|
|
8
|
+
var __export = (target, all2) => {
|
|
9
|
+
for (var name in all2)
|
|
10
|
+
__defProp(target, name, { get: all2[name], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -36,9 +36,13 @@ __export(src_exports, {
|
|
|
36
36
|
BuilderRenderer: () => BuilderRenderer,
|
|
37
37
|
BuilderSlot: () => BuilderSlot,
|
|
38
38
|
BuilderUnavailableError: () => import_builder3.BuilderUnavailableError,
|
|
39
|
+
CODE_ROUTE_DENY: () => CODE_ROUTE_DENY,
|
|
39
40
|
CUSTOM_WIDGET_CONTAINMENT: () => CUSTOM_WIDGET_CONTAINMENT,
|
|
41
|
+
CodeWidget: () => CodeWidget,
|
|
40
42
|
CompositeWidget: () => CompositeWidget,
|
|
43
|
+
DEFAULT_CATALOG_ROUTES: () => DEFAULT_CATALOG_ROUTES,
|
|
41
44
|
MAX_RENDERED_NODES: () => MAX_RENDERED_NODES,
|
|
45
|
+
MissingSavedSection: () => MissingSavedSection,
|
|
42
46
|
NodeWrapper: () => NodeWrapper,
|
|
43
47
|
RenderBudget: () => RenderBudget,
|
|
44
48
|
RichText: () => RichText,
|
|
@@ -47,14 +51,18 @@ __export(src_exports, {
|
|
|
47
51
|
basicPack: () => basicPack,
|
|
48
52
|
bindingKey: () => bindingKey,
|
|
49
53
|
bindingsOf: () => bindingsOf,
|
|
54
|
+
codeScriptUrl: () => codeScriptUrl,
|
|
50
55
|
collectBindings: () => collectBindings,
|
|
51
56
|
compileResponsiveCss: () => compileResponsiveCss,
|
|
52
57
|
createRendererRegistry: () => createRendererRegistry,
|
|
53
58
|
cssValue: () => cssValue,
|
|
54
59
|
customWidgetFactory: () => customWidgetFactory,
|
|
55
60
|
embedSrc: () => embedSrc,
|
|
61
|
+
expandSavedSections: () => expandSavedSections,
|
|
56
62
|
fitsBudget: () => fitsBudget,
|
|
63
|
+
isCodeRoute: () => isCodeRoute,
|
|
57
64
|
isFrozenAsset: () => isFrozenAsset,
|
|
65
|
+
jsonForScript: () => jsonForScript,
|
|
58
66
|
parseRichText: () => parseRichText,
|
|
59
67
|
parseVideoUrl: () => parseVideoUrl,
|
|
60
68
|
pickLocale: () => pickLocale,
|
|
@@ -65,8 +73,8 @@ __export(src_exports, {
|
|
|
65
73
|
module.exports = __toCommonJS(src_exports);
|
|
66
74
|
|
|
67
75
|
// src/renderer.tsx
|
|
68
|
-
var
|
|
69
|
-
var
|
|
76
|
+
var import_react9 = require("react");
|
|
77
|
+
var import_builder_schema11 = require("@usethrottle/builder-schema");
|
|
70
78
|
|
|
71
79
|
// src/budget.ts
|
|
72
80
|
var import_builder_schema = require("@usethrottle/builder-schema");
|
|
@@ -82,33 +90,838 @@ var RenderBudget = class {
|
|
|
82
90
|
this.spent += count;
|
|
83
91
|
return true;
|
|
84
92
|
}
|
|
85
|
-
get used() {
|
|
86
|
-
return this.spent;
|
|
93
|
+
get used() {
|
|
94
|
+
return this.spent;
|
|
95
|
+
}
|
|
96
|
+
get exhausted() {
|
|
97
|
+
return this.spent >= this.limit;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var fitsBudget = (ast, limit = MAX_RENDERED_NODES) => (0, import_builder_schema.templateWeight)(ast) <= limit;
|
|
101
|
+
|
|
102
|
+
// src/code/code-widget.tsx
|
|
103
|
+
var import_react7 = require("react");
|
|
104
|
+
var import_builder_schema8 = require("@usethrottle/builder-schema");
|
|
105
|
+
|
|
106
|
+
// src/custom/custom-css.tsx
|
|
107
|
+
var import_builder_schema2 = require("@usethrottle/builder-schema");
|
|
108
|
+
|
|
109
|
+
// src/widget-style.tsx
|
|
110
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
111
|
+
function WidgetStyle({ css }) {
|
|
112
|
+
if (css === "" || css.includes("<")) return null;
|
|
113
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: css });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/custom/custom-css.tsx
|
|
117
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
118
|
+
function scopedCss(source, type) {
|
|
119
|
+
if (source === void 0 || source === "") return "";
|
|
120
|
+
if (typeof source !== "string") return null;
|
|
121
|
+
const result = (0, import_builder_schema2.sanitizeWidgetCss)(source, type);
|
|
122
|
+
return result.ok ? result.css : null;
|
|
123
|
+
}
|
|
124
|
+
function CustomCss({ css }) {
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WidgetStyle, { css });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/custom/interpreter.tsx
|
|
129
|
+
var import_react = require("react");
|
|
130
|
+
var import_builder_schema3 = require("@usethrottle/builder-schema");
|
|
131
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
132
|
+
var MAX_OUTPUT_CHARS = 1e6;
|
|
133
|
+
var MAX_ATTR_CHARS = 2e3;
|
|
134
|
+
var MAX_DEPTH = 24;
|
|
135
|
+
function newEnv(env) {
|
|
136
|
+
return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
|
|
137
|
+
}
|
|
138
|
+
var BLOCKED = /* @__PURE__ */ new Set([
|
|
139
|
+
"__proto__",
|
|
140
|
+
"constructor",
|
|
141
|
+
"prototype",
|
|
142
|
+
...Object.getOwnPropertyNames(Object.prototype)
|
|
143
|
+
]);
|
|
144
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
145
|
+
function step(value, key) {
|
|
146
|
+
if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
|
|
147
|
+
return value[key];
|
|
148
|
+
}
|
|
149
|
+
function lookup(path, env, scope) {
|
|
150
|
+
const [root, ...rest] = path;
|
|
151
|
+
if (root === void 0) return void 0;
|
|
152
|
+
if (root === "locale") return rest.length === 0 ? env.locale : void 0;
|
|
153
|
+
let value;
|
|
154
|
+
if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
|
|
155
|
+
else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
|
|
156
|
+
else if (scope.has(root)) value = scope.get(root);
|
|
157
|
+
else return void 0;
|
|
158
|
+
for (const key of rest) {
|
|
159
|
+
value = step(value, key);
|
|
160
|
+
if (value === void 0) return void 0;
|
|
161
|
+
}
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
function truthy(value) {
|
|
165
|
+
if (value === null || value === void 0 || value === false || value === "") return false;
|
|
166
|
+
if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
|
|
167
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
function asText(value) {
|
|
171
|
+
if (typeof value === "string") return value;
|
|
172
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
173
|
+
return "";
|
|
174
|
+
}
|
|
175
|
+
function filtered(value, filters) {
|
|
176
|
+
let text = asText(value);
|
|
177
|
+
for (const filter of filters) {
|
|
178
|
+
switch (filter.name) {
|
|
179
|
+
case "upper":
|
|
180
|
+
text = text.toUpperCase();
|
|
181
|
+
break;
|
|
182
|
+
case "lower":
|
|
183
|
+
text = text.toLowerCase();
|
|
184
|
+
break;
|
|
185
|
+
case "truncate": {
|
|
186
|
+
const chars = Array.from(text);
|
|
187
|
+
if (chars.length > filter.n) text = `${chars.slice(0, filter.n).join("")}\u2026`;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case "default":
|
|
191
|
+
if (text === "") text = filter.text;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return text;
|
|
196
|
+
}
|
|
197
|
+
function spend(env, count) {
|
|
198
|
+
if (count > env.charsLeft) {
|
|
199
|
+
env.stopped = true;
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
env.charsLeft -= count;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
var ELEMENTS = new Set(import_builder_schema3.ALLOWED_ELEMENTS);
|
|
206
|
+
var VOIDS = new Set(import_builder_schema3.VOID_ELEMENTS);
|
|
207
|
+
var ROLES = new Set(import_builder_schema3.ALLOWED_ROLES);
|
|
208
|
+
function attrAllowed(tag, name) {
|
|
209
|
+
if (import_builder_schema3.DATA_ATTR_RE.test(name)) return !name.startsWith(import_builder_schema3.RESERVED_DATA_PREFIX);
|
|
210
|
+
const own = Object.hasOwn(import_builder_schema3.ALLOWED_ATTRS, tag) ? import_builder_schema3.ALLOWED_ATTRS[tag] : void 0;
|
|
211
|
+
return (import_builder_schema3.ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
|
|
212
|
+
}
|
|
213
|
+
function attrText(attr, env, scope) {
|
|
214
|
+
return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
|
|
215
|
+
}
|
|
216
|
+
function urlSource(attr, env, scope) {
|
|
217
|
+
const [only] = attr.value;
|
|
218
|
+
if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
|
|
219
|
+
const value = lookup(only.path, env, scope);
|
|
220
|
+
if (isPlainObject(value)) {
|
|
221
|
+
if (typeof value.href === "string") return value.href;
|
|
222
|
+
if (typeof value.url === "string") return value.url;
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
function attrProp(tag, attr, env, scope) {
|
|
228
|
+
const { name } = attr;
|
|
229
|
+
if (!attrAllowed(tag, name)) return null;
|
|
230
|
+
if (name === "href" || name === "src") {
|
|
231
|
+
const safe = (0, import_builder_schema3.safeUrl)(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
|
|
232
|
+
return safe === null || !spend(env, safe.length) ? null : [name, safe];
|
|
233
|
+
}
|
|
234
|
+
const text = attrText(attr, env, scope);
|
|
235
|
+
if (text === "" || text.length > MAX_ATTR_CHARS) return null;
|
|
236
|
+
let value = text;
|
|
237
|
+
if (name === "class") {
|
|
238
|
+
const tokens = text.split(/\s+/).filter((token) => import_builder_schema3.CLASS_TOKEN_RE.test(token) && !(0, import_builder_schema3.isReservedClass)(token));
|
|
239
|
+
if (tokens.length === 0) return null;
|
|
240
|
+
value = tokens.join(" ");
|
|
241
|
+
} else if (name === "role") {
|
|
242
|
+
if (!ROLES.has(text)) return null;
|
|
243
|
+
} else if (name === "aria-hidden") {
|
|
244
|
+
if (text !== "true" && text !== "false") return null;
|
|
245
|
+
}
|
|
246
|
+
if (!spend(env, value.length)) return null;
|
|
247
|
+
return [name === "class" ? "className" : name, value];
|
|
248
|
+
}
|
|
249
|
+
function renderElement(node, env, scope, depth, key) {
|
|
250
|
+
const tag = node.tag;
|
|
251
|
+
if (!ELEMENTS.has(tag)) return null;
|
|
252
|
+
const props = { key };
|
|
253
|
+
for (const attr of node.attrs) {
|
|
254
|
+
const prop = attrProp(tag, attr, env, scope);
|
|
255
|
+
if (prop !== null) props[prop[0]] = prop[1];
|
|
256
|
+
}
|
|
257
|
+
if (VOIDS.has(tag)) return (0, import_react.createElement)(tag, props);
|
|
258
|
+
return (0, import_react.createElement)(tag, props, renderNodes(node.children, env, scope, depth + 1));
|
|
259
|
+
}
|
|
260
|
+
function renderNodes(nodes, env, scope, depth) {
|
|
261
|
+
const out = [];
|
|
262
|
+
if (depth > MAX_DEPTH) return out;
|
|
263
|
+
for (const node of nodes) {
|
|
264
|
+
if (env.stopped) break;
|
|
265
|
+
if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
|
|
266
|
+
env.stopped = true;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
switch (node.type) {
|
|
270
|
+
case "text":
|
|
271
|
+
if (spend(env, node.value.length)) out.push(node.value);
|
|
272
|
+
break;
|
|
273
|
+
case "output": {
|
|
274
|
+
const text = filtered(lookup(node.path, env, scope), node.filters);
|
|
275
|
+
if (text !== "" && spend(env, text.length)) out.push(text);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
case "if": {
|
|
279
|
+
const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
|
|
280
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react.Fragment, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case "unless":
|
|
284
|
+
if (!truthy(lookup(node.path, env, scope))) {
|
|
285
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react.Fragment, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
|
|
286
|
+
}
|
|
287
|
+
break;
|
|
288
|
+
case "each": {
|
|
289
|
+
const list = lookup(node.path, env, scope);
|
|
290
|
+
if (!Array.isArray(list)) break;
|
|
291
|
+
const count = Math.min(list.length, import_builder_schema3.EACH_ITERATION_CAP);
|
|
292
|
+
for (let i = 0; i < count && !env.stopped; i += 1) {
|
|
293
|
+
const inner = new Map(scope).set(node.as, list[i]);
|
|
294
|
+
out.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react.Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case "element":
|
|
299
|
+
out.push(renderElement(node, env, scope, depth, out.length));
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
function renderTemplate(ast, env) {
|
|
306
|
+
return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/custom/template-widget.tsx
|
|
310
|
+
var import_react5 = require("react");
|
|
311
|
+
var import_builder_schema7 = require("@usethrottle/builder-schema");
|
|
312
|
+
|
|
313
|
+
// src/part-view.tsx
|
|
314
|
+
var import_react4 = require("react");
|
|
315
|
+
|
|
316
|
+
// src/context.ts
|
|
317
|
+
var import_react2 = require("react");
|
|
318
|
+
function codeRenderOf(builder, runtime) {
|
|
319
|
+
return { runtime, pathname: builder.pathname, routes: builder.codeRoutes, preview: builder.mode === "preview" };
|
|
320
|
+
}
|
|
321
|
+
var BuilderContext = typeof import_react2.createContext === "function" ? (0, import_react2.createContext)(null) : null;
|
|
322
|
+
var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
|
|
323
|
+
|
|
324
|
+
// src/saved-section.tsx
|
|
325
|
+
var import_builder_schema5 = require("@usethrottle/builder-schema");
|
|
326
|
+
|
|
327
|
+
// src/node-wrapper.tsx
|
|
328
|
+
var import_builder_schema4 = require("@usethrottle/builder-schema");
|
|
329
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
330
|
+
var CUSTOM_WIDGET_CONTAINMENT = {
|
|
331
|
+
contain: "layout paint",
|
|
332
|
+
isolation: "isolate",
|
|
333
|
+
overflow: "clip"
|
|
334
|
+
};
|
|
335
|
+
var PART_NAME = {
|
|
336
|
+
section: "builder-section",
|
|
337
|
+
column: "builder-column",
|
|
338
|
+
widget: "builder-widget"
|
|
339
|
+
};
|
|
340
|
+
function NodeWrapper(props) {
|
|
341
|
+
const { id, part, type, className, anchor, copyAnchor, custom, missing, attributes, edit, entrance, children } = props;
|
|
342
|
+
const Tag = props.as ?? "div";
|
|
343
|
+
const handlers = edit === void 0 ? {} : {
|
|
344
|
+
onClickCapture: (event) => {
|
|
345
|
+
const target = event.target;
|
|
346
|
+
if (target?.closest?.("a[href]") != null) event.preventDefault();
|
|
347
|
+
},
|
|
348
|
+
onClick: (event) => {
|
|
349
|
+
event.stopPropagation();
|
|
350
|
+
edit.onSelect(id);
|
|
351
|
+
},
|
|
352
|
+
onMouseOver: (event) => {
|
|
353
|
+
event.stopPropagation();
|
|
354
|
+
edit.onHover(id);
|
|
355
|
+
},
|
|
356
|
+
onMouseLeave: () => edit.onHover(null)
|
|
357
|
+
};
|
|
358
|
+
const style = custom === true || entrance !== void 0 ? {
|
|
359
|
+
...custom === true ? CUSTOM_WIDGET_CONTAINMENT : {},
|
|
360
|
+
...entrance !== void 0 && entrance.delayMs > 0 ? { "--tb-ed": `${String(entrance.delayMs)}ms` } : {}
|
|
361
|
+
} : void 0;
|
|
362
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
363
|
+
Tag,
|
|
364
|
+
{
|
|
365
|
+
className,
|
|
366
|
+
"data-b-id": id,
|
|
367
|
+
"data-throttle-part": PART_NAME[part],
|
|
368
|
+
...type === void 0 ? {} : { "data-b-type": type },
|
|
369
|
+
...custom === true && type !== void 0 ? { "data-b-w": type } : {},
|
|
370
|
+
...missing === true ? { "data-b-missing": "" } : {},
|
|
371
|
+
...attributes,
|
|
372
|
+
...typeof anchor === "string" && import_builder_schema4.ANCHOR_RE.test(anchor) ? { id: anchor } : {},
|
|
373
|
+
...typeof copyAnchor === "string" && import_builder_schema4.ANCHOR_RE.test(copyAnchor) ? { "data-b-anchor": copyAnchor } : {},
|
|
374
|
+
...entrance === void 0 ? {} : { "data-b-entrance": entrance.name },
|
|
375
|
+
...style === void 0 || Object.keys(style).length === 0 ? {} : { style },
|
|
376
|
+
...handlers,
|
|
377
|
+
children
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/warn.ts
|
|
383
|
+
var seen = /* @__PURE__ */ new Set();
|
|
384
|
+
function warnOnce(key, message) {
|
|
385
|
+
if (seen.has(key)) return;
|
|
386
|
+
seen.add(key);
|
|
387
|
+
console.warn(`[throttle-builder] ${message}`);
|
|
388
|
+
}
|
|
389
|
+
var isDevelopment = () => typeof process === "undefined" || process.env?.NODE_ENV !== "production";
|
|
390
|
+
|
|
391
|
+
// src/saved-section.tsx
|
|
392
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
393
|
+
var pid = (refId, id) => `${refId}-${id}`;
|
|
394
|
+
var MAX_EXPANDED_NODES = 2e4;
|
|
395
|
+
function prefixAnchor(refId, props) {
|
|
396
|
+
const anchor = props.anchor;
|
|
397
|
+
if (typeof anchor !== "string") return props;
|
|
398
|
+
const prefixed = pid(refId, anchor);
|
|
399
|
+
const { anchor: _drop, ...rest } = props;
|
|
400
|
+
void _drop;
|
|
401
|
+
return import_builder_schema5.ANCHOR_RE.test(prefixed) ? { ...rest, anchor: prefixed } : rest;
|
|
402
|
+
}
|
|
403
|
+
function prefixColumn(refId, column) {
|
|
404
|
+
return {
|
|
405
|
+
...column,
|
|
406
|
+
id: pid(refId, column.id),
|
|
407
|
+
props: prefixAnchor(refId, column.props),
|
|
408
|
+
children: column.children.map(
|
|
409
|
+
(child) => child.type === "inner-section" ? prefixSection(refId, child) : { ...child, id: pid(refId, child.id), props: prefixAnchor(refId, child.props) }
|
|
410
|
+
)
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function prefixSection(refId, section) {
|
|
414
|
+
return {
|
|
415
|
+
...section,
|
|
416
|
+
id: pid(refId, section.id),
|
|
417
|
+
props: prefixAnchor(refId, section.props),
|
|
418
|
+
columns: section.columns.map((column) => prefixColumn(refId, column))
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
var parsed = /* @__PURE__ */ new WeakMap();
|
|
422
|
+
function sectionOf(entry) {
|
|
423
|
+
const cached = parsed.get(entry);
|
|
424
|
+
if (cached !== void 0) return cached;
|
|
425
|
+
const result = import_builder_schema5.sectionNodeSchema.safeParse(entry.section);
|
|
426
|
+
const section = result.success ? result.data : null;
|
|
427
|
+
parsed.set(entry, section);
|
|
428
|
+
return section;
|
|
429
|
+
}
|
|
430
|
+
var sized = /* @__PURE__ */ new WeakMap();
|
|
431
|
+
function sizeOf(section) {
|
|
432
|
+
const known = sized.get(section);
|
|
433
|
+
if (known !== void 0) return known;
|
|
434
|
+
let size = 0;
|
|
435
|
+
(0, import_builder_schema5.walkNodes)({ sections: [section] }, () => {
|
|
436
|
+
size += 1;
|
|
437
|
+
});
|
|
438
|
+
sized.set(section, size);
|
|
439
|
+
return size;
|
|
440
|
+
}
|
|
441
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
442
|
+
var NONE = {};
|
|
443
|
+
function expandSavedSections(source, answer) {
|
|
444
|
+
if (!source.sections.some((root) => root.type === "saved-section")) return { doc: source, roots: null };
|
|
445
|
+
let perAnswer = cache.get(source);
|
|
446
|
+
if (perAnswer === void 0) {
|
|
447
|
+
perAnswer = /* @__PURE__ */ new WeakMap();
|
|
448
|
+
cache.set(source, perAnswer);
|
|
449
|
+
}
|
|
450
|
+
const key = answer ?? NONE;
|
|
451
|
+
const known = perAnswer.get(key);
|
|
452
|
+
if (known !== void 0) return known;
|
|
453
|
+
const made = expand(source, answer);
|
|
454
|
+
perAnswer.set(key, made);
|
|
455
|
+
return made;
|
|
456
|
+
}
|
|
457
|
+
function expand(source, answer) {
|
|
458
|
+
const sections = [];
|
|
459
|
+
const roots = [];
|
|
460
|
+
const snapshots = {};
|
|
461
|
+
let nodes = 0;
|
|
462
|
+
(0, import_builder_schema5.walkNodes)({ sections: source.sections.filter((root) => root.type === "section") }, () => {
|
|
463
|
+
nodes += 1;
|
|
464
|
+
});
|
|
465
|
+
for (const root of source.sections) {
|
|
466
|
+
if (root.type === "section") {
|
|
467
|
+
sections.push(root);
|
|
468
|
+
roots.push({ kind: "section", id: root.id });
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const entry = answer !== void 0 && Object.hasOwn(answer, root.ref) ? answer[root.ref] : void 0;
|
|
472
|
+
const section = entry === void 0 ? null : sectionOf(entry);
|
|
473
|
+
if (entry !== void 0 && section !== null && nodes + sizeOf(section) > MAX_EXPANDED_NODES) {
|
|
474
|
+
warnOnce("saved-section-cap", `A page holds more than ${String(MAX_EXPANDED_NODES)} nodes with its saved sections; the rest are left out`);
|
|
475
|
+
roots.push({ kind: "ref", ref: root, sectionId: null });
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
if (entry === void 0 || section === null) {
|
|
479
|
+
roots.push({ kind: "ref", ref: root, sectionId: null });
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
nodes += sizeOf(section);
|
|
483
|
+
const prefixed = prefixSection(root.id, section);
|
|
484
|
+
const anchor = root.props.anchor;
|
|
485
|
+
const placed = anchor !== void 0 ? { ...prefixed, props: { ...prefixed.props, anchor } } : prefixed;
|
|
486
|
+
sections.push(placed);
|
|
487
|
+
roots.push({ kind: "ref", ref: root, sectionId: placed.id });
|
|
488
|
+
for (const [snapshotKey, snapshot] of Object.entries(entry.customWidgets ?? {})) {
|
|
489
|
+
if (import_builder_schema5.anyCustomWidgetSnapshotSchema.safeParse(snapshot).success) snapshots[snapshotKey] = snapshot;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const customWidgets = { ...snapshots, ...source.customWidgets };
|
|
493
|
+
return {
|
|
494
|
+
doc: { ...source, sections, ...Object.keys(customWidgets).length === 0 ? {} : { customWidgets } },
|
|
495
|
+
roots
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function MissingSavedSection({ node }) {
|
|
499
|
+
warnOnce(`saved-section:${node.ref}`, `Saved section ${node.ref} has no published section; rendering nothing for it`);
|
|
500
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(NodeWrapper, { id: node.id, part: "section", as: "section", className: "tb-section", missing: true });
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// src/shopper-data.ts
|
|
504
|
+
var import_react3 = require("react");
|
|
505
|
+
|
|
506
|
+
// src/data.ts
|
|
507
|
+
var import_builder_schema6 = require("@usethrottle/builder-schema");
|
|
508
|
+
function stable(value) {
|
|
509
|
+
if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
|
|
510
|
+
if (typeof value === "object" && value !== null) {
|
|
511
|
+
const entries2 = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
512
|
+
return `{${entries2.map(([k, v]) => `${JSON.stringify(k)}:${stable(v)}`).join(",")}}`;
|
|
513
|
+
}
|
|
514
|
+
return JSON.stringify(value) ?? "null";
|
|
515
|
+
}
|
|
516
|
+
function bindingKey(binding) {
|
|
517
|
+
return "params" in binding ? `${binding.source}?${stable(binding.params)}` : binding.source;
|
|
518
|
+
}
|
|
519
|
+
var isContextBinding = (binding) => binding.source.startsWith("context.");
|
|
520
|
+
function bindingsOf(node, registry) {
|
|
521
|
+
const def = registry.widget(node.type, node.v);
|
|
522
|
+
const out = {};
|
|
523
|
+
for (const [name, input] of Object.entries(def?.data ?? {})) {
|
|
524
|
+
if (input.default !== void 0) out[name] = input.default;
|
|
525
|
+
}
|
|
526
|
+
return { ...out, ...node.data ?? {} };
|
|
527
|
+
}
|
|
528
|
+
function collectBindings(doc, registry) {
|
|
529
|
+
const found = /* @__PURE__ */ new Map();
|
|
530
|
+
(0, import_builder_schema6.walkNodes)(doc, (node) => {
|
|
531
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column" || node.type === "saved-section") {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
535
|
+
const key = bindingKey(binding);
|
|
536
|
+
if (!found.has(key)) found.set(key, binding);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
return found;
|
|
540
|
+
}
|
|
541
|
+
async function resolveBindings(bindings, registry, ctx, options) {
|
|
542
|
+
const jobs = [];
|
|
543
|
+
for (const [key, binding] of bindings) {
|
|
544
|
+
if (isContextBinding(binding) || !("params" in binding)) continue;
|
|
545
|
+
const descriptor = registry.source(binding.source);
|
|
546
|
+
const resolve = registry.resolver(binding.source);
|
|
547
|
+
if (descriptor === void 0 || resolve === void 0) continue;
|
|
548
|
+
if (options.include === "static" && descriptor.perShopper) continue;
|
|
549
|
+
if (options.include === "shopper" && !descriptor.perShopper) continue;
|
|
550
|
+
jobs.push(
|
|
551
|
+
resolve(binding.params, ctx).then(
|
|
552
|
+
(value) => [key, value],
|
|
553
|
+
(error) => {
|
|
554
|
+
warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
)
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
const settled = await Promise.all(jobs);
|
|
561
|
+
return Object.fromEntries(settled.filter((entry) => entry !== null));
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// src/shopper-data.ts
|
|
565
|
+
function useResolvedData(document2, registry, locale, include, context) {
|
|
566
|
+
const [data, setData] = (0, import_react3.useState)({});
|
|
567
|
+
(0, import_react3.useEffect)(() => {
|
|
568
|
+
const controller = new AbortController();
|
|
569
|
+
const bindings = collectBindings(document2, registry);
|
|
570
|
+
if (bindings.size === 0) return void 0;
|
|
571
|
+
void resolveBindings(
|
|
572
|
+
bindings,
|
|
573
|
+
registry,
|
|
574
|
+
{ locale, preview: false, context, signal: controller.signal },
|
|
575
|
+
{ include }
|
|
576
|
+
).then((resolved) => {
|
|
577
|
+
if (!controller.signal.aborted && Object.keys(resolved).length > 0) setData(resolved);
|
|
578
|
+
});
|
|
579
|
+
return () => controller.abort();
|
|
580
|
+
}, [document2, registry, locale, include, context]);
|
|
581
|
+
return data;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/part-view.tsx
|
|
585
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
586
|
+
var BoundaryBase = import_react4.Component ?? class {
|
|
587
|
+
};
|
|
588
|
+
var Boundary = class extends BoundaryBase {
|
|
589
|
+
constructor() {
|
|
590
|
+
super(...arguments);
|
|
591
|
+
__publicField(this, "state", { failed: false });
|
|
592
|
+
}
|
|
593
|
+
static getDerivedStateFromError() {
|
|
594
|
+
return { failed: true };
|
|
595
|
+
}
|
|
596
|
+
componentDidCatch(error, _info) {
|
|
597
|
+
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
598
|
+
try {
|
|
599
|
+
this.props.onError?.(error, { part: this.props.label });
|
|
600
|
+
} catch {
|
|
601
|
+
}
|
|
87
602
|
}
|
|
88
|
-
|
|
89
|
-
|
|
603
|
+
componentDidUpdate(previous) {
|
|
604
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
605
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
606
|
+
}
|
|
607
|
+
render() {
|
|
608
|
+
return this.state.failed ? null : this.props.children;
|
|
90
609
|
}
|
|
91
610
|
};
|
|
92
|
-
|
|
611
|
+
function PartBoundary({
|
|
612
|
+
label,
|
|
613
|
+
resetKey,
|
|
614
|
+
children
|
|
615
|
+
}) {
|
|
616
|
+
const builder = useBuilder();
|
|
617
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
618
|
+
}
|
|
619
|
+
function contextData(context) {
|
|
620
|
+
if (typeof context !== "object" || context === null) return {};
|
|
621
|
+
return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
|
|
622
|
+
}
|
|
623
|
+
function PartView({ part, context }) {
|
|
624
|
+
const builder = useBuilder();
|
|
625
|
+
if (builder === null) return null;
|
|
626
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PartBody, { part, context, builder });
|
|
627
|
+
}
|
|
628
|
+
function PartBody({
|
|
629
|
+
part,
|
|
630
|
+
context,
|
|
631
|
+
builder
|
|
632
|
+
}) {
|
|
633
|
+
const expanded = expandSavedSections(part.document, part.savedSections).doc;
|
|
634
|
+
const shopper = useResolvedData(expanded, builder.registry, builder.locale, "shopper", context);
|
|
635
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
636
|
+
BuilderRenderer,
|
|
637
|
+
{
|
|
638
|
+
document: part.document,
|
|
639
|
+
registry: builder.registry,
|
|
640
|
+
data: { ...part.initialData, ...contextData(context), ...shopper },
|
|
641
|
+
locale: builder.locale,
|
|
642
|
+
assets: part.assets,
|
|
643
|
+
mediaOrigin: builder.mediaOrigin,
|
|
644
|
+
resolveLink: builder.resolveLink,
|
|
645
|
+
interactive: builder.interactive,
|
|
646
|
+
scopeCustomCss: builder.customCss !== "",
|
|
647
|
+
savedSections: part.savedSections,
|
|
648
|
+
code: codeRenderOf(builder, part.code)
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
}
|
|
93
652
|
|
|
94
|
-
// src/
|
|
95
|
-
var
|
|
653
|
+
// src/custom/template-widget.tsx
|
|
654
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
655
|
+
var componentWeights = /* @__PURE__ */ new WeakMap();
|
|
656
|
+
var compiled = /* @__PURE__ */ new WeakMap();
|
|
657
|
+
function compileTemplate(snapshot, registry) {
|
|
658
|
+
let perRegistry = compiled.get(snapshot);
|
|
659
|
+
if (perRegistry === void 0) {
|
|
660
|
+
perRegistry = /* @__PURE__ */ new WeakMap();
|
|
661
|
+
compiled.set(snapshot, perRegistry);
|
|
662
|
+
}
|
|
663
|
+
if (perRegistry.has(registry)) return perRegistry.get(registry) ?? null;
|
|
664
|
+
const result = compile(snapshot, registry);
|
|
665
|
+
perRegistry.set(registry, result);
|
|
666
|
+
return result;
|
|
667
|
+
}
|
|
668
|
+
function compile(snapshot, registry) {
|
|
669
|
+
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
670
|
+
const refuse = (why) => {
|
|
671
|
+
warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
672
|
+
return null;
|
|
673
|
+
};
|
|
674
|
+
if (snapshot.kind !== "template") return refuse("not a template widget");
|
|
675
|
+
const source = snapshot.template;
|
|
676
|
+
if (typeof source !== "string") return refuse("no template source");
|
|
677
|
+
const parsed2 = (0, import_builder_schema7.parseTemplate)(source);
|
|
678
|
+
if (!parsed2.ok) return refuse(`template does not parse: ${parsed2.issues[0]?.message ?? "invalid"}`);
|
|
679
|
+
const data = snapshot.data;
|
|
680
|
+
const issues = (0, import_builder_schema7.validateTemplate)(parsed2.ast, {
|
|
681
|
+
settings: snapshot.settings,
|
|
682
|
+
data: typeof data === "object" && data !== null ? data : {},
|
|
683
|
+
sources: registry.sources()
|
|
684
|
+
});
|
|
685
|
+
if (issues.length > 0) return refuse(`template does not validate: ${issues[0]?.message ?? "invalid"}`);
|
|
686
|
+
if (!fitsBudget(parsed2.ast)) return refuse(`it can render more than ${String(import_builder_schema7.MAX_TEMPLATE_WEIGHT)} nodes`);
|
|
687
|
+
const css = scopedCss(snapshot.css, snapshot.type);
|
|
688
|
+
if (css === null) return refuse("its css does not pass the sanitiser");
|
|
689
|
+
return { ast: parsed2.ast, css, weight: (0, import_builder_schema7.templateWeight)(parsed2.ast) };
|
|
690
|
+
}
|
|
691
|
+
function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
|
|
692
|
+
const template = compileTemplate(snapshot, registry);
|
|
693
|
+
if (template === null) return null;
|
|
694
|
+
const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
|
|
695
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
696
|
+
template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CustomCss, { css: template.css }),
|
|
697
|
+
renderTemplate(template.ast, env)
|
|
698
|
+
] });
|
|
699
|
+
}
|
|
700
|
+
function TemplateWidget(props) {
|
|
701
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react5.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TemplateBody, { ...props }) }) });
|
|
702
|
+
}
|
|
96
703
|
|
|
97
|
-
// src/
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
704
|
+
// src/code/leave.ts
|
|
705
|
+
var import_react6 = require("react");
|
|
706
|
+
|
|
707
|
+
// src/code/reload.ts
|
|
708
|
+
function reloadHere() {
|
|
709
|
+
window.location.assign(window.location.href);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// src/code/routes.ts
|
|
713
|
+
var CODE_ROUTE_DENY = /^(checkout|cart|basket|bag|account|my-?account|sign[-_]?in|sign[-_]?up|log[-_]?in|log[-_]?out|register|orders?|pay|payments?|password|wallet)([;.\s].*)?$|^(confirm|thank|receipt|invoice|quote).*$|^order[-_].*$/i;
|
|
714
|
+
var DEFAULT_CATALOG_ROUTES = [
|
|
715
|
+
"/p/{handle}",
|
|
716
|
+
"/c/{handle}",
|
|
717
|
+
"/collections/{handle}",
|
|
718
|
+
"/tags/{tag}",
|
|
719
|
+
"/search",
|
|
720
|
+
"/shop"
|
|
721
|
+
];
|
|
722
|
+
function normalizePath(pathname) {
|
|
723
|
+
const bare = pathname.split(/[?#]/, 1)[0] ?? "";
|
|
724
|
+
let decoded2 = bare;
|
|
725
|
+
try {
|
|
726
|
+
for (let i = 0; i < 3; i++) {
|
|
727
|
+
let next;
|
|
728
|
+
try {
|
|
729
|
+
next = decodeURIComponent(decoded2);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
if (i === 0) throw error;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
if (next === decoded2) break;
|
|
735
|
+
decoded2 = next;
|
|
736
|
+
}
|
|
737
|
+
} catch {
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
if (decoded2.includes("\0")) return null;
|
|
741
|
+
const flat = decoded2.replace(/\\/g, "/");
|
|
742
|
+
if (!flat.startsWith("/")) return null;
|
|
743
|
+
const out = [];
|
|
744
|
+
for (const segment of flat.split("/")) {
|
|
745
|
+
if (segment === "" || segment === ".") continue;
|
|
746
|
+
if (segment === "..") out.pop();
|
|
747
|
+
else out.push(segment);
|
|
748
|
+
}
|
|
749
|
+
return `/${out.join("/")}`;
|
|
750
|
+
}
|
|
751
|
+
var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
752
|
+
var compiled2 = /* @__PURE__ */ new Map();
|
|
753
|
+
var MAX_COMPILED = 64;
|
|
754
|
+
function matcherOf(template) {
|
|
755
|
+
const known = compiled2.get(template);
|
|
756
|
+
if (known !== void 0) return known;
|
|
757
|
+
let regex = null;
|
|
758
|
+
if (template.startsWith("/")) {
|
|
759
|
+
const pattern = template.split(/(\{[A-Za-z][A-Za-z0-9]*\})/).map((part) => /^\{[A-Za-z][A-Za-z0-9]*\}$/.test(part) ? "[^/]+" : escapeRegExp(part)).join("").replace(/\/+$/, "");
|
|
760
|
+
regex = new RegExp(`^${pattern === "" ? "/" : pattern}$`);
|
|
761
|
+
}
|
|
762
|
+
if (compiled2.size >= MAX_COMPILED) compiled2.clear();
|
|
763
|
+
compiled2.set(template, regex);
|
|
764
|
+
return regex;
|
|
765
|
+
}
|
|
766
|
+
var matchesTemplate = (path, template) => matcherOf(template)?.test(path) ?? false;
|
|
767
|
+
function isCodeRoute(pathname, routes) {
|
|
768
|
+
if (pathname === void 0) return false;
|
|
769
|
+
const path = normalizePath(pathname);
|
|
770
|
+
if (path === null) return false;
|
|
771
|
+
if (path.split("/").some((segment) => CODE_ROUTE_DENY.test(segment))) return false;
|
|
772
|
+
if (path === "/") return true;
|
|
773
|
+
return [routes.page, ...routes.catalog ?? DEFAULT_CATALOG_ROUTES].some(
|
|
774
|
+
(template) => matchesTemplate(path, template)
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/code/leave.ts
|
|
779
|
+
var emitted = false;
|
|
780
|
+
function markCodeEmitted() {
|
|
781
|
+
emitted = true;
|
|
782
|
+
}
|
|
783
|
+
function mustLeave(pathname, routes) {
|
|
784
|
+
return emitted && typeof window !== "undefined" && pathname !== void 0 && !isCodeRoute(pathname, routes);
|
|
785
|
+
}
|
|
786
|
+
function useLeaveCodeRoutes(pathname, routes) {
|
|
787
|
+
(0, import_react6.useEffect)(() => {
|
|
788
|
+
if (mustLeave(pathname, routes)) reloadHere();
|
|
789
|
+
}, [pathname, routes]);
|
|
790
|
+
const latest = (0, import_react6.useRef)(routes);
|
|
791
|
+
latest.current = routes;
|
|
792
|
+
(0, import_react6.useEffect)(
|
|
793
|
+
() => () => {
|
|
794
|
+
if (mustLeave(window.location.pathname, latest.current)) reloadHere();
|
|
795
|
+
},
|
|
796
|
+
[]
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// src/code/code-widget.tsx
|
|
801
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
802
|
+
var SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
803
|
+
var CUSTOM_TYPE = /^custom\.[a-z][a-z0-9-]{0,63}$/;
|
|
804
|
+
var SCRIPT_ORIGIN = /^https:\/\/[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]{1,5})?$/i;
|
|
805
|
+
var SITE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
806
|
+
var MAX_INPUT_CHARS = 2e5;
|
|
807
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
808
|
+
var checked = /* @__PURE__ */ new WeakMap();
|
|
809
|
+
function check(raw, registry) {
|
|
810
|
+
let perRegistry = checked.get(raw);
|
|
811
|
+
if (perRegistry === void 0) {
|
|
812
|
+
perRegistry = /* @__PURE__ */ new WeakMap();
|
|
813
|
+
checked.set(raw, perRegistry);
|
|
814
|
+
}
|
|
815
|
+
const known = perRegistry.get(registry);
|
|
816
|
+
if (known !== void 0) return known;
|
|
817
|
+
const result = verify(raw, registry);
|
|
818
|
+
perRegistry.set(registry, result);
|
|
819
|
+
return result;
|
|
820
|
+
}
|
|
821
|
+
function verify(raw, registry) {
|
|
822
|
+
const snapshot = raw;
|
|
823
|
+
const label = `${String(snapshot.type)}@${String(snapshot.v)}`;
|
|
824
|
+
if (snapshot.disabled === true) return { status: "disabled" };
|
|
825
|
+
const refuse = (why) => {
|
|
826
|
+
warnOnce(`code:${label}`, `Code widget ${label} was refused (${why}); rendering nothing for it`);
|
|
827
|
+
return { status: "invalid" };
|
|
828
|
+
};
|
|
829
|
+
if (snapshot.kind !== "code") return refuse("not a code widget");
|
|
830
|
+
if (typeof snapshot.type !== "string" || !CUSTOM_TYPE.test(snapshot.type)) return refuse("bad type");
|
|
831
|
+
if (snapshot.disabled !== void 0) return refuse("bad disabled flag");
|
|
832
|
+
if ("js" in snapshot) return refuse("it carries a script");
|
|
833
|
+
if (typeof snapshot.jsHash !== "string" || !SHA256_HEX.test(snapshot.jsHash)) return refuse("bad script hash");
|
|
834
|
+
if (typeof snapshot.html !== "string" || snapshot.html.length > import_builder_schema8.LIMITS.codeHtmlBytes) return refuse("bad html");
|
|
835
|
+
if (typeof snapshot.css !== "string" || snapshot.css.length > import_builder_schema8.LIMITS.codeCssBytes) return refuse("bad css");
|
|
836
|
+
const template = { ...snapshot, kind: "template", template: snapshot.html };
|
|
837
|
+
if (compileTemplate(template, registry) === null) return refuse("its markup or css does not validate");
|
|
838
|
+
return { status: "ok", snapshot: raw, template };
|
|
839
|
+
}
|
|
840
|
+
function codeScriptUrl(runtime, jsHash) {
|
|
841
|
+
if (!isRecord(runtime) || runtime.enabled !== true) return null;
|
|
842
|
+
const { scriptOrigin, codeSiteId } = runtime;
|
|
843
|
+
if (typeof scriptOrigin !== "string" || !SCRIPT_ORIGIN.test(scriptOrigin)) return null;
|
|
844
|
+
if (typeof codeSiteId !== "string" || !SITE_ID.test(codeSiteId)) return null;
|
|
845
|
+
if (!SHA256_HEX.test(jsHash)) return null;
|
|
846
|
+
return `${scriptOrigin}/v1/code/${codeSiteId}/${jsHash}.js`;
|
|
847
|
+
}
|
|
848
|
+
function jsonForScript(value) {
|
|
849
|
+
return JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
850
|
+
}
|
|
851
|
+
var BADGE = {
|
|
852
|
+
display: "inline-block",
|
|
853
|
+
margin: 4,
|
|
854
|
+
padding: "2px 8px",
|
|
855
|
+
borderRadius: 4,
|
|
856
|
+
font: "600 11px/1.5 system-ui, sans-serif",
|
|
857
|
+
letterSpacing: "0.02em",
|
|
858
|
+
background: "#1f2937",
|
|
859
|
+
color: "#fff"
|
|
860
|
+
};
|
|
861
|
+
function runs(props, jsHash) {
|
|
862
|
+
const { code, edit, interactive } = props;
|
|
863
|
+
if (edit !== void 0 || interactive === false || code === void 0 || code.preview === true) return null;
|
|
864
|
+
if (!isCodeRoute(code.pathname, code.routes)) return null;
|
|
865
|
+
return codeScriptUrl(code.runtime, jsHash);
|
|
866
|
+
}
|
|
867
|
+
function CodeWidget(props) {
|
|
868
|
+
const { node, snapshot, registry, edit, anchor, copyAnchor, entrance } = props;
|
|
869
|
+
const result = check(snapshot, registry);
|
|
870
|
+
if (result.status !== "ok") {
|
|
871
|
+
return result.status === "disabled" && edit !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", edit, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "tb-missing", children: "This code widget is disabled" }) }) : null;
|
|
872
|
+
}
|
|
873
|
+
const template = compileTemplate(result.template, registry);
|
|
874
|
+
const src = runs(props, result.snapshot.jsHash);
|
|
875
|
+
if (src !== null) markCodeEmitted();
|
|
876
|
+
const env = newEnv({ settings: props.props, data: props.data, locale: props.locale, mediaOrigin: props.mediaOrigin, budget: new RenderBudget() });
|
|
877
|
+
const label = `${node.type}@${String(node.v)}`;
|
|
878
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
879
|
+
NodeWrapper,
|
|
880
|
+
{
|
|
881
|
+
id: node.id,
|
|
882
|
+
part: "widget",
|
|
883
|
+
type: node.type,
|
|
884
|
+
custom: true,
|
|
885
|
+
edit,
|
|
886
|
+
className: "tb-w",
|
|
887
|
+
anchor,
|
|
888
|
+
copyAnchor,
|
|
889
|
+
entrance,
|
|
890
|
+
attributes: src === null ? { "data-b-code-inert": "" } : { "data-b-code": result.snapshot.jsHash },
|
|
891
|
+
children: [
|
|
892
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PartBoundary, { label, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react7.Suspense, { fallback: null, children: [
|
|
893
|
+
template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CustomCss, { css: template.css }),
|
|
894
|
+
renderTemplate(template.ast, env)
|
|
895
|
+
] }) }),
|
|
896
|
+
src === null && (edit !== void 0 || props.code?.preview === true) ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { "data-b-code-badge": "", style: BADGE, children: "Runs on your store" }) : null,
|
|
897
|
+
src === null ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CodeInput, { props: props.props, data: props.data, label }),
|
|
898
|
+
src === null ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("script", { async: true, src })
|
|
899
|
+
]
|
|
900
|
+
}
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
function CodeInput({ props, data, label }) {
|
|
904
|
+
let json = "";
|
|
905
|
+
try {
|
|
906
|
+
json = jsonForScript({ props, data });
|
|
907
|
+
if (json.length > MAX_INPUT_CHARS) {
|
|
908
|
+
warnOnce(`code-input:${label}`, `The data of ${label} is too large for its code input; it gets its props only`);
|
|
909
|
+
json = jsonForScript({ props, data: {} });
|
|
910
|
+
}
|
|
911
|
+
} catch {
|
|
912
|
+
warnOnce(`code-input:${label}`, `The input of ${label} cannot be written as JSON; it gets none`);
|
|
913
|
+
json = jsonForScript({ props: {}, data: {} });
|
|
914
|
+
}
|
|
915
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("script", { type: "application/json", "data-b-code-input": "", children: json });
|
|
103
916
|
}
|
|
104
|
-
var isDevelopment = () => typeof process === "undefined" || process.env?.NODE_ENV !== "production";
|
|
105
917
|
|
|
106
918
|
// src/css-compiler.ts
|
|
919
|
+
var import_builder_schema9 = require("@usethrottle/builder-schema");
|
|
107
920
|
var TABLET_QUERY = "(max-width:1024px)";
|
|
108
921
|
var PHONE_QUERY = "(max-width:767px)";
|
|
109
922
|
var SAFE_VALUE = /^[A-Za-z0-9#%.,()\-+*/_: ]{1,200}$/;
|
|
110
923
|
var URL_QUOTE_SAFE = /^[^\s"'\\()<>{};]+$/;
|
|
111
|
-
var ID_RE = /^[a-z0-9]{8,24}
|
|
924
|
+
var ID_RE = /^[a-z0-9]{8,24}(-[a-z0-9]{8,24})?$/;
|
|
112
925
|
var PROPERTY_RE = /^--(?:b|w|tb)-[A-Za-z][A-Za-z0-9-]{0,39}$/;
|
|
113
926
|
var COLOR_TOKEN = /* @__PURE__ */ new Set([
|
|
114
927
|
"primary",
|
|
@@ -176,7 +989,7 @@ function put(out, property, value) {
|
|
|
176
989
|
}
|
|
177
990
|
out.set(property, value);
|
|
178
991
|
}
|
|
179
|
-
var COMMON_BY_KEY = new Map(
|
|
992
|
+
var COMMON_BY_KEY = new Map(import_builder_schema9.COMMON_WIDGET_SETTINGS.map((field) => [field.key, field]));
|
|
180
993
|
function widgetDecls(node, device, registry) {
|
|
181
994
|
const out = /* @__PURE__ */ new Map();
|
|
182
995
|
const def = registry.widget(node.type, node.v);
|
|
@@ -184,12 +997,12 @@ function widgetDecls(node, device, registry) {
|
|
|
184
997
|
const fields = new Map([...COMMON_BY_KEY, ...def.settings.map((f) => [f.key, f])]);
|
|
185
998
|
const defaults = {};
|
|
186
999
|
for (const field of fields.values()) if (field.output === "css") defaults[field.key] = field.default;
|
|
187
|
-
const resolved = (0,
|
|
1000
|
+
const resolved = (0, import_builder_schema9.resolveResponsive)({ ...defaults, ...node.props }, node.responsive, device);
|
|
188
1001
|
const prefix = node.type.startsWith("custom.") ? "--w-" : "--b-";
|
|
189
1002
|
for (const field of fields.values()) {
|
|
190
1003
|
if (field.output !== "css") continue;
|
|
191
1004
|
const raw = resolved[field.key];
|
|
192
|
-
const value = raw === void 0 || (0,
|
|
1005
|
+
const value = raw === void 0 || (0, import_builder_schema9.validateSettingValue)(field, raw) === null ? raw : field.default;
|
|
193
1006
|
if (value === null || value === void 0) continue;
|
|
194
1007
|
if (field.key === "hidden") {
|
|
195
1008
|
if (value === true) put(out, "--tb-hide", "none");
|
|
@@ -209,13 +1022,13 @@ function backgroundDecls(out, bg, assets, mediaOrigin) {
|
|
|
209
1022
|
if (bg.position !== void 0 && BG_POSITION.has(bg.position)) put(out, "--tb-bgpos", bg.position);
|
|
210
1023
|
if (bg.size !== void 0 && BG_SIZE.has(bg.size)) put(out, "--tb-bgsize", bg.size);
|
|
211
1024
|
const asset = bg.image === void 0 || assets === void 0 || !Object.hasOwn(assets, bg.image) ? void 0 : assets[bg.image];
|
|
212
|
-
if (asset !== void 0 && (0,
|
|
1025
|
+
if (asset !== void 0 && (0, import_builder_schema9.safeUrl)(asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
|
|
213
1026
|
out.set("--tb-bgimg", `url("${asset.url}")`);
|
|
214
1027
|
}
|
|
215
1028
|
}
|
|
216
1029
|
function sectionDecls(section, device, assets, mediaOrigin) {
|
|
217
1030
|
const out = /* @__PURE__ */ new Map();
|
|
218
|
-
const p = (0,
|
|
1031
|
+
const p = (0, import_builder_schema9.resolveResponsive)(section.props, section.responsive, device);
|
|
219
1032
|
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
220
1033
|
const full = p.width === "full";
|
|
221
1034
|
put(out, "--tb-maxw", full ? "none" : px(typeof p.contentWidth === "number" ? p.contentWidth : 1200));
|
|
@@ -225,16 +1038,16 @@ function sectionDecls(section, device, assets, mediaOrigin) {
|
|
|
225
1038
|
if (typeof p.minHeight === "number" && p.minHeight > 0 && p.minHeight <= 2e3) put(out, "--tb-minh", px(p.minHeight));
|
|
226
1039
|
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-valign", ALIGN_ITEMS[p.verticalAlign]);
|
|
227
1040
|
backgroundDecls(out, p.background, assets, mediaOrigin);
|
|
228
|
-
const widths = (0,
|
|
229
|
-
const rows = (0,
|
|
1041
|
+
const widths = (0, import_builder_schema9.resolveColumnWidths)(section, device);
|
|
1042
|
+
const rows = (0, import_builder_schema9.wrapColumnRows)(widths);
|
|
230
1043
|
const stacked = rows.every((row) => row.length === 1);
|
|
231
1044
|
put(out, "--tb-flow", stacked && p.stackOrder === "reverse" ? "column-reverse nowrap" : "row wrap");
|
|
232
1045
|
return out;
|
|
233
1046
|
}
|
|
234
1047
|
function columnWidthDecls(section, device) {
|
|
235
|
-
const widths = (0,
|
|
1048
|
+
const widths = (0, import_builder_schema9.resolveColumnWidths)(section, device);
|
|
236
1049
|
const result = section.columns.map(() => /* @__PURE__ */ new Map());
|
|
237
|
-
for (const row of (0,
|
|
1050
|
+
for (const row of (0, import_builder_schema9.wrapColumnRows)(widths)) {
|
|
238
1051
|
for (const index of row) {
|
|
239
1052
|
put(result[index], "--tb-cw", String(Math.round(widths[index] / 100 * 1e4) / 1e4));
|
|
240
1053
|
put(result[index], "--tb-cn", String(row.length - 1));
|
|
@@ -245,7 +1058,7 @@ function columnWidthDecls(section, device) {
|
|
|
245
1058
|
function columnDecls(section, index, device, assets, mediaOrigin, widths) {
|
|
246
1059
|
const column = section.columns[index];
|
|
247
1060
|
const out = new Map(widths);
|
|
248
|
-
const p = (0,
|
|
1061
|
+
const p = (0, import_builder_schema9.resolveColumnProps)(column.props, column.responsive, device);
|
|
249
1062
|
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
250
1063
|
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-self", ALIGN_ITEMS[p.verticalAlign]);
|
|
251
1064
|
put(out, "--tb-pad", p.padding === void 0 ? null : spacing(p.padding));
|
|
@@ -316,110 +1129,354 @@ function compileResponsiveCss(doc, registry, assets = doc.assets, mediaOrigin =
|
|
|
316
1129
|
return base + (tablet === "" ? "" : `@media ${TABLET_QUERY}{${tablet}}`) + (phone === "" ? "" : `@media ${PHONE_QUERY}{${phone}}`);
|
|
317
1130
|
}
|
|
318
1131
|
|
|
319
|
-
// src/
|
|
320
|
-
var
|
|
321
|
-
function
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
1132
|
+
// src/interactions/accordion.tsx
|
|
1133
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1134
|
+
function Accordion({
|
|
1135
|
+
id,
|
|
1136
|
+
panels,
|
|
1137
|
+
multiple,
|
|
1138
|
+
openFirst
|
|
1139
|
+
}) {
|
|
1140
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "tb-accordion", children: panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1141
|
+
"details",
|
|
1142
|
+
{
|
|
1143
|
+
className: "tb-acc-item",
|
|
1144
|
+
...multiple ? {} : { name: `${id}-acc` },
|
|
1145
|
+
...openFirst && i === 0 ? { open: true } : {},
|
|
1146
|
+
children: [
|
|
1147
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("summary", { className: "tb-acc-sum", children: panel.title }),
|
|
1148
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "tb-acc-body", children: panel.node })
|
|
1149
|
+
]
|
|
1150
|
+
},
|
|
1151
|
+
panel.key
|
|
1152
|
+
)) });
|
|
340
1153
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
1154
|
+
|
|
1155
|
+
// src/interactions/carousel.tsx
|
|
1156
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1157
|
+
function Carousel({
|
|
1158
|
+
panels,
|
|
1159
|
+
autoplayMs,
|
|
1160
|
+
loop
|
|
1161
|
+
}) {
|
|
1162
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
1163
|
+
"div",
|
|
1164
|
+
{
|
|
1165
|
+
className: "tb-car",
|
|
1166
|
+
role: "region",
|
|
1167
|
+
"aria-roledescription": "carousel",
|
|
1168
|
+
"aria-label": "Carousel",
|
|
1169
|
+
"data-b-car": "",
|
|
1170
|
+
...loop ? { "data-b-loop": "" } : {},
|
|
1171
|
+
...autoplayMs === null ? {} : { "data-b-autoplay": String(autoplayMs) },
|
|
1172
|
+
children: [
|
|
1173
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "tb-car-track", tabIndex: 0, children: panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1174
|
+
"div",
|
|
1175
|
+
{
|
|
1176
|
+
className: "tb-slide",
|
|
1177
|
+
role: "group",
|
|
1178
|
+
"aria-roledescription": "slide",
|
|
1179
|
+
"aria-label": panel.title === "" ? `${String(i + 1)} of ${String(panels.length)}` : panel.title,
|
|
1180
|
+
children: panel.node
|
|
1181
|
+
},
|
|
1182
|
+
panel.key
|
|
1183
|
+
)) }),
|
|
1184
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "tb-car-ctrl", children: [
|
|
1185
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "tb-car-btn", "data-b-act": "prev", "aria-label": "Previous slide", children: "\u2039" }),
|
|
1186
|
+
autoplayMs === null ? null : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "tb-car-btn tb-car-pause", "data-b-act": "pause", hidden: true, children: "Pause" }),
|
|
1187
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "tb-car-btn", "data-b-act": "next", "aria-label": "Next slide", children: "\u203A" })
|
|
1188
|
+
] })
|
|
1189
|
+
]
|
|
350
1190
|
}
|
|
351
|
-
|
|
352
|
-
return found;
|
|
353
|
-
}
|
|
354
|
-
async function resolveBindings(bindings, registry, ctx, options) {
|
|
355
|
-
const jobs = [];
|
|
356
|
-
for (const [key, binding] of bindings) {
|
|
357
|
-
if (isContextBinding(binding) || !("params" in binding)) continue;
|
|
358
|
-
const descriptor = registry.source(binding.source);
|
|
359
|
-
const resolve = registry.resolver(binding.source);
|
|
360
|
-
if (descriptor === void 0 || resolve === void 0) continue;
|
|
361
|
-
if (options.include === "static" && descriptor.perShopper) continue;
|
|
362
|
-
if (options.include === "shopper" && !descriptor.perShopper) continue;
|
|
363
|
-
jobs.push(
|
|
364
|
-
resolve(binding.params, ctx).then(
|
|
365
|
-
(value) => [key, value],
|
|
366
|
-
(error) => {
|
|
367
|
-
warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
)
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
const settled = await Promise.all(jobs);
|
|
374
|
-
return Object.fromEntries(settled.filter((entry) => entry !== null));
|
|
1191
|
+
);
|
|
375
1192
|
}
|
|
376
1193
|
|
|
377
|
-
// src/
|
|
378
|
-
var
|
|
379
|
-
var
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
1194
|
+
// src/interactions/entrance.tsx
|
|
1195
|
+
var import_react8 = require("react");
|
|
1196
|
+
var import_builder_schema10 = require("@usethrottle/builder-schema");
|
|
1197
|
+
|
|
1198
|
+
// src/interactions/styles.ts
|
|
1199
|
+
var INTERACTIONS_CSS = `@layer throttle{
|
|
1200
|
+
.tb-panel>.tb-col,.tb-acc-body>.tb-col,.tb-slide>.tb-col{inline-size:100%}
|
|
1201
|
+
.tb-tablist{display:none;flex-wrap:wrap;gap:var(--tb-space-xs);border-block-end:1px solid var(--tb-color-border,currentColor);margin-block-end:var(--tb-space-m)}
|
|
1202
|
+
html[data-b-js] .tb-tablist{display:flex}
|
|
1203
|
+
html[data-b-js] .tb-panel-title{display:none}
|
|
1204
|
+
.tb-panel-title{margin:0 0 var(--tb-space-s);font-weight:600}
|
|
1205
|
+
.tb-panel[hidden]{display:none}
|
|
1206
|
+
.tb-tab{appearance:none;cursor:pointer;font:inherit;color:inherit;background:none;border:0;border-block-end:2px solid transparent;padding:var(--tb-space-s) var(--tb-space-m)}
|
|
1207
|
+
.tb-tab[aria-selected=true]{border-block-end-color:var(--tb-color-primary,currentColor);font-weight:600}
|
|
1208
|
+
.tb-tab:focus-visible,.tb-car-btn:focus-visible,.tb-acc-sum:focus-visible,.tb-toggle-sum:focus-visible,.tb-car-track:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
|
|
1209
|
+
.tb-acc-item{border-block-end:1px solid var(--tb-color-border,currentColor)}
|
|
1210
|
+
.tb-acc-sum,.tb-toggle-sum{cursor:pointer;padding:var(--tb-space-s) 0;font-weight:600}
|
|
1211
|
+
.tb-acc-body{padding-block-end:var(--tb-space-m)}
|
|
1212
|
+
.tb-toggle-open,.tb-toggle[open] .tb-toggle-closed{display:none}
|
|
1213
|
+
.tb-toggle[open] .tb-toggle-open{display:inline}
|
|
1214
|
+
.tb-toggle .tb-row{margin-block-start:var(--tb-space-m)}
|
|
1215
|
+
.tb-car{position:relative}
|
|
1216
|
+
.tb-car-track{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;scrollbar-width:thin}
|
|
1217
|
+
.tb-slide{flex:0 0 100%;min-inline-size:0;scroll-snap-align:start}
|
|
1218
|
+
.tb-car-ctrl{display:none;justify-content:center;gap:var(--tb-space-s);margin-block-start:var(--tb-space-s)}
|
|
1219
|
+
html[data-b-js] .tb-car-ctrl{display:flex}
|
|
1220
|
+
.tb-car-btn{appearance:none;cursor:pointer;font:inherit;color:inherit;background:var(--tb-color-surface,transparent);border:1px solid var(--tb-color-border-control,currentColor);border-radius:999px;min-inline-size:2.5rem;min-block-size:2.5rem;padding:0 var(--tb-space-m)}
|
|
1221
|
+
.tb-car-btn[hidden]{display:none}
|
|
1222
|
+
@media (prefers-reduced-motion:no-preference){
|
|
1223
|
+
html[data-b-js] [data-b-entrance]{transition:opacity .6s ease var(--tb-ed,0ms),transform .6s ease var(--tb-ed,0ms)}
|
|
1224
|
+
html[data-b-js] [data-b-entrance]:not([data-b-in]){opacity:0}
|
|
1225
|
+
html[data-b-js] [data-b-entrance=slide-up]:not([data-b-in]){transform:translateY(1.5rem)}
|
|
1226
|
+
html[data-b-js] [data-b-entrance=slide-left]:not([data-b-in]){transform:translateX(-1.5rem)}
|
|
1227
|
+
html[data-b-js] [data-b-entrance=zoom]:not([data-b-in]){transform:scale(.94)}
|
|
1228
|
+
}
|
|
1229
|
+
@media (prefers-reduced-motion:reduce){.tb-car-track{scroll-behavior:auto}}
|
|
1230
|
+
}`;
|
|
1231
|
+
|
|
1232
|
+
// src/interactions/runtime.ts
|
|
1233
|
+
var UNITS = [86400, 3600, 60, 1];
|
|
1234
|
+
var KEYS = ["d", "h", "m", "s"];
|
|
1235
|
+
var NAMES = ["days", "hours", "minutes", "seconds"];
|
|
1236
|
+
var holds = 0;
|
|
1237
|
+
var stop;
|
|
1238
|
+
var seen2 = /* @__PURE__ */ new WeakSet();
|
|
1239
|
+
var autoplay = /* @__PURE__ */ new Map();
|
|
1240
|
+
var all = (selector) => Array.from(document.querySelectorAll(selector));
|
|
1241
|
+
var reduced = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
1242
|
+
function selectTab(list, index, focus = false) {
|
|
1243
|
+
const tabs = Array.from(list.querySelectorAll("[role=tab]"));
|
|
1244
|
+
tabs.forEach((tab, i) => {
|
|
1245
|
+
const on = i === index;
|
|
1246
|
+
tab.setAttribute("aria-selected", String(on));
|
|
1247
|
+
tab.tabIndex = on ? 0 : -1;
|
|
1248
|
+
const panel = document.getElementById(tab.getAttribute("aria-controls") ?? "");
|
|
1249
|
+
if (panel !== null) panel.hidden = !on;
|
|
1250
|
+
if (on && focus) tab.focus();
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
function slideTo(root, step2) {
|
|
1254
|
+
const track = root.querySelector(".tb-car-track");
|
|
1255
|
+
if (track === null || track.clientWidth === 0) return;
|
|
1256
|
+
const count = track.children.length;
|
|
1257
|
+
const at = Math.round(track.scrollLeft / track.clientWidth) + step2;
|
|
1258
|
+
const loop = root.hasAttribute("data-b-loop");
|
|
1259
|
+
const to = at >= count ? loop ? 0 : count - 1 : at < 0 ? loop ? count - 1 : 0 : at;
|
|
1260
|
+
track.scrollTo?.({ left: to * track.clientWidth, behavior: reduced() ? "auto" : "smooth" });
|
|
1261
|
+
}
|
|
1262
|
+
var carousels = /* @__PURE__ */ new WeakMap();
|
|
1263
|
+
function setupCarousel(root) {
|
|
1264
|
+
const every = Number(root.getAttribute("data-b-autoplay"));
|
|
1265
|
+
const pause = root.querySelector("[data-b-act=pause]");
|
|
1266
|
+
if (!(every > 0) || reduced() || pause === null) return;
|
|
1267
|
+
pause.hidden = false;
|
|
1268
|
+
let state = carousels.get(root);
|
|
1269
|
+
if (state === void 0) {
|
|
1270
|
+
const own = state = { hold: 0 };
|
|
1271
|
+
carousels.set(root, own);
|
|
1272
|
+
const set = (bit, on) => void (own.hold = on ? own.hold | bit : own.hold & ~bit);
|
|
1273
|
+
root.addEventListener("mouseenter", () => set(1, true));
|
|
1274
|
+
root.addEventListener("mouseleave", () => set(1, false));
|
|
1275
|
+
root.addEventListener("focusin", () => set(2, true));
|
|
1276
|
+
root.addEventListener("focusout", () => set(2, false));
|
|
1277
|
+
pause.addEventListener("click", () => {
|
|
1278
|
+
set(4, (own.hold & 4) === 0);
|
|
1279
|
+
pause.textContent = own.hold & 4 ? "Play" : "Pause";
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
const shared = state;
|
|
1283
|
+
autoplay.set(root, window.setInterval(() => shared.hold === 0 && slideTo(root, 1), every));
|
|
1284
|
+
}
|
|
1285
|
+
function remaining(el) {
|
|
1286
|
+
return Math.max(0, Math.floor((Number(el.getAttribute("data-b-cd")) - Date.now()) / 1e3));
|
|
1287
|
+
}
|
|
1288
|
+
function tick(el, minute) {
|
|
1289
|
+
let left = remaining(el);
|
|
1290
|
+
const parts = [];
|
|
1291
|
+
KEYS.forEach((key, i) => {
|
|
1292
|
+
const out = el.querySelector(`[data-u=${key}]`);
|
|
1293
|
+
if (out === null) return;
|
|
1294
|
+
const value = Math.floor(left / UNITS[i]);
|
|
1295
|
+
left -= value * UNITS[i];
|
|
1296
|
+
out.textContent = String(value).padStart(2, "0");
|
|
1297
|
+
parts.push(`${String(value)} ${out.nextElementSibling?.textContent || NAMES[i]}`);
|
|
1298
|
+
});
|
|
1299
|
+
const live = el.querySelector("[data-b-live]");
|
|
1300
|
+
if (live !== null && minute) live.textContent = parts.join(", ");
|
|
1301
|
+
if (remaining(el) === 0) {
|
|
1302
|
+
el.setAttribute("data-b-ended", "");
|
|
1303
|
+
const text = el.querySelector(".tb-b-cd-ended");
|
|
1304
|
+
if (text !== null) text.hidden = false;
|
|
1305
|
+
if (el.getAttribute("data-b-expired") === "hide") el.hidden = true;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
function scan() {
|
|
1309
|
+
autoplay.forEach((id, root) => {
|
|
1310
|
+
if (!root.isConnected) {
|
|
1311
|
+
window.clearInterval(id);
|
|
1312
|
+
autoplay.delete(root);
|
|
421
1313
|
}
|
|
422
|
-
);
|
|
1314
|
+
});
|
|
1315
|
+
document.documentElement.setAttribute("data-b-js", "");
|
|
1316
|
+
const fresh = (selector) => all(selector).filter((el) => !seen2.has(el) && seen2.add(el));
|
|
1317
|
+
fresh("[data-b-tabs]").forEach((list) => selectTab(list, 0));
|
|
1318
|
+
fresh("[data-b-car]").forEach((root) => setupCarousel(root));
|
|
1319
|
+
const counts = fresh("[data-b-cd]");
|
|
1320
|
+
counts.forEach((el) => tick(el, true));
|
|
1321
|
+
const targets = fresh("[data-b-entrance]");
|
|
1322
|
+
if (targets.length === 0) return;
|
|
1323
|
+
if (typeof IntersectionObserver === "undefined") targets.forEach((el) => el.setAttribute("data-b-in", ""));
|
|
1324
|
+
else {
|
|
1325
|
+
const watch = new IntersectionObserver(
|
|
1326
|
+
(entries2) => entries2.forEach((entry) => {
|
|
1327
|
+
if (!entry.isIntersecting) return;
|
|
1328
|
+
entry.target.setAttribute("data-b-in", "");
|
|
1329
|
+
watch.unobserve(entry.target);
|
|
1330
|
+
})
|
|
1331
|
+
);
|
|
1332
|
+
targets.forEach((el) => watch.observe(el));
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
var shown = (el) => el !== null && el.getClientRects().length > 0;
|
|
1336
|
+
function goAnchor(name) {
|
|
1337
|
+
if (name === "" || shown(document.getElementById(name))) return false;
|
|
1338
|
+
const copy = all("[data-b-anchor]").find((el) => el.getAttribute("data-b-anchor") === name && shown(el));
|
|
1339
|
+
copy?.scrollIntoView();
|
|
1340
|
+
return copy !== void 0;
|
|
1341
|
+
}
|
|
1342
|
+
var decoded = (hash) => {
|
|
1343
|
+
try {
|
|
1344
|
+
return decodeURIComponent(hash.slice(1));
|
|
1345
|
+
} catch {
|
|
1346
|
+
return "";
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
var onHash = () => void goAnchor(decoded(location.hash));
|
|
1350
|
+
function onClick(event) {
|
|
1351
|
+
const target = event.target;
|
|
1352
|
+
const href = target?.closest('a[href^="#"]')?.getAttribute("href");
|
|
1353
|
+
if (href && !event.defaultPrevented && !event.button && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) && goAnchor(decoded(href))) {
|
|
1354
|
+
event.preventDefault();
|
|
1355
|
+
history.pushState(null, "", href);
|
|
1356
|
+
}
|
|
1357
|
+
const tab = target?.closest("[role=tab]");
|
|
1358
|
+
const list = tab?.closest("[data-b-tabs]");
|
|
1359
|
+
if (tab && list) return selectTab(list, Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab));
|
|
1360
|
+
const button = target?.closest("[data-b-act]");
|
|
1361
|
+
const act = button?.getAttribute("data-b-act");
|
|
1362
|
+
const root = button?.closest("[data-b-car]");
|
|
1363
|
+
if (root && (act === "prev" || act === "next")) slideTo(root, act === "next" ? 1 : -1);
|
|
1364
|
+
}
|
|
1365
|
+
function onKey(event) {
|
|
1366
|
+
const tab = event.target?.closest("[role=tab]");
|
|
1367
|
+
const list = tab?.closest("[data-b-tabs]");
|
|
1368
|
+
if (!tab || !list) return;
|
|
1369
|
+
const count = list.querySelectorAll("[role=tab]").length;
|
|
1370
|
+
const at = Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab);
|
|
1371
|
+
const to = event.key === "ArrowRight" ? (at + 1) % count : event.key === "ArrowLeft" ? (at + count - 1) % count : event.key === "Home" ? 0 : event.key === "End" ? count - 1 : -1;
|
|
1372
|
+
if (to < 0) return;
|
|
1373
|
+
event.preventDefault();
|
|
1374
|
+
selectTab(list, to, true);
|
|
1375
|
+
}
|
|
1376
|
+
function startRuntime() {
|
|
1377
|
+
if (typeof document === "undefined") return () => void 0;
|
|
1378
|
+
const first = holds++ === 0;
|
|
1379
|
+
if (first) {
|
|
1380
|
+
document.addEventListener("click", onClick);
|
|
1381
|
+
document.addEventListener("keydown", onKey);
|
|
1382
|
+
window.addEventListener("hashchange", onHash);
|
|
1383
|
+
let beat = 0;
|
|
1384
|
+
const clock = window.setInterval(() => {
|
|
1385
|
+
const minute = ++beat % 60 === 0;
|
|
1386
|
+
all("[data-b-cd]:not([data-b-ended])").forEach((el) => tick(el, minute));
|
|
1387
|
+
}, 1e3);
|
|
1388
|
+
let queued = false;
|
|
1389
|
+
const watcher = new MutationObserver(() => {
|
|
1390
|
+
if (queued) return;
|
|
1391
|
+
queued = true;
|
|
1392
|
+
void Promise.resolve().then(() => {
|
|
1393
|
+
queued = false;
|
|
1394
|
+
if (holds > 0) scan();
|
|
1395
|
+
});
|
|
1396
|
+
});
|
|
1397
|
+
watcher.observe(document.documentElement, { childList: true, subtree: true });
|
|
1398
|
+
stop = () => {
|
|
1399
|
+
document.removeEventListener("click", onClick);
|
|
1400
|
+
document.removeEventListener("keydown", onKey);
|
|
1401
|
+
window.removeEventListener("hashchange", onHash);
|
|
1402
|
+
window.clearInterval(clock);
|
|
1403
|
+
watcher.disconnect();
|
|
1404
|
+
autoplay.forEach((id) => window.clearInterval(id));
|
|
1405
|
+
autoplay.clear();
|
|
1406
|
+
seen2 = /* @__PURE__ */ new WeakSet();
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
scan();
|
|
1410
|
+
if (first) onHash();
|
|
1411
|
+
return () => {
|
|
1412
|
+
if (--holds === 0) stop?.();
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// src/interactions/entrance.tsx
|
|
1417
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1418
|
+
function entranceOf(entrance, delayMs, interactive) {
|
|
1419
|
+
if (!interactive || typeof entrance !== "string" || entrance === "none") return void 0;
|
|
1420
|
+
if (!import_builder_schema10.ENTRANCES.includes(entrance)) return void 0;
|
|
1421
|
+
const delay = typeof delayMs === "number" && Number.isFinite(delayMs) ? Math.min(2e3, Math.max(0, Math.round(delayMs))) : 0;
|
|
1422
|
+
return { name: entrance, delayMs: delay };
|
|
1423
|
+
}
|
|
1424
|
+
function InteractionRuntime() {
|
|
1425
|
+
(0, import_react8.useEffect)(() => startRuntime(), []);
|
|
1426
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("style", { href: "tb-interactions", precedence: "throttle", children: INTERACTIONS_CSS });
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// src/interactions/tabs.tsx
|
|
1430
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1431
|
+
function Tabs({ id, panels }) {
|
|
1432
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "tb-tabs", children: [
|
|
1433
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { role: "tablist", className: "tb-tablist", "data-b-tabs": "", children: panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1434
|
+
"button",
|
|
1435
|
+
{
|
|
1436
|
+
type: "button",
|
|
1437
|
+
role: "tab",
|
|
1438
|
+
className: "tb-tab",
|
|
1439
|
+
id: `${id}-t${String(i)}`,
|
|
1440
|
+
"aria-controls": `${id}-p${String(i)}`,
|
|
1441
|
+
"aria-selected": i === 0,
|
|
1442
|
+
tabIndex: i === 0 ? 0 : -1,
|
|
1443
|
+
children: panel.title
|
|
1444
|
+
},
|
|
1445
|
+
panel.key
|
|
1446
|
+
)) }),
|
|
1447
|
+
panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
1448
|
+
"div",
|
|
1449
|
+
{
|
|
1450
|
+
role: "tabpanel",
|
|
1451
|
+
className: "tb-panel",
|
|
1452
|
+
id: `${id}-p${String(i)}`,
|
|
1453
|
+
"aria-labelledby": `${id}-t${String(i)}`,
|
|
1454
|
+
tabIndex: 0,
|
|
1455
|
+
children: [
|
|
1456
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "tb-panel-title", children: panel.title }),
|
|
1457
|
+
panel.node
|
|
1458
|
+
]
|
|
1459
|
+
},
|
|
1460
|
+
panel.key
|
|
1461
|
+
))
|
|
1462
|
+
] });
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/interactions/toggle.tsx
|
|
1466
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1467
|
+
function Toggle({
|
|
1468
|
+
labelOpen,
|
|
1469
|
+
labelClosed,
|
|
1470
|
+
startOpen,
|
|
1471
|
+
children
|
|
1472
|
+
}) {
|
|
1473
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("details", { className: "tb-toggle", ...startOpen ? { open: true } : {}, children: [
|
|
1474
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("summary", { className: "tb-toggle-sum", children: [
|
|
1475
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "tb-toggle-closed", children: labelClosed }),
|
|
1476
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "tb-toggle-open", children: labelOpen })
|
|
1477
|
+
] }),
|
|
1478
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "tb-row", children })
|
|
1479
|
+
] });
|
|
423
1480
|
}
|
|
424
1481
|
|
|
425
1482
|
// src/styles.ts
|
|
@@ -444,9 +1501,9 @@ var BASE_CSS = `@layer throttle{
|
|
|
444
1501
|
}`;
|
|
445
1502
|
|
|
446
1503
|
// src/renderer.tsx
|
|
447
|
-
var
|
|
1504
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
448
1505
|
var DEVICES = ["desktop", "tablet", "phone"];
|
|
449
|
-
var COMMON_BY_KEY2 = new Map(
|
|
1506
|
+
var COMMON_BY_KEY2 = new Map(import_builder_schema11.COMMON_WIDGET_SETTINGS.map((f) => [f.key, f]));
|
|
450
1507
|
var withCustomCache = /* @__PURE__ */ new WeakMap();
|
|
451
1508
|
function registryFor(doc, base) {
|
|
452
1509
|
const snapshots = doc.customWidgets;
|
|
@@ -461,7 +1518,7 @@ function registryFor(doc, base) {
|
|
|
461
1518
|
try {
|
|
462
1519
|
registry = base.withCustom(
|
|
463
1520
|
Object.values(snapshots).filter(
|
|
464
|
-
(snapshot) => snapshot.kind !== "code"
|
|
1521
|
+
(snapshot) => snapshot.kind !== "code" || import_builder_schema11.codeWidgetSnapshotSchema.safeParse(snapshot).success
|
|
465
1522
|
)
|
|
466
1523
|
);
|
|
467
1524
|
} catch (error) {
|
|
@@ -472,7 +1529,7 @@ function registryFor(doc, base) {
|
|
|
472
1529
|
}
|
|
473
1530
|
return registry;
|
|
474
1531
|
}
|
|
475
|
-
var
|
|
1532
|
+
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
476
1533
|
function pickLocale(value, locale) {
|
|
477
1534
|
const lang = locale.split("-")[0] ?? locale;
|
|
478
1535
|
for (const key of [locale, lang, "en"]) {
|
|
@@ -483,25 +1540,25 @@ function pickLocale(value, locale) {
|
|
|
483
1540
|
return "";
|
|
484
1541
|
}
|
|
485
1542
|
function onOrigin(asset, mediaOrigin) {
|
|
486
|
-
if ((0,
|
|
487
|
-
return { ...asset, variants: asset.variants.filter((v) => (0,
|
|
1543
|
+
if ((0, import_builder_schema11.safeUrl)(asset.url, "src", { mediaOrigin }) === null) return null;
|
|
1544
|
+
return { ...asset, variants: asset.variants.filter((v) => (0, import_builder_schema11.safeUrl)(v.url, "src", { mediaOrigin }) !== null) };
|
|
488
1545
|
}
|
|
489
1546
|
function prepare(field, value, ctx) {
|
|
490
1547
|
if (field === void 0 || value === null) return value;
|
|
491
|
-
if (field.translatable === true &&
|
|
1548
|
+
if (field.translatable === true && isRecord2(value)) return pickLocale(value, ctx.locale);
|
|
492
1549
|
if (field.control === "image" && typeof value === "string") {
|
|
493
1550
|
const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
|
|
494
1551
|
return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
|
|
495
1552
|
}
|
|
496
|
-
if (field.control === "link" &&
|
|
1553
|
+
if (field.control === "link" && isRecord2(value) && typeof value.kind === "string") {
|
|
497
1554
|
const target = value;
|
|
498
1555
|
const raw = ctx.resolveLink?.(target) ?? (target.kind === "url" ? target.href : null);
|
|
499
|
-
return { ...value, href: (0,
|
|
1556
|
+
return { ...value, href: (0, import_builder_schema11.safeUrl)(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
|
|
500
1557
|
}
|
|
501
1558
|
return value;
|
|
502
1559
|
}
|
|
503
1560
|
function storedLinkPart(value) {
|
|
504
|
-
if (!
|
|
1561
|
+
if (!isRecord2(value) || value.kind !== "page") return value;
|
|
505
1562
|
const { slug: _slug, href: _href, ...stored } = value;
|
|
506
1563
|
void _slug;
|
|
507
1564
|
void _href;
|
|
@@ -510,13 +1567,13 @@ function storedLinkPart(value) {
|
|
|
510
1567
|
function settingsAt(node, fields, device, ctx) {
|
|
511
1568
|
const base = {};
|
|
512
1569
|
for (const field of fields.values()) base[field.key] = field.default;
|
|
513
|
-
const resolved = (0,
|
|
1570
|
+
const resolved = (0, import_builder_schema11.resolveResponsive)({ ...base, ...node.props }, node.responsive, device);
|
|
514
1571
|
const out = {};
|
|
515
1572
|
for (const [key, value] of Object.entries(resolved)) {
|
|
516
1573
|
const field = fields.get(key);
|
|
517
1574
|
const freeText = field?.control === "text" || field?.control === "richtext";
|
|
518
|
-
const
|
|
519
|
-
const usable = field === void 0 || (freeText ? value !== null : (0,
|
|
1575
|
+
const checked2 = field?.control === "link" ? storedLinkPart(value) : value;
|
|
1576
|
+
const usable = field === void 0 || (freeText ? value !== null : (0, import_builder_schema11.validateSettingValue)(field, checked2) === null) ? value : field.default;
|
|
520
1577
|
out[key] = prepare(field, usable, ctx);
|
|
521
1578
|
}
|
|
522
1579
|
return out;
|
|
@@ -536,33 +1593,67 @@ function variantsOf(node, def, fields, ctx) {
|
|
|
536
1593
|
}
|
|
537
1594
|
function hiddenEverywhere(props, responsive) {
|
|
538
1595
|
return DEVICES.every(
|
|
539
|
-
(device) => (0,
|
|
1596
|
+
(device) => (0, import_builder_schema11.resolveResponsive)({ hidden: props.hidden ?? false }, responsive, device).hidden === true
|
|
540
1597
|
);
|
|
541
1598
|
}
|
|
542
1599
|
var variantClass = (variant) => `tb-v ${variant.devices.map((d) => `tb-only-${d}`).join(" ")}`;
|
|
1600
|
+
function renderCodeWidget(node, snapshot, ctx, registry) {
|
|
1601
|
+
if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
|
|
1602
|
+
const def = registry.widget(node.type, node.v);
|
|
1603
|
+
const fields = new Map([...COMMON_BY_KEY2, ...(def?.settings ?? []).map((f) => [f.key, f])]);
|
|
1604
|
+
const data = {};
|
|
1605
|
+
for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
|
|
1606
|
+
const key = bindingKey(binding);
|
|
1607
|
+
const value = Object.hasOwn(ctx.data, key) ? ctx.data[key] : void 0;
|
|
1608
|
+
if (value !== void 0) data[name] = value;
|
|
1609
|
+
}
|
|
1610
|
+
const props = settingsAt(node, fields, "desktop", ctx);
|
|
1611
|
+
const anchor = props.anchor;
|
|
1612
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1613
|
+
CodeWidget,
|
|
1614
|
+
{
|
|
1615
|
+
node,
|
|
1616
|
+
snapshot,
|
|
1617
|
+
registry,
|
|
1618
|
+
props,
|
|
1619
|
+
data,
|
|
1620
|
+
locale: ctx.locale,
|
|
1621
|
+
mediaOrigin: ctx.mediaOrigin,
|
|
1622
|
+
edit: ctx.edit,
|
|
1623
|
+
code: ctx.code,
|
|
1624
|
+
interactive: ctx.interactive,
|
|
1625
|
+
anchor: !ctx.dupe && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
1626
|
+
copyAnchor: ctx.vpath !== "" && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
1627
|
+
entrance: entranceOf(props.entrance, props.entranceDelayMs, ctx.interactive)
|
|
1628
|
+
}
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
543
1631
|
function renderWidget(node, ctx, registry) {
|
|
1632
|
+
const key = `${node.type}@${String(node.v)}`;
|
|
1633
|
+
const frozen = ctx.snapshots !== void 0 && Object.hasOwn(ctx.snapshots, key) ? ctx.snapshots[key] : void 0;
|
|
1634
|
+
if (frozen?.kind === "code") return renderCodeWidget(node, frozen, ctx, registry);
|
|
544
1635
|
const def = registry.widget(node.type, node.v);
|
|
545
1636
|
const Component2 = def === void 0 ? void 0 : registry.component(node);
|
|
546
1637
|
if (def === void 0 || Component2 === void 0) {
|
|
547
1638
|
if (isDevelopment()) {
|
|
548
1639
|
warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
|
|
549
1640
|
}
|
|
550
|
-
return /* @__PURE__ */ (0,
|
|
1641
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
|
|
551
1642
|
}
|
|
552
1643
|
if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
|
|
553
1644
|
const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
|
|
554
1645
|
const variants = variantsOf(node, def, fields, ctx);
|
|
555
1646
|
const data = {};
|
|
556
1647
|
for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
|
|
557
|
-
const
|
|
558
|
-
const value = Object.hasOwn(ctx.data,
|
|
1648
|
+
const key2 = bindingKey(binding);
|
|
1649
|
+
const value = Object.hasOwn(ctx.data, key2) ? ctx.data[key2] : void 0;
|
|
559
1650
|
if (value !== void 0) data[name] = value;
|
|
560
1651
|
}
|
|
561
1652
|
const custom = node.type.startsWith("custom.");
|
|
562
1653
|
const edit = ctx.edit;
|
|
563
1654
|
return variants.map((variant, index) => {
|
|
564
1655
|
const anchor = variant.props.anchor;
|
|
565
|
-
return /* @__PURE__ */ (0,
|
|
1656
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
566
1657
|
NodeWrapper,
|
|
567
1658
|
{
|
|
568
1659
|
id: node.id,
|
|
@@ -571,18 +1662,22 @@ function renderWidget(node, ctx, registry) {
|
|
|
571
1662
|
custom,
|
|
572
1663
|
edit,
|
|
573
1664
|
className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
|
|
574
|
-
anchor: index === 0 && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
575
|
-
|
|
1665
|
+
anchor: index === 0 && !ctx.dupe && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
1666
|
+
copyAnchor: ctx.vpath !== "" && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
1667
|
+
entrance: entranceOf(variant.props.entrance, variant.props.entranceDelayMs, ctx.interactive),
|
|
1668
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
576
1669
|
Component2,
|
|
577
1670
|
{
|
|
578
1671
|
node,
|
|
579
1672
|
props: variant.props,
|
|
580
1673
|
data,
|
|
581
1674
|
editMode: edit !== void 0,
|
|
1675
|
+
interactive: ctx.interactive,
|
|
1676
|
+
idScope: ctx.vpath === "" && !ctx.dupe ? void 0 : { vpath: ctx.vpath, dupe: ctx.dupe },
|
|
582
1677
|
locale: ctx.locale,
|
|
583
1678
|
mediaOrigin: ctx.mediaOrigin,
|
|
584
1679
|
resolveLink: ctx.resolveLink,
|
|
585
|
-
inlineEdit: edit === void 0 ? void 0 : (
|
|
1680
|
+
inlineEdit: edit === void 0 ? void 0 : (key2) => edit.inlineEdit(node.id, key2),
|
|
586
1681
|
budget: custom ? new RenderBudget() : void 0
|
|
587
1682
|
}
|
|
588
1683
|
)
|
|
@@ -593,62 +1688,167 @@ function renderWidget(node, ctx, registry) {
|
|
|
593
1688
|
}
|
|
594
1689
|
function renderColumn(column, ctx, registry) {
|
|
595
1690
|
if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
|
|
596
|
-
return /* @__PURE__ */ (0,
|
|
1691
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
597
1692
|
NodeWrapper,
|
|
598
1693
|
{
|
|
599
1694
|
id: column.id,
|
|
600
1695
|
part: "column",
|
|
601
1696
|
className: "tb-col",
|
|
602
|
-
anchor: column.props.anchor,
|
|
1697
|
+
anchor: ctx.dupe ? void 0 : column.props.anchor,
|
|
1698
|
+
copyAnchor: ctx.vpath === "" ? void 0 : column.props.anchor,
|
|
603
1699
|
edit: ctx.edit,
|
|
1700
|
+
entrance: entranceOf(
|
|
1701
|
+
(0, import_builder_schema11.resolveEntrance)(column, "desktop").entrance,
|
|
1702
|
+
(0, import_builder_schema11.resolveEntrance)(column, "desktop").entranceDelayMs,
|
|
1703
|
+
ctx.interactive
|
|
1704
|
+
),
|
|
604
1705
|
children: column.children.map(
|
|
605
|
-
(child) => child.type === "inner-section" ? /* @__PURE__ */ (0,
|
|
1706
|
+
(child) => child.type === "inner-section" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderWidget(child, ctx, registry) }, child.id)
|
|
606
1707
|
)
|
|
607
1708
|
},
|
|
608
1709
|
column.id
|
|
609
1710
|
);
|
|
610
1711
|
}
|
|
1712
|
+
var PLAIN = (0, import_builder_schema11.resolveInteraction)({ props: {}, responsive: void 0 }, "desktop");
|
|
1713
|
+
function sectionVariants(section, ctx) {
|
|
1714
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1715
|
+
for (const device of DEVICES) {
|
|
1716
|
+
const interaction = ctx.interactive ? (0, import_builder_schema11.resolveInteraction)(section, device) : PLAIN;
|
|
1717
|
+
const entrance = ctx.interactive ? (0, import_builder_schema11.resolveEntrance)(section, device) : { entrance: "none", entranceDelayMs: 0 };
|
|
1718
|
+
const signature = stable([interaction, entrance]);
|
|
1719
|
+
const group = groups.get(signature);
|
|
1720
|
+
if (group === void 0) groups.set(signature, { devices: [device], interaction, entrance });
|
|
1721
|
+
else group.devices.push(device);
|
|
1722
|
+
}
|
|
1723
|
+
return [...groups.values()];
|
|
1724
|
+
}
|
|
1725
|
+
function panelsOf(section, ctx, registry, fallback) {
|
|
1726
|
+
const rendered = section.columns.map((column) => ({ column, node: renderColumn(column, ctx, registry) })).filter((entry) => entry.node !== null);
|
|
1727
|
+
return rendered.map(({ column, node }, i) => {
|
|
1728
|
+
const title = pickLocale(column.props.panelTitle ?? {}, ctx.locale).trim();
|
|
1729
|
+
return { key: column.id, title: title === "" ? fallback(i + 1, rendered.length) : title, node };
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
611
1732
|
function renderSection(section, ctx, registry, nested = false) {
|
|
612
1733
|
if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
1734
|
+
const variants = sectionVariants(section, ctx);
|
|
1735
|
+
const marker = variants.length > 1 && !ctx.dupe && section.props.anchor !== void 0 && import_builder_schema11.ANCHOR_RE.test(section.props.anchor) ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: section.props.anchor, className: "tb-anchor" }, "anchor") : null;
|
|
1736
|
+
const copies = variants.map((variant, index) => {
|
|
1737
|
+
const { interaction } = variant;
|
|
1738
|
+
const id = `ix-${section.id}-${ctx.vpath}${String(index)}`;
|
|
1739
|
+
const own = variants.length > 1 ? { ...ctx, vpath: `${ctx.vpath}${String(index)}-`, dupe: ctx.dupe || index > 0 } : ctx;
|
|
1740
|
+
const columns = () => section.columns.map((column) => renderColumn(column, own, registry));
|
|
1741
|
+
let body;
|
|
1742
|
+
if (interaction.interaction === "tabs") {
|
|
1743
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Tabs, { id, panels: panelsOf(section, own, registry, (n) => `Tab ${String(n)}`) });
|
|
1744
|
+
} else if (interaction.interaction === "accordion") {
|
|
1745
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1746
|
+
Accordion,
|
|
1747
|
+
{
|
|
1748
|
+
id,
|
|
1749
|
+
panels: panelsOf(section, own, registry, (n) => `Section ${String(n)}`),
|
|
1750
|
+
multiple: interaction.accordionMultiple,
|
|
1751
|
+
openFirst: interaction.accordionOpenFirst
|
|
1752
|
+
}
|
|
1753
|
+
);
|
|
1754
|
+
} else if (interaction.interaction === "carousel") {
|
|
1755
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1756
|
+
Carousel,
|
|
1757
|
+
{
|
|
1758
|
+
panels: panelsOf(section, own, registry, () => ""),
|
|
1759
|
+
autoplayMs: interaction.carouselAutoplay ? interaction.carouselIntervalMs : null,
|
|
1760
|
+
loop: interaction.carouselLoop
|
|
1761
|
+
}
|
|
1762
|
+
);
|
|
1763
|
+
} else if (interaction.interaction === "toggle") {
|
|
1764
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1765
|
+
Toggle,
|
|
1766
|
+
{
|
|
1767
|
+
labelOpen: pickLocale(interaction.toggleLabelOpen, ctx.locale),
|
|
1768
|
+
labelClosed: pickLocale(interaction.toggleLabelClosed, ctx.locale),
|
|
1769
|
+
startOpen: interaction.toggleStartOpen,
|
|
1770
|
+
children: columns()
|
|
1771
|
+
}
|
|
1772
|
+
);
|
|
1773
|
+
} else {
|
|
1774
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-row", children: columns() });
|
|
623
1775
|
}
|
|
624
|
-
|
|
1776
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1777
|
+
NodeWrapper,
|
|
1778
|
+
{
|
|
1779
|
+
id: section.id,
|
|
1780
|
+
part: "section",
|
|
1781
|
+
as: nested ? "div" : "section",
|
|
1782
|
+
className: `${nested ? "tb-section tb-nested" : "tb-section"}${variants.length > 1 ? ` ${variantClass({ devices: variant.devices, props: {} })}` : ""}`,
|
|
1783
|
+
anchor: variants.length === 1 && !ctx.dupe ? section.props.anchor : void 0,
|
|
1784
|
+
copyAnchor: variants.length > 1 || ctx.vpath !== "" ? section.props.anchor : void 0,
|
|
1785
|
+
edit: ctx.edit,
|
|
1786
|
+
entrance: entranceOf(variant.entrance.entrance, variant.entrance.entranceDelayMs, ctx.interactive),
|
|
1787
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-inner", children: body })
|
|
1788
|
+
},
|
|
1789
|
+
variant.devices.join("-")
|
|
1790
|
+
);
|
|
1791
|
+
});
|
|
1792
|
+
return marker === null ? copies : [marker, ...copies];
|
|
1793
|
+
}
|
|
1794
|
+
function needsRuntime(doc) {
|
|
1795
|
+
let found = false;
|
|
1796
|
+
(0, import_builder_schema11.walkNodes)(doc, (node) => {
|
|
1797
|
+
if (found || node.type === "saved-section") return;
|
|
1798
|
+
if (node.type === "section" || node.type === "inner-section") {
|
|
1799
|
+
found = DEVICES.some(
|
|
1800
|
+
(device) => (0, import_builder_schema11.resolveInteraction)(node, device).interaction !== "none" || (0, import_builder_schema11.resolveEntrance)(node, device).entrance !== "none"
|
|
1801
|
+
);
|
|
1802
|
+
} else if (node.type === "column") {
|
|
1803
|
+
found = DEVICES.some((device) => (0, import_builder_schema11.resolveEntrance)(node, device).entrance !== "none");
|
|
1804
|
+
} else {
|
|
1805
|
+
found = DEVICES.some((device) => {
|
|
1806
|
+
const entrance = (0, import_builder_schema11.resolveResponsive)(node.props, node.responsive, device).entrance;
|
|
1807
|
+
return entrance !== void 0 && entrance !== "none";
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
return found;
|
|
625
1812
|
}
|
|
626
1813
|
function BuilderRenderer(props) {
|
|
627
|
-
const { document:
|
|
1814
|
+
const { document: raw, registry: base, data, editMode, locale, assets, resolveLink, code } = props;
|
|
1815
|
+
const expansion = expandSavedSections(raw, props.savedSections);
|
|
1816
|
+
const source = expansion.doc;
|
|
628
1817
|
const registry = registryFor(source, base);
|
|
629
|
-
const { doc } = (0,
|
|
1818
|
+
const { doc } = (0, import_builder_schema11.upgradeNodes)(source, registry);
|
|
630
1819
|
const mediaOrigin = props.mediaOrigin ?? "";
|
|
631
|
-
const
|
|
1820
|
+
const interactive = props.interactive !== false;
|
|
1821
|
+
const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, code, edit: editMode, interactive, vpath: props.idScope?.vpath ?? "", dupe: props.idScope?.dupe ?? false, snapshots: source.customWidgets };
|
|
632
1822
|
const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
)
|
|
1823
|
+
const upgraded = new Map(doc.sections.map((section) => [section.id, section]));
|
|
1824
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "tb-root", "data-throttle-part": "builder-root", ...props.scopeCustomCss === true ? { "data-b-root": "" } : {}, children: [
|
|
1825
|
+
interactive && needsRuntime(doc) ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(InteractionRuntime, {}) : null,
|
|
1826
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
1827
|
+
css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("style", { children: css }),
|
|
1828
|
+
(expansion.roots ?? doc.sections.map((section) => ({ kind: "section", id: section.id }))).map((root) => {
|
|
1829
|
+
if (root.kind === "section") {
|
|
1830
|
+
const section2 = upgraded.get(root.id);
|
|
1831
|
+
return section2?.type === "section" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderSection(section2, ctx, registry) }, root.id) : null;
|
|
1832
|
+
}
|
|
1833
|
+
const section = root.sectionId === null ? void 0 : upgraded.get(root.sectionId);
|
|
1834
|
+
if (section?.type === "section") {
|
|
1835
|
+
return root.ref.props.hidden === true && ctx.edit === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderSection(section, ctx, registry) }, root.ref.id);
|
|
1836
|
+
}
|
|
1837
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MissingSavedSection, { node: root.ref }, root.ref.id);
|
|
1838
|
+
})
|
|
639
1839
|
] });
|
|
640
1840
|
}
|
|
641
1841
|
function validateRender(doc) {
|
|
642
1842
|
const h1 = [];
|
|
643
|
-
(0,
|
|
1843
|
+
(0, import_builder_schema11.walkNodes)(doc, (node) => {
|
|
644
1844
|
if (node.type === "basic.heading" && node.props.level === "h1") h1.push(node.id);
|
|
645
1845
|
});
|
|
646
1846
|
return h1.length > 1 ? [{ code: "MULTIPLE_H1", message: `The page has ${String(h1.length)} level 1 headings; use one`, nodeIds: h1 }] : [];
|
|
647
1847
|
}
|
|
648
1848
|
|
|
649
1849
|
// src/asset-image.tsx
|
|
650
|
-
var
|
|
651
|
-
var
|
|
1850
|
+
var import_builder_schema12 = require("@usethrottle/builder-schema");
|
|
1851
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
652
1852
|
function isFrozenAsset(value) {
|
|
653
1853
|
if (typeof value !== "object" || value === null) return false;
|
|
654
1854
|
const v = value;
|
|
@@ -656,7 +1856,7 @@ function isFrozenAsset(value) {
|
|
|
656
1856
|
}
|
|
657
1857
|
function AssetImage(props) {
|
|
658
1858
|
const { asset, alt, sizes, className, loading = "lazy", style, mediaOrigin } = props;
|
|
659
|
-
const href = (url) => (0,
|
|
1859
|
+
const href = (url) => (0, import_builder_schema12.safeUrl)(url, "src", { mediaOrigin });
|
|
660
1860
|
if (!isFrozenAsset(asset)) return null;
|
|
661
1861
|
const src = href(asset.url);
|
|
662
1862
|
if (src === null) return null;
|
|
@@ -664,7 +1864,7 @@ function AssetImage(props) {
|
|
|
664
1864
|
const url = href(variant.url);
|
|
665
1865
|
return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
|
|
666
1866
|
}).join(", ");
|
|
667
|
-
return /* @__PURE__ */ (0,
|
|
1867
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
668
1868
|
"img",
|
|
669
1869
|
{
|
|
670
1870
|
src,
|
|
@@ -680,46 +1880,36 @@ function AssetImage(props) {
|
|
|
680
1880
|
);
|
|
681
1881
|
}
|
|
682
1882
|
|
|
683
|
-
// src/widget-style.tsx
|
|
684
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
685
|
-
function WidgetStyle({ css }) {
|
|
686
|
-
if (css === "" || css.includes("<")) return null;
|
|
687
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: css });
|
|
688
|
-
}
|
|
689
|
-
|
|
690
1883
|
// src/provider.tsx
|
|
691
|
-
var
|
|
1884
|
+
var import_react18 = require("react");
|
|
692
1885
|
var import_builder2 = require("@usethrottle/builder");
|
|
693
1886
|
var import_ui6 = require("@usethrottle/ui");
|
|
694
1887
|
|
|
695
|
-
// src/context.ts
|
|
696
|
-
var import_react2 = require("react");
|
|
697
|
-
var BuilderContext = typeof import_react2.createContext === "function" ? (0, import_react2.createContext)(null) : null;
|
|
698
|
-
var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
|
|
699
|
-
|
|
700
1888
|
// src/page.tsx
|
|
701
|
-
var
|
|
1889
|
+
var import_react10 = require("react");
|
|
702
1890
|
var import_builder = require("@usethrottle/builder");
|
|
703
1891
|
|
|
704
1892
|
// src/load.ts
|
|
705
1893
|
function pageOf(raw, initialData) {
|
|
706
|
-
const { document, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, ...meta } = raw;
|
|
1894
|
+
const { document: document2, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, savedSections, code, ...meta } = raw;
|
|
707
1895
|
return {
|
|
708
1896
|
kind: "page",
|
|
709
1897
|
slug,
|
|
710
1898
|
title,
|
|
711
1899
|
path,
|
|
712
1900
|
generation,
|
|
713
|
-
document,
|
|
714
|
-
assets:
|
|
1901
|
+
document: document2,
|
|
1902
|
+
assets: document2.assets ?? {},
|
|
715
1903
|
initialData,
|
|
716
|
-
meta
|
|
1904
|
+
meta,
|
|
1905
|
+
...savedSections === void 0 ? {} : { savedSections },
|
|
1906
|
+
...code === void 0 ? {} : { code }
|
|
717
1907
|
};
|
|
718
1908
|
}
|
|
719
1909
|
var isRedirect = (raw) => typeof raw.redirectTo === "string";
|
|
720
1910
|
|
|
721
1911
|
// src/safe-path.ts
|
|
722
|
-
var
|
|
1912
|
+
var import_builder_schema13 = require("@usethrottle/builder-schema");
|
|
723
1913
|
var UNSAFE = /[\x00-\x20\x7f-\xa0\\\u1680\u2000-\u200f\u2028\u2029\u202f\u205f\u3000\ufeff]/;
|
|
724
1914
|
var LEADING = /^\/(?![/\\])/;
|
|
725
1915
|
function plainPath(path) {
|
|
@@ -727,51 +1917,31 @@ function plainPath(path) {
|
|
|
727
1917
|
}
|
|
728
1918
|
function sitePath(to) {
|
|
729
1919
|
if (typeof to !== "string" || !plainPath(to)) return null;
|
|
730
|
-
let
|
|
1920
|
+
let decoded2;
|
|
731
1921
|
try {
|
|
732
|
-
|
|
1922
|
+
decoded2 = decodeURIComponent(to);
|
|
733
1923
|
} catch {
|
|
734
1924
|
return null;
|
|
735
1925
|
}
|
|
736
|
-
if (!plainPath(
|
|
737
|
-
return (0,
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
// src/shopper-data.ts
|
|
741
|
-
var import_react3 = require("react");
|
|
742
|
-
function useResolvedData(document, registry, locale, include, context) {
|
|
743
|
-
const [data, setData] = (0, import_react3.useState)({});
|
|
744
|
-
(0, import_react3.useEffect)(() => {
|
|
745
|
-
const controller = new AbortController();
|
|
746
|
-
const bindings = collectBindings(document, registry);
|
|
747
|
-
if (bindings.size === 0) return void 0;
|
|
748
|
-
void resolveBindings(
|
|
749
|
-
bindings,
|
|
750
|
-
registry,
|
|
751
|
-
{ locale, preview: false, context, signal: controller.signal },
|
|
752
|
-
{ include }
|
|
753
|
-
).then((resolved) => {
|
|
754
|
-
if (!controller.signal.aborted && Object.keys(resolved).length > 0) setData(resolved);
|
|
755
|
-
});
|
|
756
|
-
return () => controller.abort();
|
|
757
|
-
}, [document, registry, locale, include, context]);
|
|
758
|
-
return data;
|
|
1926
|
+
if (!plainPath(decoded2)) return null;
|
|
1927
|
+
return (0, import_builder_schema13.safeUrl)(to, "href", { mediaOrigin: "" });
|
|
759
1928
|
}
|
|
760
1929
|
|
|
761
1930
|
// src/page.tsx
|
|
762
|
-
var
|
|
1931
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
763
1932
|
function BuilderPageView({ page, resolve = "shopper" }) {
|
|
764
1933
|
const builder = useBuilder();
|
|
765
1934
|
if (builder === null) throw new Error("A Builder page needs a BuilderProvider above it");
|
|
766
|
-
return /* @__PURE__ */ (0,
|
|
1935
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(PageBody, { page, resolve, builder });
|
|
767
1936
|
}
|
|
768
1937
|
function PageBody({
|
|
769
1938
|
page,
|
|
770
1939
|
resolve,
|
|
771
1940
|
builder
|
|
772
1941
|
}) {
|
|
773
|
-
const
|
|
774
|
-
|
|
1942
|
+
const expanded = expandSavedSections(page.document, page.savedSections).doc;
|
|
1943
|
+
const resolved = useResolvedData(expanded, builder.registry, builder.locale, resolve);
|
|
1944
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
775
1945
|
BuilderRenderer,
|
|
776
1946
|
{
|
|
777
1947
|
document: page.document,
|
|
@@ -780,7 +1950,11 @@ function PageBody({
|
|
|
780
1950
|
locale: builder.locale,
|
|
781
1951
|
assets: page.assets,
|
|
782
1952
|
mediaOrigin: builder.mediaOrigin,
|
|
783
|
-
resolveLink: builder.resolveLink
|
|
1953
|
+
resolveLink: builder.resolveLink,
|
|
1954
|
+
interactive: builder.interactive,
|
|
1955
|
+
scopeCustomCss: builder.customCss !== "",
|
|
1956
|
+
savedSections: page.savedSections,
|
|
1957
|
+
code: codeRenderOf(builder, page.code)
|
|
784
1958
|
}
|
|
785
1959
|
);
|
|
786
1960
|
}
|
|
@@ -819,7 +1993,7 @@ function read(client, slug, locale) {
|
|
|
819
1993
|
function BuilderPage({ slug, initial }) {
|
|
820
1994
|
const builder = useBuilder();
|
|
821
1995
|
if (builder === null) throw new Error("BuilderPage needs a BuilderProvider above it");
|
|
822
|
-
if (initial !== void 0) return /* @__PURE__ */ (0,
|
|
1996
|
+
if (initial !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(BuilderPageView, { page: initial });
|
|
823
1997
|
if (builder.site.status === "unavailable") {
|
|
824
1998
|
throw new import_builder.BuilderUnavailableError("network", "The Builder is unavailable and has no last good answer");
|
|
825
1999
|
}
|
|
@@ -827,95 +2001,30 @@ function BuilderPage({ slug, initial }) {
|
|
|
827
2001
|
throw new Error("BuilderPage reads the page itself: give BuilderProvider a builderKey or a client, or pass `initial`");
|
|
828
2002
|
}
|
|
829
2003
|
const found = read(builder.client, slug, builder.locale);
|
|
830
|
-
if ("redirectTo" in found) return /* @__PURE__ */ (0,
|
|
831
|
-
return /* @__PURE__ */ (0,
|
|
2004
|
+
if ("redirectTo" in found) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Redirect, { to: found.redirectTo });
|
|
2005
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(BuilderPageView, { page: found, resolve: "all" });
|
|
832
2006
|
}
|
|
833
2007
|
function Redirect({ to }) {
|
|
834
|
-
(0,
|
|
2008
|
+
(0, import_react10.useEffect)(() => {
|
|
835
2009
|
const path = sitePath(to);
|
|
836
2010
|
if (path !== null) window.location.replace(path);
|
|
837
2011
|
}, [to]);
|
|
838
2012
|
return null;
|
|
839
2013
|
}
|
|
840
2014
|
|
|
841
|
-
// src/part-view.tsx
|
|
842
|
-
var import_react5 = require("react");
|
|
843
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
844
|
-
var BoundaryBase = import_react5.Component ?? class {
|
|
845
|
-
};
|
|
846
|
-
var Boundary = class extends BoundaryBase {
|
|
847
|
-
constructor() {
|
|
848
|
-
super(...arguments);
|
|
849
|
-
__publicField(this, "state", { failed: false });
|
|
850
|
-
}
|
|
851
|
-
static getDerivedStateFromError() {
|
|
852
|
-
return { failed: true };
|
|
853
|
-
}
|
|
854
|
-
componentDidCatch(error, _info) {
|
|
855
|
-
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
856
|
-
try {
|
|
857
|
-
this.props.onError?.(error, { part: this.props.label });
|
|
858
|
-
} catch {
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
componentDidUpdate(previous) {
|
|
862
|
-
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
863
|
-
if (moved && this.state.failed) this.setState({ failed: false });
|
|
864
|
-
}
|
|
865
|
-
render() {
|
|
866
|
-
return this.state.failed ? null : this.props.children;
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
function PartBoundary({
|
|
870
|
-
label,
|
|
871
|
-
resetKey,
|
|
872
|
-
children
|
|
873
|
-
}) {
|
|
874
|
-
const builder = useBuilder();
|
|
875
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
876
|
-
}
|
|
877
|
-
function contextData(context) {
|
|
878
|
-
if (typeof context !== "object" || context === null) return {};
|
|
879
|
-
return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
|
|
880
|
-
}
|
|
881
|
-
function PartView({ part, context }) {
|
|
882
|
-
const builder = useBuilder();
|
|
883
|
-
if (builder === null) return null;
|
|
884
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PartBody, { part, context, builder });
|
|
885
|
-
}
|
|
886
|
-
function PartBody({
|
|
887
|
-
part,
|
|
888
|
-
context,
|
|
889
|
-
builder
|
|
890
|
-
}) {
|
|
891
|
-
const shopper = useResolvedData(part.document, builder.registry, builder.locale, "shopper", context);
|
|
892
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
893
|
-
BuilderRenderer,
|
|
894
|
-
{
|
|
895
|
-
document: part.document,
|
|
896
|
-
registry: builder.registry,
|
|
897
|
-
data: { ...part.initialData, ...contextData(context), ...shopper },
|
|
898
|
-
locale: builder.locale,
|
|
899
|
-
assets: part.assets,
|
|
900
|
-
mediaOrigin: builder.mediaOrigin,
|
|
901
|
-
resolveLink: builder.resolveLink
|
|
902
|
-
}
|
|
903
|
-
);
|
|
904
|
-
}
|
|
905
|
-
|
|
906
2015
|
// src/registry.ts
|
|
907
|
-
var
|
|
2016
|
+
var import_builder_schema23 = require("@usethrottle/builder-schema");
|
|
908
2017
|
|
|
909
2018
|
// src/basics/index.ts
|
|
910
|
-
var
|
|
2019
|
+
var import_builder_schema21 = require("@usethrottle/builder-schema");
|
|
911
2020
|
|
|
912
2021
|
// src/basics/announcement.tsx
|
|
913
|
-
var
|
|
2022
|
+
var import_react11 = require("react");
|
|
914
2023
|
var import_ui = require("@usethrottle/ui");
|
|
915
|
-
var
|
|
2024
|
+
var import_builder_schema15 = require("@usethrottle/builder-schema");
|
|
916
2025
|
|
|
917
2026
|
// src/basics/util.tsx
|
|
918
|
-
var
|
|
2027
|
+
var import_builder_schema14 = require("@usethrottle/builder-schema");
|
|
919
2028
|
|
|
920
2029
|
// src/basics/styles.ts
|
|
921
2030
|
var BASICS_CSS = `@layer throttle{
|
|
@@ -980,26 +2089,26 @@ var BASICS_CSS = `@layer throttle{
|
|
|
980
2089
|
}`;
|
|
981
2090
|
|
|
982
2091
|
// src/basics/util.tsx
|
|
983
|
-
var
|
|
2092
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
984
2093
|
function BasicStyles() {
|
|
985
|
-
return /* @__PURE__ */ (0,
|
|
2094
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
|
|
986
2095
|
}
|
|
987
|
-
var
|
|
2096
|
+
var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
988
2097
|
var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
989
2098
|
function oneOf(value, allowed, fallback) {
|
|
990
2099
|
return allowed.find((candidate) => candidate === value) ?? fallback;
|
|
991
2100
|
}
|
|
992
2101
|
function hrefOf(link, mediaOrigin) {
|
|
993
|
-
if (!
|
|
994
|
-
return (0,
|
|
2102
|
+
if (!isRecord3(link)) return null;
|
|
2103
|
+
return (0, import_builder_schema14.safeUrl)(link.href, "href", { mediaOrigin });
|
|
995
2104
|
}
|
|
996
2105
|
function Placeholder({ editMode, children }) {
|
|
997
|
-
return editMode ? /* @__PURE__ */ (0,
|
|
2106
|
+
return editMode ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "tb-b-empty", children }) : null;
|
|
998
2107
|
}
|
|
999
|
-
var ID_RE2 = /^[a-z0-9]{8,24}
|
|
2108
|
+
var ID_RE2 = /^[a-z0-9]{8,24}(-[a-z0-9]{8,24})?$/;
|
|
1000
2109
|
var DEVICES2 = ["desktop", "tablet", "phone"];
|
|
1001
2110
|
function defaultOf(type, key) {
|
|
1002
|
-
const def =
|
|
2111
|
+
const def = import_builder_schema14.BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
|
|
1003
2112
|
return def?.settings.find((f) => f.key === key)?.default ?? null;
|
|
1004
2113
|
}
|
|
1005
2114
|
function enumCss(node, rules) {
|
|
@@ -1007,7 +2116,7 @@ function enumCss(node, rules) {
|
|
|
1007
2116
|
const per = { desktop: /* @__PURE__ */ new Map(), tablet: /* @__PURE__ */ new Map(), phone: /* @__PURE__ */ new Map() };
|
|
1008
2117
|
for (const device of DEVICES2) {
|
|
1009
2118
|
const settings = { ...Object.fromEntries(rules.map((r) => [r.key, defaultOf(node.type, r.key)])), ...node.props };
|
|
1010
|
-
const resolved = (0,
|
|
2119
|
+
const resolved = (0, import_builder_schema14.resolveResponsive)(settings, node.responsive, device);
|
|
1011
2120
|
for (const rule of rules) {
|
|
1012
2121
|
const value = resolved[rule.key];
|
|
1013
2122
|
const fallback = defaultOf(node.type, rule.key);
|
|
@@ -1024,7 +2133,7 @@ function enumCss(node, rules) {
|
|
|
1024
2133
|
}
|
|
1025
2134
|
|
|
1026
2135
|
// src/basics/announcement.tsx
|
|
1027
|
-
var
|
|
2136
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1028
2137
|
var KEY = "tb-announcement-dismissed";
|
|
1029
2138
|
function read2(message) {
|
|
1030
2139
|
try {
|
|
@@ -1042,25 +2151,25 @@ function write(message) {
|
|
|
1042
2151
|
function Announcement({ props, mediaOrigin, editMode }) {
|
|
1043
2152
|
const design = (0, import_ui.useSiteDesign)();
|
|
1044
2153
|
const message = design?.announcement?.message;
|
|
1045
|
-
const [dismissed, setDismissed] = (0,
|
|
1046
|
-
(0,
|
|
2154
|
+
const [dismissed, setDismissed] = (0, import_react11.useState)(false);
|
|
2155
|
+
(0, import_react11.useEffect)(() => {
|
|
1047
2156
|
if (message !== void 0 && read2(message)) setDismissed(true);
|
|
1048
2157
|
}, [message]);
|
|
1049
2158
|
if (message === void 0) {
|
|
1050
|
-
return /* @__PURE__ */ (0,
|
|
1051
|
-
/* @__PURE__ */ (0,
|
|
1052
|
-
/* @__PURE__ */ (0,
|
|
2159
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
|
|
2160
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicStyles, {}),
|
|
2161
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
|
|
1053
2162
|
] });
|
|
1054
2163
|
}
|
|
1055
2164
|
if (dismissed && !editMode) return null;
|
|
1056
|
-
const href = (0,
|
|
2165
|
+
const href = (0, import_builder_schema15.safeUrl)(design?.announcement?.href, "href", { mediaOrigin });
|
|
1057
2166
|
const strings = design?.strings;
|
|
1058
|
-
const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ??
|
|
1059
|
-
return /* @__PURE__ */ (0,
|
|
1060
|
-
/* @__PURE__ */ (0,
|
|
1061
|
-
/* @__PURE__ */ (0,
|
|
1062
|
-
/* @__PURE__ */ (0,
|
|
1063
|
-
props.dismissible === true && /* @__PURE__ */ (0,
|
|
2167
|
+
const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? import_builder_schema15.SITE_STRING_DEFAULTS["announcement.dismiss"];
|
|
2168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
|
|
2169
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicStyles, {}),
|
|
2170
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
|
|
2171
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("a", { href, children: message }) }),
|
|
2172
|
+
props.dismissible === true && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1064
2173
|
"button",
|
|
1065
2174
|
{
|
|
1066
2175
|
type: "button",
|
|
@@ -1069,7 +2178,7 @@ function Announcement({ props, mediaOrigin, editMode }) {
|
|
|
1069
2178
|
write(message);
|
|
1070
2179
|
setDismissed(true);
|
|
1071
2180
|
},
|
|
1072
|
-
children: /* @__PURE__ */ (0,
|
|
2181
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui.Icon, { name: "close", size: 16, label: dismissLabel })
|
|
1073
2182
|
}
|
|
1074
2183
|
)
|
|
1075
2184
|
] })
|
|
@@ -1077,59 +2186,125 @@ function Announcement({ props, mediaOrigin, editMode }) {
|
|
|
1077
2186
|
}
|
|
1078
2187
|
|
|
1079
2188
|
// src/basics/button.tsx
|
|
1080
|
-
var
|
|
2189
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1081
2190
|
var STYLES = ["primary", "secondary", "outline", "link"];
|
|
1082
2191
|
var SIZES = ["s", "m", "l"];
|
|
1083
2192
|
function Button({ props, mediaOrigin, inlineEdit }) {
|
|
1084
2193
|
const href = hrefOf(props.link, mediaOrigin);
|
|
1085
2194
|
const className = `tb-b-button tb-b-button--${oneOf(props.style, STYLES, "primary")} tb-b-button--${oneOf(props.size, SIZES, "m")}`;
|
|
1086
2195
|
const label = inlineEdit?.("label") ?? str(props.label) ?? "";
|
|
1087
|
-
return /* @__PURE__ */ (0,
|
|
1088
|
-
/* @__PURE__ */ (0,
|
|
1089
|
-
/* @__PURE__ */ (0,
|
|
2196
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
|
|
2197
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BasicStyles, {}),
|
|
2198
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("a", { className, ...href === null ? {} : { href }, children: label }) })
|
|
1090
2199
|
] });
|
|
1091
2200
|
}
|
|
1092
2201
|
|
|
1093
2202
|
// src/basics/copyright.tsx
|
|
1094
2203
|
var import_ui2 = require("@usethrottle/ui");
|
|
1095
|
-
var
|
|
1096
|
-
var
|
|
2204
|
+
var import_builder_schema16 = require("@usethrottle/builder-schema");
|
|
2205
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
1097
2206
|
function Copyright(_) {
|
|
1098
2207
|
const design = (0, import_ui2.useSiteDesign)();
|
|
1099
2208
|
const strings = design?.strings;
|
|
1100
2209
|
const template = strings !== void 0 && Object.hasOwn(strings, "footer.copyright") ? str(strings["footer.copyright"]) : void 0;
|
|
1101
|
-
const line = (template ??
|
|
1102
|
-
return /* @__PURE__ */ (0,
|
|
1103
|
-
/* @__PURE__ */ (0,
|
|
1104
|
-
/* @__PURE__ */ (0,
|
|
2210
|
+
const line = (template ?? import_builder_schema16.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");
|
|
2211
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
|
|
2212
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(BasicStyles, {}),
|
|
2213
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "tb-b-copyright", children: line })
|
|
2214
|
+
] });
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
// src/basics/countdown.tsx
|
|
2218
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2219
|
+
var UNITS2 = [
|
|
2220
|
+
{ key: "d", show: "showDays", label: "labelDays", seconds: 86400 },
|
|
2221
|
+
{ key: "h", show: "showHours", label: "labelHours", seconds: 3600 },
|
|
2222
|
+
{ key: "m", show: "showMinutes", label: "labelMinutes", seconds: 60 },
|
|
2223
|
+
{ key: "s", show: "showSeconds", label: "labelSeconds", seconds: 1 }
|
|
2224
|
+
];
|
|
2225
|
+
var COUNTDOWN_CSS = `@layer throttle{
|
|
2226
|
+
.tb-b-cd{text-align:var(--b-align,center);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l))}
|
|
2227
|
+
.tb-b-cd-date{margin:0}
|
|
2228
|
+
.tb-b-cd-units{display:none;justify-content:var(--b-align,center);gap:var(--tb-space-m);flex-wrap:wrap}
|
|
2229
|
+
html[data-b-js] .tb-b-cd-units{display:flex}
|
|
2230
|
+
html[data-b-js] .tb-b-cd-date{font-size:.5em;opacity:.7}
|
|
2231
|
+
.tb-b-cd-unit{display:flex;flex-direction:column;align-items:center;min-inline-size:3ch}
|
|
2232
|
+
.tb-b-cd-num{font-variant-numeric:tabular-nums;font-weight:700;line-height:1.1}
|
|
2233
|
+
.tb-b-cd-label{font-size:.45em;opacity:.8}
|
|
2234
|
+
.tb-b-cd-ended{margin:0}
|
|
2235
|
+
.tb-b-cd[data-b-ended] .tb-b-cd-units,.tb-b-cd[data-b-ended] .tb-b-cd-date{display:none}
|
|
2236
|
+
.tb-b-sr{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
2237
|
+
}`;
|
|
2238
|
+
var two = (n) => String(n).padStart(2, "0");
|
|
2239
|
+
function targetText(date) {
|
|
2240
|
+
return `${date.toISOString().slice(0, 10)} ${date.toISOString().slice(11, 16)} UTC`;
|
|
2241
|
+
}
|
|
2242
|
+
function Countdown({ props, editMode, interactive, locale }) {
|
|
2243
|
+
void locale;
|
|
2244
|
+
const target = str(props.target);
|
|
2245
|
+
const when = target === void 0 ? null : new Date(target);
|
|
2246
|
+
if (when === null || Number.isNaN(when.getTime())) {
|
|
2247
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Placeholder, { editMode, children: "Set the date and time the countdown ends" });
|
|
2248
|
+
}
|
|
2249
|
+
const live = interactive !== false;
|
|
2250
|
+
const behavior = oneOf(props.expiredBehavior, ["text", "hide"], "text");
|
|
2251
|
+
const shown2 = UNITS2.filter((unit) => props[unit.show] !== false);
|
|
2252
|
+
let left = live ? 0 : Math.max(0, Math.floor((when.getTime() - Date.now()) / 1e3));
|
|
2253
|
+
const units = shown2.map((unit) => {
|
|
2254
|
+
const value = live ? null : Math.floor(left / unit.seconds);
|
|
2255
|
+
if (value !== null) left -= value * unit.seconds;
|
|
2256
|
+
return { ...unit, text: value === null ? "--" : two(value), name: str(props[unit.label]) ?? "" };
|
|
2257
|
+
});
|
|
2258
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
|
|
2259
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(BasicStyles, {}),
|
|
2260
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("style", { href: "tb-countdown", precedence: "throttle", children: COUNTDOWN_CSS }),
|
|
2261
|
+
live ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(InteractionRuntime, {}) : null,
|
|
2262
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
2263
|
+
"div",
|
|
2264
|
+
{
|
|
2265
|
+
className: "tb-b-cd",
|
|
2266
|
+
role: "timer",
|
|
2267
|
+
"aria-live": "off",
|
|
2268
|
+
...live ? { "data-b-cd": String(when.getTime()), "data-b-expired": behavior } : {},
|
|
2269
|
+
children: [
|
|
2270
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "tb-b-cd-date", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("time", { dateTime: when.toISOString(), children: targetText(when) }) }),
|
|
2271
|
+
units.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "tb-b-cd-units", children: units.map((unit) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "tb-b-cd-unit", children: [
|
|
2272
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "tb-b-cd-num", "data-u": unit.key, "aria-hidden": "true", children: unit.text }),
|
|
2273
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "tb-b-cd-label", children: unit.name })
|
|
2274
|
+
] }, unit.key)) }),
|
|
2275
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "tb-b-cd-ended", hidden: live || when.getTime() > Date.now(), children: str(props.expiredText) ?? "" }),
|
|
2276
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "tb-b-sr", "data-b-live": "", "aria-live": "polite" })
|
|
2277
|
+
]
|
|
2278
|
+
}
|
|
2279
|
+
)
|
|
1105
2280
|
] });
|
|
1106
2281
|
}
|
|
1107
2282
|
|
|
1108
2283
|
// src/basics/divider.tsx
|
|
1109
|
-
var
|
|
2284
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
1110
2285
|
var RULES = [{ key: "style", property: "--bx-style", values: { solid: "solid", dashed: "dashed", dotted: "dotted" } }];
|
|
1111
2286
|
function Divider({ node }) {
|
|
1112
|
-
return /* @__PURE__ */ (0,
|
|
1113
|
-
/* @__PURE__ */ (0,
|
|
1114
|
-
/* @__PURE__ */ (0,
|
|
1115
|
-
/* @__PURE__ */ (0,
|
|
2287
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
|
|
2288
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(BasicStyles, {}),
|
|
2289
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(WidgetStyle, { css: enumCss(node, RULES) }),
|
|
2290
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("hr", { className: "tb-b-divider" })
|
|
1116
2291
|
] });
|
|
1117
2292
|
}
|
|
1118
2293
|
|
|
1119
2294
|
// src/basics/heading.tsx
|
|
1120
|
-
var
|
|
2295
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
1121
2296
|
var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
1122
2297
|
function Heading({ props, inlineEdit }) {
|
|
1123
2298
|
const Tag = oneOf(props.level, LEVELS, "h2");
|
|
1124
|
-
return /* @__PURE__ */ (0,
|
|
1125
|
-
/* @__PURE__ */ (0,
|
|
1126
|
-
/* @__PURE__ */ (0,
|
|
2299
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
|
|
2300
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(BasicStyles, {}),
|
|
2301
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" })
|
|
1127
2302
|
] });
|
|
1128
2303
|
}
|
|
1129
2304
|
|
|
1130
2305
|
// src/basics/image.tsx
|
|
1131
|
-
var
|
|
1132
|
-
var
|
|
2306
|
+
var import_builder_schema17 = require("@usethrottle/builder-schema");
|
|
2307
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
1133
2308
|
var RULES2 = [
|
|
1134
2309
|
{ key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
|
|
1135
2310
|
{ key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
|
|
@@ -1139,23 +2314,23 @@ function Image({ node, props, mediaOrigin, editMode }) {
|
|
|
1139
2314
|
const decorative = props.decorative === true;
|
|
1140
2315
|
const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
|
|
1141
2316
|
const asset = isFrozenAsset(props.image) ? props.image : void 0;
|
|
1142
|
-
const image = /* @__PURE__ */ (0,
|
|
1143
|
-
const
|
|
1144
|
-
return /* @__PURE__ */ (0,
|
|
1145
|
-
/* @__PURE__ */ (0,
|
|
1146
|
-
/* @__PURE__ */ (0,
|
|
1147
|
-
|
|
2317
|
+
const image = /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
|
|
2318
|
+
const shown2 = asset !== void 0 && (0, import_builder_schema17.safeUrl)(asset.url, "src", { mediaOrigin }) !== null;
|
|
2319
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
|
|
2320
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(BasicStyles, {}),
|
|
2321
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(WidgetStyle, { css: enumCss(node, RULES2) }),
|
|
2322
|
+
shown2 ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "tb-b-image", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("a", { href, children: image }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
|
|
1148
2323
|
] });
|
|
1149
2324
|
}
|
|
1150
2325
|
|
|
1151
2326
|
// src/basics/logo.tsx
|
|
1152
2327
|
var import_ui3 = require("@usethrottle/ui");
|
|
1153
|
-
var
|
|
1154
|
-
var
|
|
2328
|
+
var import_builder_schema18 = require("@usethrottle/builder-schema");
|
|
2329
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
1155
2330
|
function Logo({ props, mediaOrigin, editMode }) {
|
|
1156
2331
|
const design = (0, import_ui3.useSiteDesign)();
|
|
1157
2332
|
const scheme = design?.theme?.colorScheme ?? "auto";
|
|
1158
|
-
const src = (url) => url === void 0 ? void 0 : (0,
|
|
2333
|
+
const src = (url) => url === void 0 ? void 0 : (0, import_builder_schema18.safeUrl)(url, "src", { mediaOrigin }) ?? void 0;
|
|
1159
2334
|
const light = src(design?.brand?.logo?.light);
|
|
1160
2335
|
const dark = src(design?.brand?.logo?.dark);
|
|
1161
2336
|
const main = scheme === "dark" ? dark ?? light : light ?? dark;
|
|
@@ -1164,53 +2339,53 @@ function Logo({ props, mediaOrigin, editMode }) {
|
|
|
1164
2339
|
const alt = name ?? "";
|
|
1165
2340
|
let content = null;
|
|
1166
2341
|
if (main !== void 0) {
|
|
1167
|
-
const img = /* @__PURE__ */ (0,
|
|
1168
|
-
content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ (0,
|
|
1169
|
-
/* @__PURE__ */ (0,
|
|
2342
|
+
const img = /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("img", { src: main, alt, decoding: "async" });
|
|
2343
|
+
content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("picture", { children: [
|
|
2344
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
|
|
1170
2345
|
img
|
|
1171
2346
|
] }) : img;
|
|
1172
2347
|
} else if (name !== void 0) {
|
|
1173
|
-
content = /* @__PURE__ */ (0,
|
|
2348
|
+
content = /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "tb-b-logo-name", children: name });
|
|
1174
2349
|
}
|
|
1175
|
-
return /* @__PURE__ */ (0,
|
|
1176
|
-
/* @__PURE__ */ (0,
|
|
1177
|
-
content === null ? /* @__PURE__ */ (0,
|
|
2350
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2351
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BasicStyles, {}),
|
|
2352
|
+
content === null ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "tb-b-logo", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("a", { href, children: content }) })
|
|
1178
2353
|
] });
|
|
1179
2354
|
}
|
|
1180
2355
|
|
|
1181
2356
|
// src/basics/menu.tsx
|
|
1182
|
-
var
|
|
2357
|
+
var import_react12 = require("react");
|
|
1183
2358
|
var import_ui4 = require("@usethrottle/ui");
|
|
1184
|
-
var
|
|
1185
|
-
var
|
|
2359
|
+
var import_builder_schema19 = require("@usethrottle/builder-schema");
|
|
2360
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
1186
2361
|
var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
|
|
1187
|
-
var
|
|
2362
|
+
var MAX_DEPTH2 = 3;
|
|
1188
2363
|
function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
|
|
1189
|
-
const
|
|
1190
|
-
const href = (0,
|
|
2364
|
+
const shown2 = items.flatMap((item) => {
|
|
2365
|
+
const href = (0, import_builder_schema19.safeUrl)(item.href, "href", { mediaOrigin });
|
|
1191
2366
|
return href === null ? [] : [{ item, href }];
|
|
1192
2367
|
});
|
|
1193
|
-
if (
|
|
1194
|
-
return /* @__PURE__ */ (0,
|
|
1195
|
-
/* @__PURE__ */ (0,
|
|
1196
|
-
depth + 1 <
|
|
2368
|
+
if (shown2.length === 0) return null;
|
|
2369
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown2.map(({ item, href }, index) => /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("li", { children: [
|
|
2370
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href, children: item.label }),
|
|
2371
|
+
depth + 1 < MAX_DEPTH2 && item.children !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(List, { items: item.children, mediaOrigin, depth: depth + 1 })
|
|
1197
2372
|
] }, `${String(index)}:${href}`)) });
|
|
1198
2373
|
}
|
|
1199
2374
|
function Menu({ props, mediaOrigin, editMode }) {
|
|
1200
2375
|
const design = (0, import_ui4.useSiteDesign)();
|
|
1201
|
-
const listId = (0,
|
|
1202
|
-
const toggle = (0,
|
|
1203
|
-
const [open, setOpen] = (0,
|
|
2376
|
+
const listId = (0, import_react12.useId)();
|
|
2377
|
+
const toggle = (0, import_react12.useRef)(null);
|
|
2378
|
+
const [open, setOpen] = (0, import_react12.useState)(false);
|
|
1204
2379
|
const name = str(props.menu) ?? "header";
|
|
1205
2380
|
const layout = oneOf(props.layout, LAYOUTS, "horizontal");
|
|
1206
2381
|
const menus = design?.menus;
|
|
1207
2382
|
const items = menus !== void 0 && Object.hasOwn(menus, name) ? menus[name] : void 0;
|
|
1208
2383
|
const strings = design?.strings;
|
|
1209
|
-
const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ??
|
|
2384
|
+
const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? import_builder_schema19.SITE_STRING_DEFAULTS["nav.menu"];
|
|
1210
2385
|
if (items === void 0 || items.length === 0) {
|
|
1211
|
-
return /* @__PURE__ */ (0,
|
|
1212
|
-
/* @__PURE__ */ (0,
|
|
1213
|
-
/* @__PURE__ */ (0,
|
|
2386
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
|
|
2387
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(BasicStyles, {}),
|
|
2388
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
|
|
1214
2389
|
] });
|
|
1215
2390
|
}
|
|
1216
2391
|
const drawer = layout === "drawer-on-phone";
|
|
@@ -1220,9 +2395,9 @@ function Menu({ props, mediaOrigin, editMode }) {
|
|
|
1220
2395
|
toggle.current?.focus();
|
|
1221
2396
|
}
|
|
1222
2397
|
};
|
|
1223
|
-
return /* @__PURE__ */ (0,
|
|
1224
|
-
/* @__PURE__ */ (0,
|
|
1225
|
-
/* @__PURE__ */ (0,
|
|
2398
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
|
|
2399
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(BasicStyles, {}),
|
|
2400
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
1226
2401
|
"nav",
|
|
1227
2402
|
{
|
|
1228
2403
|
className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
|
|
@@ -1230,7 +2405,7 @@ function Menu({ props, mediaOrigin, editMode }) {
|
|
|
1230
2405
|
"data-open": drawer ? String(open) : void 0,
|
|
1231
2406
|
onKeyDown: drawer ? onKeyDown : void 0,
|
|
1232
2407
|
children: [
|
|
1233
|
-
drawer && /* @__PURE__ */ (0,
|
|
2408
|
+
drawer && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
1234
2409
|
"button",
|
|
1235
2410
|
{
|
|
1236
2411
|
ref: toggle,
|
|
@@ -1239,10 +2414,10 @@ function Menu({ props, mediaOrigin, editMode }) {
|
|
|
1239
2414
|
"aria-expanded": open,
|
|
1240
2415
|
"aria-controls": listId,
|
|
1241
2416
|
onClick: () => setOpen((value) => !value),
|
|
1242
|
-
children: /* @__PURE__ */ (0,
|
|
2417
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_ui4.Icon, { name: open ? "close" : "menu", size: 24, label })
|
|
1243
2418
|
}
|
|
1244
2419
|
),
|
|
1245
|
-
/* @__PURE__ */ (0,
|
|
2420
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
|
|
1246
2421
|
]
|
|
1247
2422
|
}
|
|
1248
2423
|
)
|
|
@@ -1250,18 +2425,18 @@ function Menu({ props, mediaOrigin, editMode }) {
|
|
|
1250
2425
|
}
|
|
1251
2426
|
|
|
1252
2427
|
// src/basics/spacer.tsx
|
|
1253
|
-
var
|
|
2428
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
1254
2429
|
function Spacer() {
|
|
1255
|
-
return /* @__PURE__ */ (0,
|
|
1256
|
-
/* @__PURE__ */ (0,
|
|
1257
|
-
/* @__PURE__ */ (0,
|
|
2430
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(import_jsx_runtime27.Fragment, { children: [
|
|
2431
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(BasicStyles, {}),
|
|
2432
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "tb-b-spacer", "aria-hidden": "true" })
|
|
1258
2433
|
] });
|
|
1259
2434
|
}
|
|
1260
2435
|
|
|
1261
2436
|
// src/basics/rich-text.tsx
|
|
1262
|
-
var
|
|
1263
|
-
var
|
|
1264
|
-
var
|
|
2437
|
+
var import_react13 = require("react");
|
|
2438
|
+
var import_builder_schema20 = require("@usethrottle/builder-schema");
|
|
2439
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
1265
2440
|
var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
|
|
1266
2441
|
var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
|
|
1267
2442
|
var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
@@ -1286,7 +2461,7 @@ var VOID = /* @__PURE__ */ new Set(["br"]);
|
|
|
1286
2461
|
var BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote"]);
|
|
1287
2462
|
var TEXT_BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4"]);
|
|
1288
2463
|
var MAX_LENGTH = 2e4;
|
|
1289
|
-
var
|
|
2464
|
+
var MAX_DEPTH3 = 24;
|
|
1290
2465
|
var MAX_NODES = 4e3;
|
|
1291
2466
|
var NAMED = {
|
|
1292
2467
|
amp: "&",
|
|
@@ -1430,23 +2605,23 @@ function parseRichText(source, mediaOrigin) {
|
|
|
1430
2605
|
const el = { tag: name, children: [] };
|
|
1431
2606
|
if (name === "a") {
|
|
1432
2607
|
const href = tag.attrs.get("href");
|
|
1433
|
-
el.href = href === void 0 ? null : (0,
|
|
2608
|
+
el.href = href === void 0 ? null : (0, import_builder_schema20.safeUrl)(decode(href).trim(), "href", { mediaOrigin });
|
|
1434
2609
|
}
|
|
1435
2610
|
nodes += 1;
|
|
1436
2611
|
top().children.push(el);
|
|
1437
|
-
if (!VOID.has(name) && stack.length <
|
|
2612
|
+
if (!VOID.has(name) && stack.length < MAX_DEPTH3) stack.push(el);
|
|
1438
2613
|
}
|
|
1439
2614
|
if (nodes > MAX_NODES) root.truncated = true;
|
|
1440
2615
|
return root;
|
|
1441
2616
|
}
|
|
1442
2617
|
function toReact(el, key) {
|
|
1443
2618
|
const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
|
|
1444
|
-
if (el.tag === "br") return /* @__PURE__ */ (0,
|
|
2619
|
+
if (el.tag === "br") return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("br", {}, key);
|
|
1445
2620
|
if (el.tag === "a") {
|
|
1446
|
-
if (el.href === null || el.href === void 0) return /* @__PURE__ */ (0,
|
|
1447
|
-
return /* @__PURE__ */ (0,
|
|
2621
|
+
if (el.href === null || el.href === void 0) return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_react13.Fragment, { children }, key);
|
|
2622
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
|
|
1448
2623
|
}
|
|
1449
|
-
return (0,
|
|
2624
|
+
return (0, import_react13.createElement)(el.tag, { key }, ...children);
|
|
1450
2625
|
}
|
|
1451
2626
|
function RichText({
|
|
1452
2627
|
html,
|
|
@@ -1455,26 +2630,26 @@ function RichText({
|
|
|
1455
2630
|
editMode = false
|
|
1456
2631
|
}) {
|
|
1457
2632
|
const tree = parseRichText(html, mediaOrigin);
|
|
1458
|
-
return /* @__PURE__ */ (0,
|
|
2633
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className, children: [
|
|
1459
2634
|
tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
|
|
1460
|
-
editMode && tree.truncated === true && /* @__PURE__ */ (0,
|
|
2635
|
+
editMode && tree.truncated === true && /* @__PURE__ */ (0, import_jsx_runtime28.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." })
|
|
1461
2636
|
] });
|
|
1462
2637
|
}
|
|
1463
2638
|
|
|
1464
2639
|
// src/basics/text.tsx
|
|
1465
|
-
var
|
|
2640
|
+
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
1466
2641
|
function Text({ props, mediaOrigin, editMode, inlineEdit }) {
|
|
1467
2642
|
const editor = inlineEdit?.("html") ?? null;
|
|
1468
|
-
return /* @__PURE__ */ (0,
|
|
1469
|
-
/* @__PURE__ */ (0,
|
|
1470
|
-
editor === null ? /* @__PURE__ */ (0,
|
|
2643
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [
|
|
2644
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(BasicStyles, {}),
|
|
2645
|
+
editor === null ? /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "tb-b-text", children: editor })
|
|
1471
2646
|
] });
|
|
1472
2647
|
}
|
|
1473
2648
|
|
|
1474
2649
|
// src/basics/video.tsx
|
|
1475
|
-
var
|
|
2650
|
+
var import_react14 = require("react");
|
|
1476
2651
|
var import_ui5 = require("@usethrottle/ui");
|
|
1477
|
-
var
|
|
2652
|
+
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
1478
2653
|
var RULES3 = [
|
|
1479
2654
|
{ key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
|
|
1480
2655
|
];
|
|
@@ -1514,12 +2689,12 @@ function embedSrc(video, muted) {
|
|
|
1514
2689
|
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" : ""}`;
|
|
1515
2690
|
}
|
|
1516
2691
|
function Video({ node, props, editMode }) {
|
|
1517
|
-
const [loaded, setLoaded] = (0,
|
|
2692
|
+
const [loaded, setLoaded] = (0, import_react14.useState)(false);
|
|
1518
2693
|
const video = parseVideoUrl(str(props.url) ?? "");
|
|
1519
|
-
return /* @__PURE__ */ (0,
|
|
1520
|
-
/* @__PURE__ */ (0,
|
|
1521
|
-
/* @__PURE__ */ (0,
|
|
1522
|
-
video === null ? /* @__PURE__ */ (0,
|
|
2694
|
+
return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
|
|
2695
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(BasicStyles, {}),
|
|
2696
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(WidgetStyle, { css: enumCss(node, RULES3) }),
|
|
2697
|
+
video === null ? /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
|
|
1523
2698
|
"iframe",
|
|
1524
2699
|
{
|
|
1525
2700
|
src: embedSrc(video, props.autoplayMuted === true),
|
|
@@ -1528,7 +2703,7 @@ function Video({ node, props, editMode }) {
|
|
|
1528
2703
|
referrerPolicy: "strict-origin-when-cross-origin",
|
|
1529
2704
|
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
|
|
1530
2705
|
}
|
|
1531
|
-
) : /* @__PURE__ */ (0,
|
|
2706
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_ui5.Icon, { name: "play", size: 28 }) }) }) })
|
|
1532
2707
|
] });
|
|
1533
2708
|
}
|
|
1534
2709
|
|
|
@@ -1544,289 +2719,39 @@ var BASIC_COMPONENTS = {
|
|
|
1544
2719
|
"basic.logo": Logo,
|
|
1545
2720
|
"basic.menu": Menu,
|
|
1546
2721
|
"basic.announcement": Announcement,
|
|
1547
|
-
"basic.copyright": Copyright
|
|
2722
|
+
"basic.copyright": Copyright,
|
|
2723
|
+
"basic.countdown": Countdown
|
|
1548
2724
|
};
|
|
1549
|
-
var widgets =
|
|
2725
|
+
var widgets = import_builder_schema21.BASIC_WIDGET_DEFINITIONS.flatMap(
|
|
1550
2726
|
(definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
|
|
1551
2727
|
);
|
|
1552
2728
|
var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
|
|
1553
2729
|
|
|
1554
2730
|
// src/custom/factory.ts
|
|
1555
|
-
var
|
|
1556
|
-
|
|
1557
|
-
// src/custom/composite-widget.tsx
|
|
1558
|
-
var import_react12 = require("react");
|
|
1559
|
-
var import_builder_schema19 = require("@usethrottle/builder-schema");
|
|
1560
|
-
|
|
1561
|
-
// src/custom/template-widget.tsx
|
|
1562
|
-
var import_react11 = require("react");
|
|
1563
|
-
var import_builder_schema18 = require("@usethrottle/builder-schema");
|
|
1564
|
-
|
|
1565
|
-
// src/custom/custom-css.tsx
|
|
1566
|
-
var import_builder_schema16 = require("@usethrottle/builder-schema");
|
|
1567
|
-
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
1568
|
-
function scopedCss(source, type) {
|
|
1569
|
-
if (source === void 0 || source === "") return "";
|
|
1570
|
-
if (typeof source !== "string") return null;
|
|
1571
|
-
const result = (0, import_builder_schema16.sanitizeWidgetCss)(source, type);
|
|
1572
|
-
return result.ok ? result.css : null;
|
|
1573
|
-
}
|
|
1574
|
-
function CustomCss({ css }) {
|
|
1575
|
-
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(WidgetStyle, { css });
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
// src/custom/interpreter.tsx
|
|
1579
|
-
var import_react10 = require("react");
|
|
1580
|
-
var import_builder_schema17 = require("@usethrottle/builder-schema");
|
|
1581
|
-
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
1582
|
-
var MAX_OUTPUT_CHARS = 1e6;
|
|
1583
|
-
var MAX_ATTR_CHARS = 2e3;
|
|
1584
|
-
var MAX_DEPTH3 = 24;
|
|
1585
|
-
function newEnv(env) {
|
|
1586
|
-
return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
|
|
1587
|
-
}
|
|
1588
|
-
var BLOCKED = /* @__PURE__ */ new Set([
|
|
1589
|
-
"__proto__",
|
|
1590
|
-
"constructor",
|
|
1591
|
-
"prototype",
|
|
1592
|
-
...Object.getOwnPropertyNames(Object.prototype)
|
|
1593
|
-
]);
|
|
1594
|
-
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1595
|
-
function step(value, key) {
|
|
1596
|
-
if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
|
|
1597
|
-
return value[key];
|
|
1598
|
-
}
|
|
1599
|
-
function lookup(path, env, scope) {
|
|
1600
|
-
const [root, ...rest] = path;
|
|
1601
|
-
if (root === void 0) return void 0;
|
|
1602
|
-
if (root === "locale") return rest.length === 0 ? env.locale : void 0;
|
|
1603
|
-
let value;
|
|
1604
|
-
if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
|
|
1605
|
-
else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
|
|
1606
|
-
else if (scope.has(root)) value = scope.get(root);
|
|
1607
|
-
else return void 0;
|
|
1608
|
-
for (const key of rest) {
|
|
1609
|
-
value = step(value, key);
|
|
1610
|
-
if (value === void 0) return void 0;
|
|
1611
|
-
}
|
|
1612
|
-
return value;
|
|
1613
|
-
}
|
|
1614
|
-
function truthy(value) {
|
|
1615
|
-
if (value === null || value === void 0 || value === false || value === "") return false;
|
|
1616
|
-
if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
|
|
1617
|
-
if (Array.isArray(value)) return value.length > 0;
|
|
1618
|
-
return true;
|
|
1619
|
-
}
|
|
1620
|
-
function asText(value) {
|
|
1621
|
-
if (typeof value === "string") return value;
|
|
1622
|
-
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
1623
|
-
return "";
|
|
1624
|
-
}
|
|
1625
|
-
function filtered(value, filters) {
|
|
1626
|
-
let text = asText(value);
|
|
1627
|
-
for (const filter of filters) {
|
|
1628
|
-
switch (filter.name) {
|
|
1629
|
-
case "upper":
|
|
1630
|
-
text = text.toUpperCase();
|
|
1631
|
-
break;
|
|
1632
|
-
case "lower":
|
|
1633
|
-
text = text.toLowerCase();
|
|
1634
|
-
break;
|
|
1635
|
-
case "truncate": {
|
|
1636
|
-
const chars = Array.from(text);
|
|
1637
|
-
if (chars.length > filter.n) text = `${chars.slice(0, filter.n).join("")}\u2026`;
|
|
1638
|
-
break;
|
|
1639
|
-
}
|
|
1640
|
-
case "default":
|
|
1641
|
-
if (text === "") text = filter.text;
|
|
1642
|
-
break;
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return text;
|
|
1646
|
-
}
|
|
1647
|
-
function spend(env, count) {
|
|
1648
|
-
if (count > env.charsLeft) {
|
|
1649
|
-
env.stopped = true;
|
|
1650
|
-
return false;
|
|
1651
|
-
}
|
|
1652
|
-
env.charsLeft -= count;
|
|
1653
|
-
return true;
|
|
1654
|
-
}
|
|
1655
|
-
var ELEMENTS = new Set(import_builder_schema17.ALLOWED_ELEMENTS);
|
|
1656
|
-
var VOIDS = new Set(import_builder_schema17.VOID_ELEMENTS);
|
|
1657
|
-
var ROLES = new Set(import_builder_schema17.ALLOWED_ROLES);
|
|
1658
|
-
function attrAllowed(tag, name) {
|
|
1659
|
-
if (import_builder_schema17.DATA_ATTR_RE.test(name)) return !name.startsWith(import_builder_schema17.RESERVED_DATA_PREFIX);
|
|
1660
|
-
const own = Object.hasOwn(import_builder_schema17.ALLOWED_ATTRS, tag) ? import_builder_schema17.ALLOWED_ATTRS[tag] : void 0;
|
|
1661
|
-
return (import_builder_schema17.ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
|
|
1662
|
-
}
|
|
1663
|
-
function attrText(attr, env, scope) {
|
|
1664
|
-
return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
|
|
1665
|
-
}
|
|
1666
|
-
function urlSource(attr, env, scope) {
|
|
1667
|
-
const [only] = attr.value;
|
|
1668
|
-
if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
|
|
1669
|
-
const value = lookup(only.path, env, scope);
|
|
1670
|
-
if (isPlainObject(value)) {
|
|
1671
|
-
if (typeof value.href === "string") return value.href;
|
|
1672
|
-
if (typeof value.url === "string") return value.url;
|
|
1673
|
-
return null;
|
|
1674
|
-
}
|
|
1675
|
-
return value;
|
|
1676
|
-
}
|
|
1677
|
-
function attrProp(tag, attr, env, scope) {
|
|
1678
|
-
const { name } = attr;
|
|
1679
|
-
if (!attrAllowed(tag, name)) return null;
|
|
1680
|
-
if (name === "href" || name === "src") {
|
|
1681
|
-
const safe = (0, import_builder_schema17.safeUrl)(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
|
|
1682
|
-
return safe === null || !spend(env, safe.length) ? null : [name, safe];
|
|
1683
|
-
}
|
|
1684
|
-
const text = attrText(attr, env, scope);
|
|
1685
|
-
if (text === "" || text.length > MAX_ATTR_CHARS) return null;
|
|
1686
|
-
let value = text;
|
|
1687
|
-
if (name === "class") {
|
|
1688
|
-
const tokens = text.split(/\s+/).filter((token) => import_builder_schema17.CLASS_TOKEN_RE.test(token) && !(0, import_builder_schema17.isReservedClass)(token));
|
|
1689
|
-
if (tokens.length === 0) return null;
|
|
1690
|
-
value = tokens.join(" ");
|
|
1691
|
-
} else if (name === "role") {
|
|
1692
|
-
if (!ROLES.has(text)) return null;
|
|
1693
|
-
} else if (name === "aria-hidden") {
|
|
1694
|
-
if (text !== "true" && text !== "false") return null;
|
|
1695
|
-
}
|
|
1696
|
-
if (!spend(env, value.length)) return null;
|
|
1697
|
-
return [name === "class" ? "className" : name, value];
|
|
1698
|
-
}
|
|
1699
|
-
function renderElement(node, env, scope, depth, key) {
|
|
1700
|
-
const tag = node.tag;
|
|
1701
|
-
if (!ELEMENTS.has(tag)) return null;
|
|
1702
|
-
const props = { key };
|
|
1703
|
-
for (const attr of node.attrs) {
|
|
1704
|
-
const prop = attrProp(tag, attr, env, scope);
|
|
1705
|
-
if (prop !== null) props[prop[0]] = prop[1];
|
|
1706
|
-
}
|
|
1707
|
-
if (VOIDS.has(tag)) return (0, import_react10.createElement)(tag, props);
|
|
1708
|
-
return (0, import_react10.createElement)(tag, props, renderNodes(node.children, env, scope, depth + 1));
|
|
1709
|
-
}
|
|
1710
|
-
function renderNodes(nodes, env, scope, depth) {
|
|
1711
|
-
const out = [];
|
|
1712
|
-
if (depth > MAX_DEPTH3) return out;
|
|
1713
|
-
for (const node of nodes) {
|
|
1714
|
-
if (env.stopped) break;
|
|
1715
|
-
if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
|
|
1716
|
-
env.stopped = true;
|
|
1717
|
-
break;
|
|
1718
|
-
}
|
|
1719
|
-
switch (node.type) {
|
|
1720
|
-
case "text":
|
|
1721
|
-
if (spend(env, node.value.length)) out.push(node.value);
|
|
1722
|
-
break;
|
|
1723
|
-
case "output": {
|
|
1724
|
-
const text = filtered(lookup(node.path, env, scope), node.filters);
|
|
1725
|
-
if (text !== "" && spend(env, text.length)) out.push(text);
|
|
1726
|
-
break;
|
|
1727
|
-
}
|
|
1728
|
-
case "if": {
|
|
1729
|
-
const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
|
|
1730
|
-
out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
|
|
1731
|
-
break;
|
|
1732
|
-
}
|
|
1733
|
-
case "unless":
|
|
1734
|
-
if (!truthy(lookup(node.path, env, scope))) {
|
|
1735
|
-
out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
|
|
1736
|
-
}
|
|
1737
|
-
break;
|
|
1738
|
-
case "each": {
|
|
1739
|
-
const list = lookup(node.path, env, scope);
|
|
1740
|
-
if (!Array.isArray(list)) break;
|
|
1741
|
-
const count = Math.min(list.length, import_builder_schema17.EACH_ITERATION_CAP);
|
|
1742
|
-
for (let i = 0; i < count && !env.stopped; i += 1) {
|
|
1743
|
-
const inner = new Map(scope).set(node.as, list[i]);
|
|
1744
|
-
out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
|
|
1745
|
-
}
|
|
1746
|
-
break;
|
|
1747
|
-
}
|
|
1748
|
-
case "element":
|
|
1749
|
-
out.push(renderElement(node, env, scope, depth, out.length));
|
|
1750
|
-
break;
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
return out;
|
|
1754
|
-
}
|
|
1755
|
-
function renderTemplate(ast, env) {
|
|
1756
|
-
return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
// src/custom/template-widget.tsx
|
|
1760
|
-
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
1761
|
-
var componentWeights = /* @__PURE__ */ new WeakMap();
|
|
1762
|
-
var compiled = /* @__PURE__ */ new WeakMap();
|
|
1763
|
-
function compileTemplate(snapshot, registry) {
|
|
1764
|
-
let perRegistry = compiled.get(snapshot);
|
|
1765
|
-
if (perRegistry === void 0) {
|
|
1766
|
-
perRegistry = /* @__PURE__ */ new WeakMap();
|
|
1767
|
-
compiled.set(snapshot, perRegistry);
|
|
1768
|
-
}
|
|
1769
|
-
if (perRegistry.has(registry)) return perRegistry.get(registry) ?? null;
|
|
1770
|
-
const result = compile(snapshot, registry);
|
|
1771
|
-
perRegistry.set(registry, result);
|
|
1772
|
-
return result;
|
|
1773
|
-
}
|
|
1774
|
-
function compile(snapshot, registry) {
|
|
1775
|
-
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
1776
|
-
const refuse = (why) => {
|
|
1777
|
-
warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
1778
|
-
return null;
|
|
1779
|
-
};
|
|
1780
|
-
if (snapshot.kind !== "template") return refuse("not a template widget");
|
|
1781
|
-
const source = snapshot.template;
|
|
1782
|
-
if (typeof source !== "string") return refuse("no template source");
|
|
1783
|
-
const parsed = (0, import_builder_schema18.parseTemplate)(source);
|
|
1784
|
-
if (!parsed.ok) return refuse(`template does not parse: ${parsed.issues[0]?.message ?? "invalid"}`);
|
|
1785
|
-
const data = snapshot.data;
|
|
1786
|
-
const issues = (0, import_builder_schema18.validateTemplate)(parsed.ast, {
|
|
1787
|
-
settings: snapshot.settings,
|
|
1788
|
-
data: typeof data === "object" && data !== null ? data : {},
|
|
1789
|
-
sources: registry.sources()
|
|
1790
|
-
});
|
|
1791
|
-
if (issues.length > 0) return refuse(`template does not validate: ${issues[0]?.message ?? "invalid"}`);
|
|
1792
|
-
if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(import_builder_schema18.MAX_TEMPLATE_WEIGHT)} nodes`);
|
|
1793
|
-
const css = scopedCss(snapshot.css, snapshot.type);
|
|
1794
|
-
if (css === null) return refuse("its css does not pass the sanitiser");
|
|
1795
|
-
return { ast: parsed.ast, css, weight: (0, import_builder_schema18.templateWeight)(parsed.ast) };
|
|
1796
|
-
}
|
|
1797
|
-
function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
|
|
1798
|
-
const template = compileTemplate(snapshot, registry);
|
|
1799
|
-
if (template === null) return null;
|
|
1800
|
-
const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
|
|
1801
|
-
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
|
|
1802
|
-
template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CustomCss, { css: template.css }),
|
|
1803
|
-
renderTemplate(template.ast, env)
|
|
1804
|
-
] });
|
|
1805
|
-
}
|
|
1806
|
-
function TemplateWidget(props) {
|
|
1807
|
-
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 }) }) });
|
|
1808
|
-
}
|
|
2731
|
+
var import_react16 = require("react");
|
|
1809
2732
|
|
|
1810
2733
|
// src/custom/composite-widget.tsx
|
|
1811
|
-
var
|
|
2734
|
+
var import_react15 = require("react");
|
|
2735
|
+
var import_builder_schema22 = require("@usethrottle/builder-schema");
|
|
2736
|
+
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
1812
2737
|
var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
|
|
1813
2738
|
var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
|
|
1814
2739
|
var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
|
|
1815
|
-
var
|
|
1816
|
-
var
|
|
2740
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2741
|
+
var compiled3 = /* @__PURE__ */ new WeakMap();
|
|
1817
2742
|
function parseBody(raw) {
|
|
1818
|
-
if (!
|
|
2743
|
+
if (!isRecord4(raw)) return null;
|
|
1819
2744
|
const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
|
|
1820
2745
|
const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
|
|
1821
2746
|
if (columns === void 0 === (stack === void 0)) return null;
|
|
1822
2747
|
const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : stack ?? [];
|
|
1823
|
-
if (stack?.some((node) =>
|
|
1824
|
-
const
|
|
2748
|
+
if (stack?.some((node) => isRecord4(node) && node.type === "inner-section")) return null;
|
|
2749
|
+
const parsed2 = import_builder_schema22.pageDocumentSchema.safeParse({
|
|
1825
2750
|
schemaVersion: 1,
|
|
1826
2751
|
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1827
2752
|
});
|
|
1828
|
-
if (!
|
|
1829
|
-
const wrapper =
|
|
2753
|
+
if (!parsed2.success) return null;
|
|
2754
|
+
const wrapper = parsed2.data.sections[0];
|
|
1830
2755
|
const first = (wrapper?.type === "section" ? wrapper.columns[0]?.children : void 0) ?? [];
|
|
1831
2756
|
if (columns !== void 0) {
|
|
1832
2757
|
const inner = first[0];
|
|
@@ -1835,9 +2760,9 @@ function parseBody(raw) {
|
|
|
1835
2760
|
return { stack: first.filter((node) => node.type !== "inner-section") };
|
|
1836
2761
|
}
|
|
1837
2762
|
function compileComposite(snapshot) {
|
|
1838
|
-
if (
|
|
2763
|
+
if (compiled3.has(snapshot)) return compiled3.get(snapshot) ?? null;
|
|
1839
2764
|
const result = compile2(snapshot);
|
|
1840
|
-
|
|
2765
|
+
compiled3.set(snapshot, result);
|
|
1841
2766
|
return result;
|
|
1842
2767
|
}
|
|
1843
2768
|
function compile2(snapshot) {
|
|
@@ -1853,12 +2778,12 @@ function compile2(snapshot) {
|
|
|
1853
2778
|
const bindings = [];
|
|
1854
2779
|
if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
|
|
1855
2780
|
for (const raw of extra.bindings ?? []) {
|
|
1856
|
-
if (!
|
|
2781
|
+
if (!isRecord4(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
|
|
1857
2782
|
return refuse("a binding is malformed");
|
|
1858
2783
|
}
|
|
1859
2784
|
const targets = [];
|
|
1860
2785
|
for (const target of raw.targets) {
|
|
1861
|
-
if (!
|
|
2786
|
+
if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
|
|
1862
2787
|
return refuse("a binding target is malformed");
|
|
1863
2788
|
}
|
|
1864
2789
|
targets.push({ node: target.node, prop: target.prop });
|
|
@@ -1866,12 +2791,12 @@ function compile2(snapshot) {
|
|
|
1866
2791
|
bindings.push({ setting: raw.setting, targets });
|
|
1867
2792
|
}
|
|
1868
2793
|
const data = [];
|
|
1869
|
-
if (extra.data !== void 0 && !
|
|
2794
|
+
if (extra.data !== void 0 && !isRecord4(extra.data)) return refuse("data is not a record");
|
|
1870
2795
|
for (const [name, raw] of Object.entries(extra.data ?? {})) {
|
|
1871
|
-
if (!SETTING_KEY_RE.test(name) || !
|
|
2796
|
+
if (!SETTING_KEY_RE.test(name) || !isRecord4(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
|
|
1872
2797
|
const targets = [];
|
|
1873
2798
|
for (const target of raw.targets) {
|
|
1874
|
-
if (!
|
|
2799
|
+
if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
|
|
1875
2800
|
return refuse("a data target is malformed");
|
|
1876
2801
|
}
|
|
1877
2802
|
targets.push({ node: target.node, input: target.input });
|
|
@@ -1927,7 +2852,7 @@ function build(input) {
|
|
|
1927
2852
|
return id;
|
|
1928
2853
|
}
|
|
1929
2854
|
if (field.control === "link") {
|
|
1930
|
-
if (!
|
|
2855
|
+
if (!isRecord4(value) || typeof value.kind !== "string") return null;
|
|
1931
2856
|
const { href, ...target } = value;
|
|
1932
2857
|
if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
|
|
1933
2858
|
hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
|
|
@@ -1944,14 +2869,14 @@ function build(input) {
|
|
|
1944
2869
|
const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target.prop);
|
|
1945
2870
|
if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
|
|
1946
2871
|
const converted = convert(field, value);
|
|
1947
|
-
if ((0,
|
|
2872
|
+
if ((0, import_builder_schema22.validateSettingValue)(innerField, converted) !== null) continue;
|
|
1948
2873
|
inner.props[target.prop] = converted;
|
|
1949
2874
|
const responsive = inner.responsive;
|
|
1950
2875
|
for (const device of DEVICES3) {
|
|
1951
2876
|
if (responsive?.[device] !== void 0) delete responsive[device][target.prop];
|
|
1952
2877
|
const raw = outer.responsive?.[device];
|
|
1953
2878
|
const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
|
|
1954
|
-
if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && (0,
|
|
2879
|
+
if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && (0, import_builder_schema22.validateSettingValue)(innerField, raw[binding.setting]) === null) {
|
|
1955
2880
|
const target$ = inner.responsive ?? (inner.responsive = {});
|
|
1956
2881
|
(target$[device] ?? (target$[device] = {}))[target.prop] = raw[binding.setting];
|
|
1957
2882
|
}
|
|
@@ -1978,7 +2903,7 @@ function build(input) {
|
|
|
1978
2903
|
props: { width: 100 },
|
|
1979
2904
|
children: columns !== void 0 ? [{ id: ids.inner, type: "inner-section", props: { width: "full" }, columns }] : stack ?? []
|
|
1980
2905
|
};
|
|
1981
|
-
const
|
|
2906
|
+
const document2 = {
|
|
1982
2907
|
schemaVersion: 1,
|
|
1983
2908
|
sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
|
|
1984
2909
|
};
|
|
@@ -1987,10 +2912,10 @@ function build(input) {
|
|
|
1987
2912
|
const component = registry.component(widget);
|
|
1988
2913
|
weight += 1 + (component === void 0 ? 0 : componentWeights.get(component) ?? 0);
|
|
1989
2914
|
}
|
|
1990
|
-
return { document, assets, data: innerData, hrefs, weight };
|
|
2915
|
+
return { document: document2, assets, data: innerData, hrefs, weight };
|
|
1991
2916
|
}
|
|
1992
2917
|
function CompositeBody(props) {
|
|
1993
|
-
const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink } = props;
|
|
2918
|
+
const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink, interactive, idScope } = props;
|
|
1994
2919
|
const composite = compileComposite(snapshot);
|
|
1995
2920
|
if (composite === null) return null;
|
|
1996
2921
|
const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
|
|
@@ -1998,7 +2923,7 @@ function CompositeBody(props) {
|
|
|
1998
2923
|
warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
|
|
1999
2924
|
return null;
|
|
2000
2925
|
}
|
|
2001
|
-
return /* @__PURE__ */ (0,
|
|
2926
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
|
|
2002
2927
|
BuilderRenderer,
|
|
2003
2928
|
{
|
|
2004
2929
|
document: built.document,
|
|
@@ -2007,28 +2932,30 @@ function CompositeBody(props) {
|
|
|
2007
2932
|
locale,
|
|
2008
2933
|
assets: built.assets,
|
|
2009
2934
|
mediaOrigin,
|
|
2935
|
+
interactive,
|
|
2936
|
+
idScope,
|
|
2010
2937
|
resolveLink: (target) => built.hrefs.get(JSON.stringify(target)) ?? resolveLink?.(target) ?? null
|
|
2011
2938
|
}
|
|
2012
2939
|
);
|
|
2013
2940
|
}
|
|
2014
2941
|
function CompositeWidget(props) {
|
|
2015
|
-
return /* @__PURE__ */ (0,
|
|
2942
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_react15.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(CompositeBody, { ...props }) }) });
|
|
2016
2943
|
}
|
|
2017
2944
|
|
|
2018
2945
|
// src/custom/factory.ts
|
|
2019
2946
|
var isDisabled = (snapshot) => snapshot.status === "disabled";
|
|
2020
|
-
var Disabled = ({ editMode }) => editMode ? (0,
|
|
2947
|
+
var Disabled = ({ editMode }) => editMode ? (0, import_react16.createElement)("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
|
|
2021
2948
|
var customWidgetFactory = (snapshot, registry) => {
|
|
2022
2949
|
if (isDisabled(snapshot)) return Disabled;
|
|
2023
2950
|
if (snapshot.kind === "template") {
|
|
2024
2951
|
const template = compileTemplate(snapshot, registry);
|
|
2025
2952
|
if (template === null) return null;
|
|
2026
|
-
const Component2 = (props) => (0,
|
|
2953
|
+
const Component2 = (props) => (0, import_react16.createElement)(TemplateWidget, { ...props, snapshot, registry });
|
|
2027
2954
|
componentWeights.set(Component2, template.weight);
|
|
2028
2955
|
return Component2;
|
|
2029
2956
|
}
|
|
2030
2957
|
if (compileComposite(snapshot) === null) return null;
|
|
2031
|
-
return (props) => (0,
|
|
2958
|
+
return (props) => (0, import_react16.createElement)(CompositeWidget, { ...props, snapshot, registry });
|
|
2032
2959
|
};
|
|
2033
2960
|
|
|
2034
2961
|
// src/registry.ts
|
|
@@ -2036,12 +2963,12 @@ var BUILTIN_PACKS = [basicPack];
|
|
|
2036
2963
|
var DEFAULT_CUSTOM_WIDGET = customWidgetFactory;
|
|
2037
2964
|
var customKey = (type, v) => `${type}@${String(v)}`;
|
|
2038
2965
|
function createRendererRegistry(packs, options = {}) {
|
|
2039
|
-
const
|
|
2966
|
+
const all2 = [...BUILTIN_PACKS, ...packs];
|
|
2040
2967
|
const components = /* @__PURE__ */ new Map();
|
|
2041
2968
|
const definitions = [];
|
|
2042
2969
|
const sources = [];
|
|
2043
2970
|
const resolvers = /* @__PURE__ */ new Map();
|
|
2044
|
-
for (const pack of
|
|
2971
|
+
for (const pack of all2) {
|
|
2045
2972
|
for (const { Component: Component2, ...definition } of pack.widgets) {
|
|
2046
2973
|
const key = customKey(definition.type, definition.v);
|
|
2047
2974
|
if (components.has(key)) continue;
|
|
@@ -2056,7 +2983,7 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
2056
2983
|
}
|
|
2057
2984
|
const factory = options.customWidget ?? DEFAULT_CUSTOM_WIDGET;
|
|
2058
2985
|
const build2 = (custom) => {
|
|
2059
|
-
const schema = (0,
|
|
2986
|
+
const schema = (0, import_builder_schema23.createRegistry)(definitions, sources, custom);
|
|
2060
2987
|
const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
|
|
2061
2988
|
const built = /* @__PURE__ */ new Map();
|
|
2062
2989
|
const registry = {
|
|
@@ -2072,7 +2999,7 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
2072
2999
|
if (own !== void 0) return own;
|
|
2073
3000
|
if (!node.type.startsWith("custom.") || factory === void 0) return void 0;
|
|
2074
3001
|
const snapshot = snapshots.get(key);
|
|
2075
|
-
if (snapshot === void 0) return void 0;
|
|
3002
|
+
if (snapshot === void 0 || snapshot.kind === "code") return void 0;
|
|
2076
3003
|
if (!built.has(key)) built.set(key, factory(snapshot, registry));
|
|
2077
3004
|
return built.get(key) ?? void 0;
|
|
2078
3005
|
},
|
|
@@ -2084,8 +3011,8 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
2084
3011
|
}
|
|
2085
3012
|
|
|
2086
3013
|
// src/slot.tsx
|
|
2087
|
-
var
|
|
2088
|
-
var
|
|
3014
|
+
var import_react17 = require("react");
|
|
3015
|
+
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
2089
3016
|
function contextKey(context) {
|
|
2090
3017
|
if (typeof context !== "object" || context === null) return "";
|
|
2091
3018
|
return Object.values(context).map((value) => {
|
|
@@ -2101,20 +3028,20 @@ function BuilderSlot({ name, context }) {
|
|
|
2101
3028
|
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2102
3029
|
return (
|
|
2103
3030
|
// Suspense inside the boundary: see parts.tsx.
|
|
2104
|
-
/* @__PURE__ */ (0,
|
|
3031
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(PartBoundary, { label: `Builder slot ${name}`, resetKey: contextKey(context), children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_react17.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(PartView, { part, context }) }) }) })
|
|
2105
3032
|
);
|
|
2106
3033
|
}
|
|
2107
3034
|
|
|
2108
3035
|
// src/theme.ts
|
|
2109
|
-
var
|
|
3036
|
+
var import_builder_schema24 = require("@usethrottle/builder-schema");
|
|
2110
3037
|
var import_presets = require("@usethrottle/ui/presets");
|
|
2111
|
-
var
|
|
3038
|
+
var isRecord5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2112
3039
|
var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
2113
3040
|
var HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
2114
3041
|
var SCALE = { compact: 0.85, comfortable: 1, roomy: 1.25 };
|
|
2115
3042
|
var PALETTE_KEYS = Object.keys(import_presets.PRESET_TOKENS.clean.light);
|
|
2116
3043
|
function palette(base, over) {
|
|
2117
|
-
if (!
|
|
3044
|
+
if (!isRecord5(over)) return base;
|
|
2118
3045
|
const out = { ...base };
|
|
2119
3046
|
for (const key of PALETTE_KEYS) {
|
|
2120
3047
|
const value = over[key];
|
|
@@ -2123,13 +3050,13 @@ function palette(base, over) {
|
|
|
2123
3050
|
return out;
|
|
2124
3051
|
}
|
|
2125
3052
|
function themeTokens(settings) {
|
|
2126
|
-
const theme =
|
|
3053
|
+
const theme = isRecord5(settings.theme) ? settings.theme : {};
|
|
2127
3054
|
const preset = import_presets.PRESET_NAMES.includes(theme.preset) ? theme.preset : "clean";
|
|
2128
3055
|
const customized = theme.customized === true;
|
|
2129
3056
|
const base = import_presets.PRESET_TOKENS[preset];
|
|
2130
3057
|
const colorScheme = theme.colorScheme === "light" || theme.colorScheme === "dark" ? theme.colorScheme : "auto";
|
|
2131
3058
|
if (!customized) return { preset, customized, tokens: base, colorScheme };
|
|
2132
|
-
const fonts =
|
|
3059
|
+
const fonts = isRecord5(theme.fonts) ? theme.fonts : {};
|
|
2133
3060
|
return {
|
|
2134
3061
|
preset,
|
|
2135
3062
|
customized,
|
|
@@ -2155,7 +3082,7 @@ var SYSTEM_STACK = {
|
|
|
2155
3082
|
};
|
|
2156
3083
|
function fontStack(family) {
|
|
2157
3084
|
if (Object.hasOwn(SYSTEM_STACK, family)) return SYSTEM_STACK[family];
|
|
2158
|
-
const known =
|
|
3085
|
+
const known = import_builder_schema24.SITE_FONTS.find((f) => f.family === family);
|
|
2159
3086
|
if (known === void 0 || !/^[A-Za-z0-9 ]{1,60}$/.test(family)) return SYSTEM_STACK["system-sans"];
|
|
2160
3087
|
return `"${family}", ${Object.hasOwn(GENERIC, known.category) ? GENERIC[known.category] : "sans-serif"}`;
|
|
2161
3088
|
}
|
|
@@ -2199,20 +3126,30 @@ function themeCss(settings) {
|
|
|
2199
3126
|
if (colorScheme === "dark") return `${light}:root{${dark}}`;
|
|
2200
3127
|
return `${light}@media (prefers-color-scheme:dark){:root{${dark}}}`;
|
|
2201
3128
|
}
|
|
3129
|
+
function customCssOf(settings) {
|
|
3130
|
+
const theme = isRecord5(settings.theme) ? settings.theme : {};
|
|
3131
|
+
const css = theme.customCss;
|
|
3132
|
+
if (typeof css !== "string" || css.trim() === "" || css.length > import_builder_schema24.THEME_CSS_MAX_CHARS) return "";
|
|
3133
|
+
const result = (0, import_builder_schema24.sanitizeThemeCss)(css);
|
|
3134
|
+
return result.ok ? result.css : "";
|
|
3135
|
+
}
|
|
3136
|
+
function customCssSheet(css) {
|
|
3137
|
+
return css === "" ? "" : `@layer throttle,throttle-custom;@layer throttle-custom{${css}}`;
|
|
3138
|
+
}
|
|
2202
3139
|
function makeResolveLink(settings, packs) {
|
|
2203
|
-
const routes =
|
|
3140
|
+
const routes = isRecord5(settings.routes) ? settings.routes : {};
|
|
2204
3141
|
const pageRoute = str2(routes.page) ?? "/pages/{handle}";
|
|
2205
3142
|
return (target) => {
|
|
2206
3143
|
for (const pack of packs) {
|
|
2207
3144
|
const href = pack.linkTargets?.resolve(target) ?? null;
|
|
2208
|
-
if (href !== null) return (0,
|
|
3145
|
+
if (href !== null) return (0, import_builder_schema24.safeUrl)(href, "href", { mediaOrigin: "" });
|
|
2209
3146
|
}
|
|
2210
|
-
if (target.kind === "url") return (0,
|
|
2211
|
-
if (typeof target.href === "string") return (0,
|
|
3147
|
+
if (target.kind === "url") return (0, import_builder_schema24.safeUrl)(target.href, "href", { mediaOrigin: "" });
|
|
3148
|
+
if (typeof target.href === "string") return (0, import_builder_schema24.safeUrl)(target.href, "href", { mediaOrigin: "" });
|
|
2212
3149
|
if (target.kind === "page") {
|
|
2213
3150
|
const slug = str2(target.slug) ?? str2(target.handle);
|
|
2214
3151
|
if (slug !== void 0 && /^[A-Za-z0-9._~-]{1,200}$/.test(slug)) {
|
|
2215
|
-
return (0,
|
|
3152
|
+
return (0, import_builder_schema24.safeUrl)(pageRoute.replace("{handle}", slug), "href", { mediaOrigin: "" });
|
|
2216
3153
|
}
|
|
2217
3154
|
}
|
|
2218
3155
|
return null;
|
|
@@ -2223,7 +3160,7 @@ function menuItems(items, resolve, depth = 0) {
|
|
|
2223
3160
|
if (!Array.isArray(items) || depth > 3) return [];
|
|
2224
3161
|
const out = [];
|
|
2225
3162
|
for (const item of items) {
|
|
2226
|
-
if (!
|
|
3163
|
+
if (!isRecord5(item) || !isRecord5(item.target) || typeof item.target.kind !== "string") continue;
|
|
2227
3164
|
const label = str2(item.label);
|
|
2228
3165
|
const href = resolve(item.target);
|
|
2229
3166
|
if (label === void 0 || href === null) continue;
|
|
@@ -2239,24 +3176,24 @@ function menuItems(items, resolve, depth = 0) {
|
|
|
2239
3176
|
return out;
|
|
2240
3177
|
}
|
|
2241
3178
|
var assetUrl = (v, mediaOrigin) => {
|
|
2242
|
-
const raw = typeof v === "string" ? v :
|
|
2243
|
-
return typeof raw === "string" ? (0,
|
|
3179
|
+
const raw = typeof v === "string" ? v : isRecord5(v) ? v.url : void 0;
|
|
3180
|
+
return typeof raw === "string" ? (0, import_builder_schema24.safeUrl)(raw, "src", { mediaOrigin }) ?? void 0 : void 0;
|
|
2244
3181
|
};
|
|
2245
3182
|
function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
|
|
2246
3183
|
const { preset, customized, tokens, colorScheme } = themeTokens(settings);
|
|
2247
|
-
const brand =
|
|
2248
|
-
const logo =
|
|
3184
|
+
const brand = isRecord5(settings.brand) ? settings.brand : {};
|
|
3185
|
+
const logo = isRecord5(brand.logo) ? brand.logo : {};
|
|
2249
3186
|
const light = assetUrl(logo.light, mediaOrigin);
|
|
2250
3187
|
const dark = assetUrl(logo.dark, mediaOrigin);
|
|
2251
3188
|
const favicon = assetUrl(brand.favicon, mediaOrigin);
|
|
2252
|
-
const menus =
|
|
2253
|
-
const announcement =
|
|
3189
|
+
const menus = isRecord5(settings.menus) ? Object.fromEntries(Object.entries(settings.menus).map(([name, items]) => [name, menuItems(items, resolve)])) : {};
|
|
3190
|
+
const announcement = isRecord5(settings.announcement) ? settings.announcement : null;
|
|
2254
3191
|
const message = announcement === null ? void 0 : str2(announcement.message);
|
|
2255
|
-
const announcementHref = announcement !== null &&
|
|
2256
|
-
const strings =
|
|
2257
|
-
const seo =
|
|
2258
|
-
const routes =
|
|
2259
|
-
const connections =
|
|
3192
|
+
const announcementHref = announcement !== null && isRecord5(announcement.target) && typeof announcement.target.kind === "string" ? resolve(announcement.target) : null;
|
|
3193
|
+
const strings = isRecord5(settings.strings) ? Object.fromEntries(Object.entries(settings.strings).filter((entry) => typeof entry[1] === "string")) : {};
|
|
3194
|
+
const seo = isRecord5(settings.seo) ? settings.seo : {};
|
|
3195
|
+
const routes = isRecord5(settings.routes) ? settings.routes : {};
|
|
3196
|
+
const connections = isRecord5(settings.connections) ? settings.connections : {};
|
|
2260
3197
|
const shareImage = assetUrl(seo.shareImage, mediaOrigin);
|
|
2261
3198
|
const titleTemplate = str2(seo.titleTemplate);
|
|
2262
3199
|
const defaultDescription = str2(seo.defaultDescription);
|
|
@@ -2286,45 +3223,45 @@ function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
|
|
|
2286
3223
|
}
|
|
2287
3224
|
|
|
2288
3225
|
// src/provider.tsx
|
|
2289
|
-
var
|
|
3226
|
+
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
2290
3227
|
var EMPTY = {};
|
|
2291
3228
|
function useParentFont() {
|
|
2292
|
-
return (0,
|
|
3229
|
+
return (0, import_react18.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
|
|
2293
3230
|
}
|
|
2294
|
-
function BuilderProvider({ builderKey, client, packs, site, onError, children }) {
|
|
3231
|
+
function BuilderProvider({ builderKey, client, packs, site, onError, interactive = true, pathname, catalogRoutes, mode = "live", children }) {
|
|
2295
3232
|
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2296
|
-
const registryRef = (0,
|
|
3233
|
+
const registryRef = (0, import_react18.useRef)(null);
|
|
2297
3234
|
if (registryRef.current?.key !== packsKey) {
|
|
2298
3235
|
registryRef.current = { key: packsKey, registry: createRendererRegistry(packs) };
|
|
2299
3236
|
}
|
|
2300
3237
|
const registry = registryRef.current.registry;
|
|
2301
|
-
const builder = (0,
|
|
3238
|
+
const builder = (0, import_react18.useMemo)(
|
|
2302
3239
|
() => client ?? (builderKey === void 0 ? null : (0, import_builder2.createBuilderClient)({ builderKey })),
|
|
2303
3240
|
[client, builderKey]
|
|
2304
3241
|
);
|
|
2305
3242
|
const mediaOrigin = site.status === "ok" ? site.mediaOrigin : "";
|
|
2306
3243
|
const settings = site.status === "ok" ? site.settings : EMPTY;
|
|
2307
|
-
const resolveLink = (0,
|
|
2308
|
-
const outlets = (0,
|
|
2309
|
-
const renderers = (0,
|
|
2310
|
-
const pageOutlet = (0,
|
|
3244
|
+
const resolveLink = (0, import_react18.useMemo)(() => makeResolveLink(settings, packs), [settings, packs]);
|
|
3245
|
+
const outlets = (0, import_react18.useRef)(/* @__PURE__ */ new Map());
|
|
3246
|
+
const renderers = (0, import_react18.useRef)(/* @__PURE__ */ new Map());
|
|
3247
|
+
const pageOutlet = (0, import_react18.useCallback)((handle) => {
|
|
2311
3248
|
let outlet = outlets.current.get(handle);
|
|
2312
3249
|
if (outlet === void 0) {
|
|
2313
3250
|
outlet = function PageOutlet() {
|
|
2314
|
-
return /* @__PURE__ */ (0,
|
|
3251
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(PartBoundary, { label: `Builder page ${handle}`, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_react18.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderPage, { slug: handle }) }) });
|
|
2315
3252
|
};
|
|
2316
3253
|
outlets.current.set(handle, outlet);
|
|
2317
3254
|
}
|
|
2318
3255
|
return outlet;
|
|
2319
3256
|
}, []);
|
|
2320
|
-
const resolveSlot = (0,
|
|
3257
|
+
const resolveSlot = (0, import_react18.useCallback)(
|
|
2321
3258
|
(name) => {
|
|
2322
3259
|
const part = site.status === "ok" && Object.hasOwn(site.slots, name) ? site.slots[name] : void 0;
|
|
2323
3260
|
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2324
3261
|
let renderer = renderers.current.get(name);
|
|
2325
3262
|
if (renderer === void 0) {
|
|
2326
3263
|
renderer = function SlotRenderer({ context }) {
|
|
2327
|
-
return /* @__PURE__ */ (0,
|
|
3264
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderSlot, { name, context });
|
|
2328
3265
|
};
|
|
2329
3266
|
renderers.current.set(name, renderer);
|
|
2330
3267
|
}
|
|
@@ -2332,30 +3269,42 @@ function BuilderProvider({ builderKey, client, packs, site, onError, children })
|
|
|
2332
3269
|
},
|
|
2333
3270
|
[site]
|
|
2334
3271
|
);
|
|
2335
|
-
const
|
|
2336
|
-
|
|
2337
|
-
|
|
3272
|
+
const customCss = (0, import_react18.useMemo)(() => site.status === "ok" ? customCssOf(site.settings) : "", [site]);
|
|
3273
|
+
const configured = settings.routes?.page;
|
|
3274
|
+
const pageRoute = typeof configured === "string" ? configured : "/pages/{handle}";
|
|
3275
|
+
const catalogKey = catalogRoutes?.join("\n");
|
|
3276
|
+
const codeRoutes = (0, import_react18.useMemo)(
|
|
3277
|
+
() => ({ page: pageRoute, ...catalogRoutes === void 0 ? {} : { catalog: catalogRoutes } }),
|
|
3278
|
+
// `catalogRoutes` is compared by value: a store passes a fresh array each render.
|
|
3279
|
+
[pageRoute, catalogKey]
|
|
3280
|
+
);
|
|
3281
|
+
useLeaveCodeRoutes(pathname, codeRoutes);
|
|
3282
|
+
const leaving = mustLeave(pathname, codeRoutes);
|
|
3283
|
+
const value = (0, import_react18.useMemo)(
|
|
3284
|
+
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes }),
|
|
3285
|
+
[builder, packs, registry, site, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes]
|
|
2338
3286
|
);
|
|
2339
|
-
const design = (0,
|
|
3287
|
+
const design = (0, import_react18.useMemo)(
|
|
2340
3288
|
() => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
|
|
2341
3289
|
[site, resolveLink, pageOutlet, mediaOrigin]
|
|
2342
3290
|
);
|
|
2343
|
-
const own = (0,
|
|
3291
|
+
const own = (0, import_react18.useMemo)(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
|
|
2344
3292
|
const merged = (0, import_ui6.useAppearanceProviderValue)(own);
|
|
2345
3293
|
const parentFont = useParentFont();
|
|
2346
|
-
const appearance = (0,
|
|
3294
|
+
const appearance = (0, import_react18.useMemo)(() => {
|
|
2347
3295
|
if (own === void 0) return void 0;
|
|
2348
3296
|
return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
|
|
2349
3297
|
}, [own, merged, parentFont]);
|
|
2350
|
-
return /* @__PURE__ */ (0,
|
|
2351
|
-
site.status === "ok" ? /* @__PURE__ */ (0,
|
|
2352
|
-
children
|
|
3298
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_ui6.ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_ui6.SiteDesignProvider, { value: design, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(import_ui6.SlotOutletProvider, { resolve: resolveSlot, children: [
|
|
3299
|
+
site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("style", { children: themeCss(site.settings) }) : null,
|
|
3300
|
+
customCss === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("style", { children: customCssSheet(customCss) }),
|
|
3301
|
+
leaving ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { "data-b-leaving": "", hidden: true }) : children
|
|
2353
3302
|
] }) }) }) });
|
|
2354
3303
|
}
|
|
2355
3304
|
|
|
2356
3305
|
// src/parts.tsx
|
|
2357
|
-
var
|
|
2358
|
-
var
|
|
3306
|
+
var import_react19 = require("react");
|
|
3307
|
+
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
2359
3308
|
function Part({ name, tag }) {
|
|
2360
3309
|
const builder = useBuilder();
|
|
2361
3310
|
if (builder === null || builder.site.status !== "ok") return null;
|
|
@@ -2365,11 +3314,11 @@ function Part({ name, tag }) {
|
|
|
2365
3314
|
return (
|
|
2366
3315
|
// Error boundaries do not catch on the server: the Suspense inside turns a throw
|
|
2367
3316
|
// during SSR into "render nothing here" and the client retries under the boundary.
|
|
2368
|
-
/* @__PURE__ */ (0,
|
|
3317
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PartBoundary, { label: `Builder ${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Tag, { "data-throttle-part": `builder-${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_react19.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PartView, { part }) }) }) })
|
|
2369
3318
|
);
|
|
2370
3319
|
}
|
|
2371
|
-
var BuilderHeader = () => /* @__PURE__ */ (0,
|
|
2372
|
-
var BuilderFooter = () => /* @__PURE__ */ (0,
|
|
3320
|
+
var BuilderHeader = () => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Part, { name: "header", tag: "header" });
|
|
3321
|
+
var BuilderFooter = () => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Part, { name: "footer", tag: "footer" });
|
|
2373
3322
|
|
|
2374
3323
|
// src/index.ts
|
|
2375
3324
|
var import_builder3 = require("@usethrottle/builder");
|