@usethrottle/builder-react 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +178 -0
- package/dist/bundle-x5Vxd-xE.d.cts +136 -0
- package/dist/bundle-x5Vxd-xE.d.ts +136 -0
- package/dist/chunk-DRQNR5GN.js +1929 -0
- package/dist/chunk-RWDLDDSF.cjs +1929 -0
- package/dist/index.cjs +2315 -0
- package/dist/index.d.cts +446 -0
- package/dist/index.d.ts +446 -0
- package/dist/index.js +2318 -0
- package/dist/next.cjs +95 -0
- package/dist/next.d.cts +41 -0
- package/dist/next.d.ts +41 -0
- package/dist/next.js +95 -0
- package/dist/server.cjs +74 -0
- package/dist/server.d.cts +59 -0
- package/dist/server.d.ts +59 -0
- package/dist/server.js +74 -0
- package/package.json +95 -3
- package/README.md +0 -3
|
@@ -0,0 +1,1929 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/data.ts
|
|
6
|
+
import { walkNodes } from "@usethrottle/builder-schema";
|
|
7
|
+
|
|
8
|
+
// src/warn.ts
|
|
9
|
+
var seen = /* @__PURE__ */ new Set();
|
|
10
|
+
function warnOnce(key, message) {
|
|
11
|
+
if (seen.has(key)) return;
|
|
12
|
+
seen.add(key);
|
|
13
|
+
console.warn(`[throttle-builder] ${message}`);
|
|
14
|
+
}
|
|
15
|
+
var isDevelopment = () => typeof process === "undefined" || process.env?.NODE_ENV !== "production";
|
|
16
|
+
|
|
17
|
+
// src/data.ts
|
|
18
|
+
function stable(value) {
|
|
19
|
+
if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
|
|
20
|
+
if (typeof value === "object" && value !== null) {
|
|
21
|
+
const entries = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
22
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${stable(v)}`).join(",")}}`;
|
|
23
|
+
}
|
|
24
|
+
return JSON.stringify(value) ?? "null";
|
|
25
|
+
}
|
|
26
|
+
function bindingKey(binding) {
|
|
27
|
+
return "params" in binding ? `${binding.source}?${stable(binding.params)}` : binding.source;
|
|
28
|
+
}
|
|
29
|
+
var isContextBinding = (binding) => binding.source.startsWith("context.");
|
|
30
|
+
function bindingsOf(node, registry) {
|
|
31
|
+
const def = registry.widget(node.type, node.v);
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const [name, input] of Object.entries(def?.data ?? {})) {
|
|
34
|
+
if (input.default !== void 0) out[name] = input.default;
|
|
35
|
+
}
|
|
36
|
+
return { ...out, ...node.data ?? {} };
|
|
37
|
+
}
|
|
38
|
+
function collectBindings(doc, registry) {
|
|
39
|
+
const found = /* @__PURE__ */ new Map();
|
|
40
|
+
walkNodes(doc, (node) => {
|
|
41
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column") return;
|
|
42
|
+
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
43
|
+
const key = bindingKey(binding);
|
|
44
|
+
if (!found.has(key)) found.set(key, binding);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return found;
|
|
48
|
+
}
|
|
49
|
+
async function resolveBindings(bindings, registry, ctx, options) {
|
|
50
|
+
const jobs = [];
|
|
51
|
+
for (const [key, binding] of bindings) {
|
|
52
|
+
if (isContextBinding(binding) || !("params" in binding)) continue;
|
|
53
|
+
const descriptor = registry.source(binding.source);
|
|
54
|
+
const resolve = registry.resolver(binding.source);
|
|
55
|
+
if (descriptor === void 0 || resolve === void 0) continue;
|
|
56
|
+
if (options.include === "static" && descriptor.perShopper) continue;
|
|
57
|
+
if (options.include === "shopper" && !descriptor.perShopper) continue;
|
|
58
|
+
jobs.push(
|
|
59
|
+
resolve(binding.params, ctx).then(
|
|
60
|
+
(value) => [key, value],
|
|
61
|
+
(error) => {
|
|
62
|
+
warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const settled = await Promise.all(jobs);
|
|
69
|
+
return Object.fromEntries(settled.filter((entry) => entry !== null));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/load.ts
|
|
73
|
+
function pageOf(raw, initialData) {
|
|
74
|
+
const { document, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, ...meta } = raw;
|
|
75
|
+
return {
|
|
76
|
+
kind: "page",
|
|
77
|
+
slug,
|
|
78
|
+
title,
|
|
79
|
+
path,
|
|
80
|
+
generation,
|
|
81
|
+
document,
|
|
82
|
+
assets: document.assets ?? {},
|
|
83
|
+
initialData,
|
|
84
|
+
meta
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function staticDataFor(documents, registry, locale) {
|
|
88
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const document of documents) {
|
|
90
|
+
for (const [key, binding] of collectBindings(document, registry)) bindings.set(key, binding);
|
|
91
|
+
}
|
|
92
|
+
if (bindings.size === 0) return {};
|
|
93
|
+
return resolveBindings(
|
|
94
|
+
bindings,
|
|
95
|
+
registry,
|
|
96
|
+
{ locale, preview: false, signal: new AbortController().signal },
|
|
97
|
+
{ include: "static" }
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
function partOf(loaded, initialData) {
|
|
101
|
+
return { document: loaded.document, assets: loaded.document.assets ?? {}, initialData };
|
|
102
|
+
}
|
|
103
|
+
var isRedirect = (raw) => typeof raw.redirectTo === "string";
|
|
104
|
+
|
|
105
|
+
// src/server/bundle.ts
|
|
106
|
+
import * as React from "react";
|
|
107
|
+
import { createBuilderClient } from "@usethrottle/builder";
|
|
108
|
+
var cache2 = React.cache ?? ((fn) => fn);
|
|
109
|
+
var requestBatches = cache2(() => []);
|
|
110
|
+
function getBundle(ask) {
|
|
111
|
+
const batches = requestBatches();
|
|
112
|
+
const slots = new Set(ask.slots ?? []);
|
|
113
|
+
const sameClient = (batch2) => batch2.client === ask.client && batch2.locale === ask.locale;
|
|
114
|
+
const pageFits = (batch2) => ask.page === void 0 || batch2.page === ask.page;
|
|
115
|
+
for (const batch2 of batches) {
|
|
116
|
+
if (!sameClient(batch2)) continue;
|
|
117
|
+
if (batch2.dispatched) {
|
|
118
|
+
if (pageFits(batch2) && [...slots].every((slot) => batch2.slots.has(slot))) return batch2.promise;
|
|
119
|
+
} else if (ask.page === void 0 || batch2.page === void 0 || batch2.page === ask.page) {
|
|
120
|
+
batch2.page ?? (batch2.page = ask.page);
|
|
121
|
+
for (const slot of slots) batch2.slots.add(slot);
|
|
122
|
+
return batch2.promise;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const batch = {
|
|
126
|
+
client: ask.client,
|
|
127
|
+
locale: ask.locale,
|
|
128
|
+
page: ask.page,
|
|
129
|
+
slots,
|
|
130
|
+
dispatched: false,
|
|
131
|
+
promise: Promise.resolve()
|
|
132
|
+
};
|
|
133
|
+
batch.promise = Promise.resolve().then(() => {
|
|
134
|
+
batch.dispatched = true;
|
|
135
|
+
return ask.client.bundle({
|
|
136
|
+
locale: ask.locale,
|
|
137
|
+
...batch.page === void 0 ? {} : { page: batch.page },
|
|
138
|
+
slots: [...batch.slots].sort()
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
batches.push(batch);
|
|
142
|
+
return batch.promise;
|
|
143
|
+
}
|
|
144
|
+
var clients = /* @__PURE__ */ new Map();
|
|
145
|
+
function clientOf(options) {
|
|
146
|
+
if (options.client !== void 0) return options.client;
|
|
147
|
+
const key = options.builderKey;
|
|
148
|
+
if (key === void 0 || key === "") throw new TypeError("Give the Builder loaders a client or a builderKey");
|
|
149
|
+
let client = clients.get(key);
|
|
150
|
+
if (client === void 0) {
|
|
151
|
+
client = createBuilderClient({ builderKey: key });
|
|
152
|
+
clients.set(key, client);
|
|
153
|
+
}
|
|
154
|
+
return client;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/registry.ts
|
|
158
|
+
import { createRegistry } from "@usethrottle/builder-schema";
|
|
159
|
+
|
|
160
|
+
// src/basics/index.ts
|
|
161
|
+
import { BASIC_WIDGET_DEFINITIONS as BASIC_WIDGET_DEFINITIONS2 } from "@usethrottle/builder-schema";
|
|
162
|
+
|
|
163
|
+
// src/basics/announcement.tsx
|
|
164
|
+
import { useEffect, useState } from "react";
|
|
165
|
+
import { Icon, useSiteDesign } from "@usethrottle/ui";
|
|
166
|
+
import { SITE_STRING_DEFAULTS, safeUrl as safeUrl2 } from "@usethrottle/builder-schema";
|
|
167
|
+
|
|
168
|
+
// src/basics/util.tsx
|
|
169
|
+
import { BASIC_WIDGET_DEFINITIONS, resolveResponsive, safeUrl } from "@usethrottle/builder-schema";
|
|
170
|
+
|
|
171
|
+
// src/basics/styles.ts
|
|
172
|
+
var BASICS_CSS = `@layer throttle{
|
|
173
|
+
.tb-b-heading{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
|
|
174
|
+
.tb-b-text{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6;overflow-wrap:anywhere}
|
|
175
|
+
.tb-b-text>:first-child{margin-block-start:0}
|
|
176
|
+
.tb-b-text>:last-child{margin-block-end:0}
|
|
177
|
+
.tb-b-text h2,.tb-b-text h3,.tb-b-text h4{line-height:1.25}
|
|
178
|
+
.tb-b-text blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
|
|
179
|
+
.tb-b-text code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
|
|
180
|
+
.tb-b-link{color:var(--tb-color-primary,currentColor);text-decoration:underline}
|
|
181
|
+
.tb-b-image{text-align:var(--b-align,left);line-height:0}
|
|
182
|
+
.tb-b-image-box{display:inline-block;max-inline-size:100%;inline-size:calc(var(--b-width,100)*1%);vertical-align:top}
|
|
183
|
+
.tb-b-image-box a{display:block}
|
|
184
|
+
.tb-b-img{display:block;inline-size:100%;max-inline-size:100%;block-size:calc(var(--b-height)*1px);object-fit:var(--bx-fit,cover);border-radius:var(--bx-radius,0)}
|
|
185
|
+
.tb-b-empty{padding:var(--tb-space-m);border:1px dashed var(--tb-color-border-control,currentColor);color:var(--tb-color-muted-foreground,inherit);font-size:var(--tb-text-s);line-height:1.4;text-align:center}
|
|
186
|
+
.tb-b-button-wrap{text-align:var(--b-align,left)}
|
|
187
|
+
.tb-b-button{display:inline-block;box-sizing:border-box;min-inline-size:calc(100%*var(--b-fullWidth,0));max-inline-size:100%;border:1px solid transparent;border-radius:var(--throttle-radius,8px);font:inherit;font-weight:600;line-height:1.2;text-align:center;text-decoration:none;cursor:pointer}
|
|
188
|
+
.tb-b-button--s{padding:.4rem .9rem;font-size:var(--tb-text-s)}
|
|
189
|
+
.tb-b-button--m{padding:.65rem 1.25rem;font-size:var(--tb-text-m)}
|
|
190
|
+
.tb-b-button--l{padding:.9rem 1.75rem;font-size:var(--tb-text-l)}
|
|
191
|
+
.tb-b-button--primary{background:var(--tb-color-primary,#111);color:var(--tb-color-primary-foreground,#fff)}
|
|
192
|
+
.tb-b-button--secondary{background:var(--tb-color-muted,#eee);color:var(--tb-color-foreground,#111)}
|
|
193
|
+
.tb-b-button--outline{background:transparent;border-color:var(--tb-color-border-control,currentColor);color:var(--tb-color-foreground,#111)}
|
|
194
|
+
.tb-b-button--link{padding-inline:0;background:transparent;color:var(--tb-color-primary,#111);text-decoration:underline}
|
|
195
|
+
.tb-b-button:hover{filter:brightness(.92)}
|
|
196
|
+
.tb-b-button:focus-visible,.tb-b-menu a:focus-visible,.tb-b-menu-toggle:focus-visible,.tb-b-play:focus-visible,.tb-b-dismiss:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
|
|
197
|
+
.tb-b-spacer{block-size:var(--b-height,var(--tb-space-l))}
|
|
198
|
+
.tb-b-divider{box-sizing:border-box;inline-size:calc(var(--b-width,100)*1%);margin:0 auto;border:0;border-block-start:calc(var(--b-thickness,1)*1px) var(--bx-style,solid) var(--b-color,var(--tb-color-border,currentColor))}
|
|
199
|
+
.tb-b-video{position:relative;inline-size:100%;aspect-ratio:var(--bx-ratio,16/9);background:var(--tb-color-foreground,#111);border-radius:var(--throttle-radius,8px);overflow:hidden}
|
|
200
|
+
.tb-b-video iframe,.tb-b-play{position:absolute;inset:0;inline-size:100%;block-size:100%;border:0}
|
|
201
|
+
.tb-b-play{display:flex;align-items:center;justify-content:center;padding:0;background:transparent;color:var(--tb-color-background,#fff);cursor:pointer}
|
|
202
|
+
.tb-b-play span{display:grid;place-items:center;inline-size:4rem;block-size:4rem;border-radius:50%;background:rgba(0,0,0,.55)}
|
|
203
|
+
.tb-b-play:hover span{background:rgba(0,0,0,.75)}
|
|
204
|
+
.tb-b-logo{text-align:var(--b-align,left);line-height:0}
|
|
205
|
+
.tb-b-logo a{display:inline-block;color:inherit;text-decoration:none}
|
|
206
|
+
.tb-b-logo img{display:block;block-size:calc(var(--b-height,40)*1px);inline-size:auto;max-inline-size:100%}
|
|
207
|
+
.tb-b-logo-name{display:inline-block;font-size:var(--tb-text-xl);font-weight:700;line-height:calc(var(--b-height,40)*1px)}
|
|
208
|
+
.tb-b-menu{position:relative;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m))}
|
|
209
|
+
.tb-b-menu ul{margin:0;padding:0;list-style:none}
|
|
210
|
+
.tb-b-menu a{display:block;padding:var(--tb-space-xs) var(--tb-space-s);color:inherit;text-decoration:none}
|
|
211
|
+
.tb-b-menu a:hover{text-decoration:underline}
|
|
212
|
+
.tb-b-menu li{position:relative}
|
|
213
|
+
.tb-b-menu--vertical li li{padding-inline-start:var(--tb-space-m)}
|
|
214
|
+
.tb-b-menu--h>ul>li{display:inline-block}
|
|
215
|
+
.tb-b-menu--h li>ul{display:none;position:absolute;inset-block-start:100%;inset-inline-start:0;z-index:20;min-inline-size:12rem;padding:var(--tb-space-xs);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);border:1px solid var(--tb-color-border,#ddd);border-radius:var(--throttle-radius,8px)}
|
|
216
|
+
.tb-b-menu--h li:hover>ul,.tb-b-menu--h li:focus-within>ul{display:block}
|
|
217
|
+
.tb-b-menu-toggle{display:none;align-items:center;justify-content:center;min-inline-size:44px;min-block-size:44px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
|
|
218
|
+
@media (max-width:767px){
|
|
219
|
+
.tb-b-menu--drawer-on-phone .tb-b-menu-toggle{display:inline-flex;position:relative;z-index:61}
|
|
220
|
+
.tb-b-menu--drawer-on-phone[data-open=true] .tb-b-menu-toggle{position:fixed;inset-block-start:var(--tb-space-s);inset-inline-end:var(--tb-space-s)}
|
|
221
|
+
.tb-b-menu--drawer-on-phone>ul{display:none}
|
|
222
|
+
.tb-b-menu--drawer-on-phone[data-open=true]>ul{display:block;position:fixed;inset:0;z-index:60;overflow:auto;padding:4.5rem var(--tb-space-m) var(--tb-space-m);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);font-size:var(--tb-text-l)}
|
|
223
|
+
.tb-b-menu--drawer-on-phone>ul>li{display:block}
|
|
224
|
+
.tb-b-menu--drawer-on-phone li>ul{display:block;position:static;min-inline-size:0;padding:0;border:0;padding-inline-start:var(--tb-space-m)}
|
|
225
|
+
}
|
|
226
|
+
.tb-b-announcement{display:flex;align-items:center;justify-content:center;gap:var(--tb-space-s);box-sizing:border-box;padding:var(--tb-space-s) var(--tb-space-m);text-align:var(--b-align,center);background:var(--b-background,var(--tb-color-primary,#111));color:var(--b-color,var(--tb-color-primary-foreground,#fff));font-size:var(--tb-text-s)}
|
|
227
|
+
.tb-b-announcement-text{flex:1 1 auto}
|
|
228
|
+
.tb-b-announcement a{color:inherit;text-decoration:underline}
|
|
229
|
+
.tb-b-dismiss{display:inline-grid;place-items:center;flex:0 0 auto;min-inline-size:32px;min-block-size:32px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
|
|
230
|
+
.tb-b-copyright{margin:0;text-align:var(--b-align,center);color:var(--b-color,var(--tb-color-muted-foreground,inherit));font-size:var(--b-size,var(--tb-text-s))}
|
|
231
|
+
}`;
|
|
232
|
+
|
|
233
|
+
// src/basics/util.tsx
|
|
234
|
+
import { jsx } from "react/jsx-runtime";
|
|
235
|
+
function BasicStyles() {
|
|
236
|
+
return /* @__PURE__ */ jsx("style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
|
|
237
|
+
}
|
|
238
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
239
|
+
var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
240
|
+
function oneOf(value, allowed, fallback) {
|
|
241
|
+
return allowed.find((candidate) => candidate === value) ?? fallback;
|
|
242
|
+
}
|
|
243
|
+
function hrefOf(link, mediaOrigin) {
|
|
244
|
+
if (!isRecord(link)) return null;
|
|
245
|
+
return safeUrl(link.href, "href", { mediaOrigin });
|
|
246
|
+
}
|
|
247
|
+
function Placeholder({ editMode, children }) {
|
|
248
|
+
return editMode ? /* @__PURE__ */ jsx("div", { className: "tb-b-empty", children }) : null;
|
|
249
|
+
}
|
|
250
|
+
var ID_RE = /^[a-z0-9]{8,24}$/;
|
|
251
|
+
var DEVICES = ["desktop", "tablet", "phone"];
|
|
252
|
+
function defaultOf(type, key) {
|
|
253
|
+
const def = BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
|
|
254
|
+
return def?.settings.find((f) => f.key === key)?.default ?? null;
|
|
255
|
+
}
|
|
256
|
+
function enumCss(node, rules) {
|
|
257
|
+
if (!ID_RE.test(node.id)) return "";
|
|
258
|
+
const per = { desktop: /* @__PURE__ */ new Map(), tablet: /* @__PURE__ */ new Map(), phone: /* @__PURE__ */ new Map() };
|
|
259
|
+
for (const device of DEVICES) {
|
|
260
|
+
const settings = { ...Object.fromEntries(rules.map((r) => [r.key, defaultOf(node.type, r.key)])), ...node.props };
|
|
261
|
+
const resolved = resolveResponsive(settings, node.responsive, device);
|
|
262
|
+
for (const rule of rules) {
|
|
263
|
+
const value = resolved[rule.key];
|
|
264
|
+
const fallback = defaultOf(node.type, rule.key);
|
|
265
|
+
const pick = typeof value === "string" && Object.hasOwn(rule.values, value) ? value : String(fallback);
|
|
266
|
+
const css = Object.hasOwn(rule.values, pick) ? rule.values[pick] : void 0;
|
|
267
|
+
if (css !== void 0) per[device].set(rule.property, css);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const block2 = (decls) => decls.length === 0 ? "" : `[data-b-id="${node.id}"]{${decls.map(([p, v]) => `${p}:${v}`).join(";")}}`;
|
|
271
|
+
const diff = (prev, next) => [...next].filter(([p, v]) => prev.get(p) !== v);
|
|
272
|
+
const tablet = block2(diff(per.desktop, per.tablet));
|
|
273
|
+
const phone = block2(diff(per.tablet, per.phone));
|
|
274
|
+
return block2([...per.desktop]) + (tablet === "" ? "" : `@media (max-width:1024px){${tablet}}`) + (phone === "" ? "" : `@media (max-width:767px){${phone}}`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/basics/announcement.tsx
|
|
278
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
279
|
+
var KEY = "tb-announcement-dismissed";
|
|
280
|
+
function read(message) {
|
|
281
|
+
try {
|
|
282
|
+
return window.sessionStorage.getItem(KEY) === message;
|
|
283
|
+
} catch {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function write(message) {
|
|
288
|
+
try {
|
|
289
|
+
window.sessionStorage.setItem(KEY, message);
|
|
290
|
+
} catch {
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function Announcement({ props, mediaOrigin, editMode }) {
|
|
294
|
+
const design = useSiteDesign();
|
|
295
|
+
const message = design?.announcement?.message;
|
|
296
|
+
const [dismissed, setDismissed] = useState(false);
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
if (message !== void 0 && read(message)) setDismissed(true);
|
|
299
|
+
}, [message]);
|
|
300
|
+
if (message === void 0) {
|
|
301
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
302
|
+
/* @__PURE__ */ jsx2(BasicStyles, {}),
|
|
303
|
+
/* @__PURE__ */ jsx2(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
|
|
304
|
+
] });
|
|
305
|
+
}
|
|
306
|
+
if (dismissed && !editMode) return null;
|
|
307
|
+
const href = safeUrl2(design?.announcement?.href, "href", { mediaOrigin });
|
|
308
|
+
const strings = design?.strings;
|
|
309
|
+
const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? SITE_STRING_DEFAULTS["announcement.dismiss"];
|
|
310
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
311
|
+
/* @__PURE__ */ jsx2(BasicStyles, {}),
|
|
312
|
+
/* @__PURE__ */ jsxs("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
|
|
313
|
+
/* @__PURE__ */ jsx2("span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ jsx2("a", { href, children: message }) }),
|
|
314
|
+
props.dismissible === true && /* @__PURE__ */ jsx2(
|
|
315
|
+
"button",
|
|
316
|
+
{
|
|
317
|
+
type: "button",
|
|
318
|
+
className: "tb-b-dismiss",
|
|
319
|
+
onClick: () => {
|
|
320
|
+
write(message);
|
|
321
|
+
setDismissed(true);
|
|
322
|
+
},
|
|
323
|
+
children: /* @__PURE__ */ jsx2(Icon, { name: "close", size: 16, label: dismissLabel })
|
|
324
|
+
}
|
|
325
|
+
)
|
|
326
|
+
] })
|
|
327
|
+
] });
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/basics/button.tsx
|
|
331
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
332
|
+
var STYLES = ["primary", "secondary", "outline", "link"];
|
|
333
|
+
var SIZES = ["s", "m", "l"];
|
|
334
|
+
function Button({ props, mediaOrigin, inlineEdit }) {
|
|
335
|
+
const href = hrefOf(props.link, mediaOrigin);
|
|
336
|
+
const className = `tb-b-button tb-b-button--${oneOf(props.style, STYLES, "primary")} tb-b-button--${oneOf(props.size, SIZES, "m")}`;
|
|
337
|
+
const label = inlineEdit?.("label") ?? str(props.label) ?? "";
|
|
338
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
339
|
+
/* @__PURE__ */ jsx3(BasicStyles, {}),
|
|
340
|
+
/* @__PURE__ */ jsx3("div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ jsx3("a", { className, ...href === null ? {} : { href }, children: label }) })
|
|
341
|
+
] });
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/basics/copyright.tsx
|
|
345
|
+
import { useSiteDesign as useSiteDesign2 } from "@usethrottle/ui";
|
|
346
|
+
import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS2 } from "@usethrottle/builder-schema";
|
|
347
|
+
import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
348
|
+
function Copyright(_) {
|
|
349
|
+
const design = useSiteDesign2();
|
|
350
|
+
const strings = design?.strings;
|
|
351
|
+
const template = strings !== void 0 && Object.hasOwn(strings, "footer.copyright") ? str(strings["footer.copyright"]) : void 0;
|
|
352
|
+
const line = (template ?? SITE_STRING_DEFAULTS2["footer.copyright"]).replace("{year}", () => String((/* @__PURE__ */ new Date()).getFullYear())).replace("{store}", () => str(design?.brand?.storeName) ?? "").replace(/\s{2,}/g, " ").replace(/\s+([.,])/g, "$1");
|
|
353
|
+
return /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
354
|
+
/* @__PURE__ */ jsx4(BasicStyles, {}),
|
|
355
|
+
/* @__PURE__ */ jsx4("p", { className: "tb-b-copyright", children: line })
|
|
356
|
+
] });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/widget-style.tsx
|
|
360
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
361
|
+
function WidgetStyle({ css }) {
|
|
362
|
+
if (css === "" || css.includes("<")) return null;
|
|
363
|
+
return /* @__PURE__ */ jsx5("style", { children: css });
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/basics/divider.tsx
|
|
367
|
+
import { Fragment as Fragment4, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
368
|
+
var RULES = [{ key: "style", property: "--bx-style", values: { solid: "solid", dashed: "dashed", dotted: "dotted" } }];
|
|
369
|
+
function Divider({ node }) {
|
|
370
|
+
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
371
|
+
/* @__PURE__ */ jsx6(BasicStyles, {}),
|
|
372
|
+
/* @__PURE__ */ jsx6(WidgetStyle, { css: enumCss(node, RULES) }),
|
|
373
|
+
/* @__PURE__ */ jsx6("hr", { className: "tb-b-divider" })
|
|
374
|
+
] });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// src/basics/heading.tsx
|
|
378
|
+
import { Fragment as Fragment5, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
379
|
+
var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
380
|
+
function Heading({ props, inlineEdit }) {
|
|
381
|
+
const Tag = oneOf(props.level, LEVELS, "h2");
|
|
382
|
+
return /* @__PURE__ */ jsxs5(Fragment5, { children: [
|
|
383
|
+
/* @__PURE__ */ jsx7(BasicStyles, {}),
|
|
384
|
+
/* @__PURE__ */ jsx7(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" })
|
|
385
|
+
] });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/basics/image.tsx
|
|
389
|
+
import { safeUrl as safeUrl4 } from "@usethrottle/builder-schema";
|
|
390
|
+
|
|
391
|
+
// src/asset-image.tsx
|
|
392
|
+
import { safeUrl as safeUrl3 } from "@usethrottle/builder-schema";
|
|
393
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
394
|
+
function isFrozenAsset(value) {
|
|
395
|
+
if (typeof value !== "object" || value === null) return false;
|
|
396
|
+
const v = value;
|
|
397
|
+
return typeof v.url === "string" && typeof v.width === "number" && typeof v.height === "number" && Array.isArray(v.variants);
|
|
398
|
+
}
|
|
399
|
+
function AssetImage(props) {
|
|
400
|
+
const { asset, alt, sizes, className, loading = "lazy", style, mediaOrigin } = props;
|
|
401
|
+
const href = (url) => safeUrl3(url, "src", { mediaOrigin });
|
|
402
|
+
if (!isFrozenAsset(asset)) return null;
|
|
403
|
+
const src = href(asset.url);
|
|
404
|
+
if (src === null) return null;
|
|
405
|
+
const srcSet = asset.variants.flatMap((variant) => {
|
|
406
|
+
const url = href(variant.url);
|
|
407
|
+
return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
|
|
408
|
+
}).join(", ");
|
|
409
|
+
return /* @__PURE__ */ jsx8(
|
|
410
|
+
"img",
|
|
411
|
+
{
|
|
412
|
+
src,
|
|
413
|
+
...srcSet === "" ? {} : { srcSet, sizes: sizes ?? "100vw" },
|
|
414
|
+
width: asset.width,
|
|
415
|
+
height: asset.height,
|
|
416
|
+
alt,
|
|
417
|
+
loading,
|
|
418
|
+
decoding: "async",
|
|
419
|
+
...className === void 0 ? {} : { className },
|
|
420
|
+
style: { aspectRatio: `${String(asset.width)} / ${String(asset.height)}`, ...style }
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/basics/image.tsx
|
|
426
|
+
import { Fragment as Fragment6, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
427
|
+
var RULES2 = [
|
|
428
|
+
{ key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
|
|
429
|
+
{ key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
|
|
430
|
+
];
|
|
431
|
+
function Image({ node, props, mediaOrigin, editMode }) {
|
|
432
|
+
const href = hrefOf(props.link, mediaOrigin);
|
|
433
|
+
const decorative = props.decorative === true;
|
|
434
|
+
const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
|
|
435
|
+
const asset = isFrozenAsset(props.image) ? props.image : void 0;
|
|
436
|
+
const image = /* @__PURE__ */ jsx9(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
|
|
437
|
+
const shown = asset !== void 0 && safeUrl4(asset.url, "src", { mediaOrigin }) !== null;
|
|
438
|
+
return /* @__PURE__ */ jsxs6(Fragment6, { children: [
|
|
439
|
+
/* @__PURE__ */ jsx9(BasicStyles, {}),
|
|
440
|
+
/* @__PURE__ */ jsx9(WidgetStyle, { css: enumCss(node, RULES2) }),
|
|
441
|
+
shown ? /* @__PURE__ */ jsx9("div", { className: "tb-b-image", children: /* @__PURE__ */ jsx9("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ jsx9("a", { href, children: image }) }) }) : /* @__PURE__ */ jsx9(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
|
|
442
|
+
] });
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/basics/logo.tsx
|
|
446
|
+
import { useSiteDesign as useSiteDesign3 } from "@usethrottle/ui";
|
|
447
|
+
import { safeUrl as safeUrl5 } from "@usethrottle/builder-schema";
|
|
448
|
+
import { Fragment as Fragment7, jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
449
|
+
function Logo({ props, mediaOrigin, editMode }) {
|
|
450
|
+
const design = useSiteDesign3();
|
|
451
|
+
const scheme = design?.theme?.colorScheme ?? "auto";
|
|
452
|
+
const src = (url) => url === void 0 ? void 0 : safeUrl5(url, "src", { mediaOrigin }) ?? void 0;
|
|
453
|
+
const light = src(design?.brand?.logo?.light);
|
|
454
|
+
const dark = src(design?.brand?.logo?.dark);
|
|
455
|
+
const main = scheme === "dark" ? dark ?? light : light ?? dark;
|
|
456
|
+
const name = str(design?.brand?.storeName);
|
|
457
|
+
const href = hrefOf(props.link, mediaOrigin) ?? "/";
|
|
458
|
+
const alt = name ?? "";
|
|
459
|
+
let content = null;
|
|
460
|
+
if (main !== void 0) {
|
|
461
|
+
const img = /* @__PURE__ */ jsx10("img", { src: main, alt, decoding: "async" });
|
|
462
|
+
content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ jsxs7("picture", { children: [
|
|
463
|
+
/* @__PURE__ */ jsx10("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
|
|
464
|
+
img
|
|
465
|
+
] }) : img;
|
|
466
|
+
} else if (name !== void 0) {
|
|
467
|
+
content = /* @__PURE__ */ jsx10("span", { className: "tb-b-logo-name", children: name });
|
|
468
|
+
}
|
|
469
|
+
return /* @__PURE__ */ jsxs7(Fragment7, { children: [
|
|
470
|
+
/* @__PURE__ */ jsx10(BasicStyles, {}),
|
|
471
|
+
content === null ? /* @__PURE__ */ jsx10(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ jsx10("div", { className: "tb-b-logo", children: /* @__PURE__ */ jsx10("a", { href, children: content }) })
|
|
472
|
+
] });
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/basics/menu.tsx
|
|
476
|
+
import { useId, useRef, useState as useState2 } from "react";
|
|
477
|
+
import { Icon as Icon2, useSiteDesign as useSiteDesign4 } from "@usethrottle/ui";
|
|
478
|
+
import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS3, safeUrl as safeUrl6 } from "@usethrottle/builder-schema";
|
|
479
|
+
import { Fragment as Fragment8, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
480
|
+
var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
|
|
481
|
+
var MAX_DEPTH = 3;
|
|
482
|
+
function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
|
|
483
|
+
const shown = items.flatMap((item) => {
|
|
484
|
+
const href = safeUrl6(item.href, "href", { mediaOrigin });
|
|
485
|
+
return href === null ? [] : [{ item, href }];
|
|
486
|
+
});
|
|
487
|
+
if (shown.length === 0) return null;
|
|
488
|
+
return /* @__PURE__ */ jsx11("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown.map(({ item, href }, index) => /* @__PURE__ */ jsxs8("li", { children: [
|
|
489
|
+
/* @__PURE__ */ jsx11("a", { href, children: item.label }),
|
|
490
|
+
depth + 1 < MAX_DEPTH && item.children !== void 0 && /* @__PURE__ */ jsx11(List, { items: item.children, mediaOrigin, depth: depth + 1 })
|
|
491
|
+
] }, `${String(index)}:${href}`)) });
|
|
492
|
+
}
|
|
493
|
+
function Menu({ props, mediaOrigin, editMode }) {
|
|
494
|
+
const design = useSiteDesign4();
|
|
495
|
+
const listId = useId();
|
|
496
|
+
const toggle = useRef(null);
|
|
497
|
+
const [open, setOpen] = useState2(false);
|
|
498
|
+
const name = str(props.menu) ?? "header";
|
|
499
|
+
const layout = oneOf(props.layout, LAYOUTS, "horizontal");
|
|
500
|
+
const menus = design?.menus;
|
|
501
|
+
const items = menus !== void 0 && Object.hasOwn(menus, name) ? menus[name] : void 0;
|
|
502
|
+
const strings = design?.strings;
|
|
503
|
+
const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? SITE_STRING_DEFAULTS3["nav.menu"];
|
|
504
|
+
if (items === void 0 || items.length === 0) {
|
|
505
|
+
return /* @__PURE__ */ jsxs8(Fragment8, { children: [
|
|
506
|
+
/* @__PURE__ */ jsx11(BasicStyles, {}),
|
|
507
|
+
/* @__PURE__ */ jsx11(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
|
|
508
|
+
] });
|
|
509
|
+
}
|
|
510
|
+
const drawer = layout === "drawer-on-phone";
|
|
511
|
+
const onKeyDown = (event) => {
|
|
512
|
+
if (event.key === "Escape" && open) {
|
|
513
|
+
setOpen(false);
|
|
514
|
+
toggle.current?.focus();
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
return /* @__PURE__ */ jsxs8(Fragment8, { children: [
|
|
518
|
+
/* @__PURE__ */ jsx11(BasicStyles, {}),
|
|
519
|
+
/* @__PURE__ */ jsxs8(
|
|
520
|
+
"nav",
|
|
521
|
+
{
|
|
522
|
+
className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
|
|
523
|
+
"aria-label": label,
|
|
524
|
+
"data-open": drawer ? String(open) : void 0,
|
|
525
|
+
onKeyDown: drawer ? onKeyDown : void 0,
|
|
526
|
+
children: [
|
|
527
|
+
drawer && /* @__PURE__ */ jsx11(
|
|
528
|
+
"button",
|
|
529
|
+
{
|
|
530
|
+
ref: toggle,
|
|
531
|
+
type: "button",
|
|
532
|
+
className: "tb-b-menu-toggle",
|
|
533
|
+
"aria-expanded": open,
|
|
534
|
+
"aria-controls": listId,
|
|
535
|
+
onClick: () => setOpen((value) => !value),
|
|
536
|
+
children: /* @__PURE__ */ jsx11(Icon2, { name: open ? "close" : "menu", size: 24, label })
|
|
537
|
+
}
|
|
538
|
+
),
|
|
539
|
+
/* @__PURE__ */ jsx11(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
|
|
540
|
+
]
|
|
541
|
+
}
|
|
542
|
+
)
|
|
543
|
+
] });
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/basics/spacer.tsx
|
|
547
|
+
import { Fragment as Fragment9, jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
548
|
+
function Spacer() {
|
|
549
|
+
return /* @__PURE__ */ jsxs9(Fragment9, { children: [
|
|
550
|
+
/* @__PURE__ */ jsx12(BasicStyles, {}),
|
|
551
|
+
/* @__PURE__ */ jsx12("div", { className: "tb-b-spacer", "aria-hidden": "true" })
|
|
552
|
+
] });
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/basics/rich-text.tsx
|
|
556
|
+
import { Fragment as Fragment10, createElement } from "react";
|
|
557
|
+
import { safeUrl as safeUrl7 } from "@usethrottle/builder-schema";
|
|
558
|
+
import { jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
559
|
+
var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
|
|
560
|
+
var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
|
|
561
|
+
var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
562
|
+
"script",
|
|
563
|
+
"style",
|
|
564
|
+
"iframe",
|
|
565
|
+
"object",
|
|
566
|
+
"embed",
|
|
567
|
+
"noscript",
|
|
568
|
+
"template",
|
|
569
|
+
"textarea",
|
|
570
|
+
"title",
|
|
571
|
+
"head",
|
|
572
|
+
"xml",
|
|
573
|
+
"svg",
|
|
574
|
+
"math",
|
|
575
|
+
"noembed",
|
|
576
|
+
"noframes",
|
|
577
|
+
"xmp"
|
|
578
|
+
]);
|
|
579
|
+
var VOID = /* @__PURE__ */ new Set(["br"]);
|
|
580
|
+
var BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote"]);
|
|
581
|
+
var TEXT_BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4"]);
|
|
582
|
+
var MAX_LENGTH = 2e4;
|
|
583
|
+
var MAX_DEPTH2 = 24;
|
|
584
|
+
var MAX_NODES = 4e3;
|
|
585
|
+
var NAMED = {
|
|
586
|
+
amp: "&",
|
|
587
|
+
lt: "<",
|
|
588
|
+
gt: ">",
|
|
589
|
+
quot: '"',
|
|
590
|
+
apos: "'",
|
|
591
|
+
nbsp: "\xA0",
|
|
592
|
+
copy: "\xA9",
|
|
593
|
+
reg: "\xAE",
|
|
594
|
+
trade: "\u2122",
|
|
595
|
+
mdash: "\u2014",
|
|
596
|
+
ndash: "\u2013",
|
|
597
|
+
hellip: "\u2026",
|
|
598
|
+
lsquo: "\u2018",
|
|
599
|
+
rsquo: "\u2019",
|
|
600
|
+
ldquo: "\u201C",
|
|
601
|
+
rdquo: "\u201D",
|
|
602
|
+
euro: "\u20AC",
|
|
603
|
+
pound: "\xA3"
|
|
604
|
+
};
|
|
605
|
+
function decode(value) {
|
|
606
|
+
return value.replace(/&(?:#x([0-9a-f]{1,6})|#(\d{1,7})|([a-z]{2,8}));/gi, (whole, hex, dec, name) => {
|
|
607
|
+
if (name !== void 0) return Object.hasOwn(NAMED, name.toLowerCase()) ? NAMED[name.toLowerCase()] : whole;
|
|
608
|
+
const code = hex !== void 0 ? Number.parseInt(hex, 16) : Number.parseInt(dec ?? "", 10);
|
|
609
|
+
return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : "";
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
var TAG_NAME = /[a-z][a-z0-9:_-]*/iy;
|
|
613
|
+
function readTag(html, start) {
|
|
614
|
+
const attrs = /* @__PURE__ */ new Map();
|
|
615
|
+
let i = start;
|
|
616
|
+
for (; ; ) {
|
|
617
|
+
while (i < html.length && /[\s/]/.test(html[i])) i += 1;
|
|
618
|
+
if (i >= html.length) return null;
|
|
619
|
+
if (html[i] === ">") return { attrs, end: i + 1, selfClosing: /\/\s*$/.test(html.slice(start, i)) };
|
|
620
|
+
let name = "";
|
|
621
|
+
while (i < html.length && !/[\s=/>]/.test(html[i])) name += html[i++];
|
|
622
|
+
while (i < html.length && /\s/.test(html[i])) i += 1;
|
|
623
|
+
let value = "";
|
|
624
|
+
if (html[i] === "=") {
|
|
625
|
+
i += 1;
|
|
626
|
+
while (i < html.length && /\s/.test(html[i])) i += 1;
|
|
627
|
+
const quote = html[i];
|
|
628
|
+
if (quote === '"' || quote === "'") {
|
|
629
|
+
const close = html.indexOf(quote, i + 1);
|
|
630
|
+
if (close === -1) return null;
|
|
631
|
+
value = html.slice(i + 1, close);
|
|
632
|
+
i = close + 1;
|
|
633
|
+
} else {
|
|
634
|
+
while (i < html.length && !/[\s>]/.test(html[i])) value += html[i++];
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const key = name.toLowerCase();
|
|
638
|
+
if (key !== "" && !attrs.has(key)) attrs.set(key, value);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function parseRichText(source, mediaOrigin) {
|
|
642
|
+
const html = source.slice(0, MAX_LENGTH);
|
|
643
|
+
const root = { tag: "#root", children: [], ...source.length > MAX_LENGTH ? { truncated: true } : {} };
|
|
644
|
+
const stack = [root];
|
|
645
|
+
const top = () => stack[stack.length - 1];
|
|
646
|
+
let nodes = 0;
|
|
647
|
+
const text = (value) => {
|
|
648
|
+
if (value === "" || nodes > MAX_NODES) return;
|
|
649
|
+
nodes += 1;
|
|
650
|
+
const parent = top();
|
|
651
|
+
const last = parent.children[parent.children.length - 1];
|
|
652
|
+
if (typeof last === "string") parent.children[parent.children.length - 1] = last + value;
|
|
653
|
+
else parent.children.push(value);
|
|
654
|
+
};
|
|
655
|
+
const closeTo = (tag) => {
|
|
656
|
+
const at = stack.map((e) => e.tag).lastIndexOf(tag);
|
|
657
|
+
if (at > 0) stack.length = at;
|
|
658
|
+
};
|
|
659
|
+
let i = 0;
|
|
660
|
+
while (i < html.length && nodes <= MAX_NODES) {
|
|
661
|
+
const lt = html.indexOf("<", i);
|
|
662
|
+
if (lt === -1) {
|
|
663
|
+
text(decode(html.slice(i)));
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
text(decode(html.slice(i, lt)));
|
|
667
|
+
i = lt;
|
|
668
|
+
if (html.startsWith("<!--", i)) {
|
|
669
|
+
const close = html.indexOf("-->", i + 4);
|
|
670
|
+
i = close === -1 ? html.length : close + 3;
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const closing = html[i + 1] === "/";
|
|
674
|
+
const nameStart = i + (closing ? 2 : 1);
|
|
675
|
+
TAG_NAME.lastIndex = nameStart;
|
|
676
|
+
const raw = TAG_NAME.exec(html)?.[0]?.toLowerCase();
|
|
677
|
+
if (raw === void 0) {
|
|
678
|
+
if (html[i + 1] === "!" || html[i + 1] === "?") {
|
|
679
|
+
const close = html.indexOf(">", i);
|
|
680
|
+
i = close === -1 ? html.length : close + 1;
|
|
681
|
+
} else {
|
|
682
|
+
text("<");
|
|
683
|
+
i += 1;
|
|
684
|
+
}
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
const tag = readTag(html, nameStart + raw.length);
|
|
688
|
+
if (tag === null) {
|
|
689
|
+
root.truncated = true;
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
i = tag.end;
|
|
693
|
+
const name = Object.hasOwn(ALIAS, raw) ? ALIAS[raw] : raw;
|
|
694
|
+
if (closing) {
|
|
695
|
+
if (ALLOWED.has(name)) closeTo(name);
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
if (DROP_WITH_CONTENT.has(raw)) {
|
|
699
|
+
if (!tag.selfClosing) {
|
|
700
|
+
const close = new RegExp(`</${raw}\\s*>`, "ig");
|
|
701
|
+
close.lastIndex = i;
|
|
702
|
+
const found = close.exec(html);
|
|
703
|
+
i = found === null ? html.length : found.index + found[0].length;
|
|
704
|
+
}
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
if (!ALLOWED.has(name)) continue;
|
|
708
|
+
if (BLOCK.has(name)) {
|
|
709
|
+
for (let at = stack.length - 1; at > 0; at -= 1) {
|
|
710
|
+
if (TEXT_BLOCK.has(stack[at].tag)) {
|
|
711
|
+
stack.length = at;
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (name === "li") {
|
|
717
|
+
let list = stack.length - 1;
|
|
718
|
+
while (list > 0 && stack[list].tag !== "ul" && stack[list].tag !== "ol") list -= 1;
|
|
719
|
+
if (list === 0) list = -1;
|
|
720
|
+
if (list === -1) continue;
|
|
721
|
+
stack.length = list + 1;
|
|
722
|
+
}
|
|
723
|
+
if (name === "a") closeTo("a");
|
|
724
|
+
const el = { tag: name, children: [] };
|
|
725
|
+
if (name === "a") {
|
|
726
|
+
const href = tag.attrs.get("href");
|
|
727
|
+
el.href = href === void 0 ? null : safeUrl7(decode(href).trim(), "href", { mediaOrigin });
|
|
728
|
+
}
|
|
729
|
+
nodes += 1;
|
|
730
|
+
top().children.push(el);
|
|
731
|
+
if (!VOID.has(name) && stack.length < MAX_DEPTH2) stack.push(el);
|
|
732
|
+
}
|
|
733
|
+
if (nodes > MAX_NODES) root.truncated = true;
|
|
734
|
+
return root;
|
|
735
|
+
}
|
|
736
|
+
function toReact(el, key) {
|
|
737
|
+
const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
|
|
738
|
+
if (el.tag === "br") return /* @__PURE__ */ jsx13("br", {}, key);
|
|
739
|
+
if (el.tag === "a") {
|
|
740
|
+
if (el.href === null || el.href === void 0) return /* @__PURE__ */ jsx13(Fragment10, { children }, key);
|
|
741
|
+
return /* @__PURE__ */ jsx13("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
|
|
742
|
+
}
|
|
743
|
+
return createElement(el.tag, { key }, ...children);
|
|
744
|
+
}
|
|
745
|
+
function RichText({
|
|
746
|
+
html,
|
|
747
|
+
mediaOrigin,
|
|
748
|
+
className,
|
|
749
|
+
editMode = false
|
|
750
|
+
}) {
|
|
751
|
+
const tree = parseRichText(html, mediaOrigin);
|
|
752
|
+
return /* @__PURE__ */ jsxs10("div", { className, children: [
|
|
753
|
+
tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
|
|
754
|
+
editMode && tree.truncated === true && /* @__PURE__ */ jsx13("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." })
|
|
755
|
+
] });
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/basics/text.tsx
|
|
759
|
+
import { Fragment as Fragment11, jsx as jsx14, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
760
|
+
function Text({ props, mediaOrigin, editMode, inlineEdit }) {
|
|
761
|
+
const editor = inlineEdit?.("html") ?? null;
|
|
762
|
+
return /* @__PURE__ */ jsxs11(Fragment11, { children: [
|
|
763
|
+
/* @__PURE__ */ jsx14(BasicStyles, {}),
|
|
764
|
+
editor === null ? /* @__PURE__ */ jsx14(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ jsx14("div", { className: "tb-b-text", children: editor })
|
|
765
|
+
] });
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/basics/video.tsx
|
|
769
|
+
import { useState as useState3 } from "react";
|
|
770
|
+
import { Icon as Icon3 } from "@usethrottle/ui";
|
|
771
|
+
import { Fragment as Fragment12, jsx as jsx15, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
772
|
+
var RULES3 = [
|
|
773
|
+
{ key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
|
|
774
|
+
];
|
|
775
|
+
var YOUTUBE_ID = /^[A-Za-z0-9_-]{11}$/;
|
|
776
|
+
var VIMEO_ID = /^\d{5,12}$/;
|
|
777
|
+
var YOUTUBE_HOSTS = /* @__PURE__ */ new Set(["youtube.com", "www.youtube.com", "m.youtube.com", "youtube-nocookie.com", "www.youtube-nocookie.com"]);
|
|
778
|
+
var VIMEO_HOSTS = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com", "player.vimeo.com"]);
|
|
779
|
+
function parseVideoUrl(input) {
|
|
780
|
+
let url;
|
|
781
|
+
try {
|
|
782
|
+
url = new URL(input.trim());
|
|
783
|
+
} catch {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
if (url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" && url.port !== "443") return null;
|
|
787
|
+
const host = url.hostname.toLowerCase();
|
|
788
|
+
const parts = url.pathname.split("/").filter((part) => part !== "");
|
|
789
|
+
if (host === "youtu.be") {
|
|
790
|
+
const id = parts[0];
|
|
791
|
+
return parts.length === 1 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
|
|
792
|
+
}
|
|
793
|
+
if (YOUTUBE_HOSTS.has(host)) {
|
|
794
|
+
if (parts[0] === "watch" && parts.length === 1) {
|
|
795
|
+
const id2 = url.searchParams.get("v");
|
|
796
|
+
return id2 !== null && YOUTUBE_ID.test(id2) ? { provider: "youtube", id: id2 } : null;
|
|
797
|
+
}
|
|
798
|
+
const id = parts[1];
|
|
799
|
+
return (parts[0] === "embed" || parts[0] === "shorts" || parts[0] === "live") && parts.length === 2 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
|
|
800
|
+
}
|
|
801
|
+
if (VIMEO_HOSTS.has(host)) {
|
|
802
|
+
const id = host === "player.vimeo.com" ? parts[0] === "video" && parts.length === 2 ? parts[1] : void 0 : parts.length === 1 ? parts[0] : void 0;
|
|
803
|
+
return id !== void 0 && VIMEO_ID.test(id) ? { provider: "vimeo", id } : null;
|
|
804
|
+
}
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
function embedSrc(video, muted) {
|
|
808
|
+
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" : ""}`;
|
|
809
|
+
}
|
|
810
|
+
function Video({ node, props, editMode }) {
|
|
811
|
+
const [loaded, setLoaded] = useState3(false);
|
|
812
|
+
const video = parseVideoUrl(str(props.url) ?? "");
|
|
813
|
+
return /* @__PURE__ */ jsxs12(Fragment12, { children: [
|
|
814
|
+
/* @__PURE__ */ jsx15(BasicStyles, {}),
|
|
815
|
+
/* @__PURE__ */ jsx15(WidgetStyle, { css: enumCss(node, RULES3) }),
|
|
816
|
+
video === null ? /* @__PURE__ */ jsx15(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ jsx15("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ jsx15(
|
|
817
|
+
"iframe",
|
|
818
|
+
{
|
|
819
|
+
src: embedSrc(video, props.autoplayMuted === true),
|
|
820
|
+
title: "Video",
|
|
821
|
+
allow: "autoplay; encrypted-media; picture-in-picture; fullscreen",
|
|
822
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
823
|
+
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
|
|
824
|
+
}
|
|
825
|
+
) : /* @__PURE__ */ jsx15("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ jsx15("span", { children: /* @__PURE__ */ jsx15(Icon3, { name: "play", size: 28 }) }) }) })
|
|
826
|
+
] });
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// src/basics/index.ts
|
|
830
|
+
var BASIC_COMPONENTS = {
|
|
831
|
+
"basic.heading": Heading,
|
|
832
|
+
"basic.text": Text,
|
|
833
|
+
"basic.image": Image,
|
|
834
|
+
"basic.button": Button,
|
|
835
|
+
"basic.spacer": Spacer,
|
|
836
|
+
"basic.divider": Divider,
|
|
837
|
+
"basic.video": Video,
|
|
838
|
+
"basic.logo": Logo,
|
|
839
|
+
"basic.menu": Menu,
|
|
840
|
+
"basic.announcement": Announcement,
|
|
841
|
+
"basic.copyright": Copyright
|
|
842
|
+
};
|
|
843
|
+
var widgets = BASIC_WIDGET_DEFINITIONS2.flatMap(
|
|
844
|
+
(definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
|
|
845
|
+
);
|
|
846
|
+
var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
|
|
847
|
+
|
|
848
|
+
// src/custom/factory.ts
|
|
849
|
+
import { createElement as createElement3 } from "react";
|
|
850
|
+
|
|
851
|
+
// src/custom/composite-widget.tsx
|
|
852
|
+
import { Suspense as Suspense2 } from "react";
|
|
853
|
+
import { pageDocumentSchema, validateSettingValue } from "@usethrottle/builder-schema";
|
|
854
|
+
|
|
855
|
+
// src/budget.ts
|
|
856
|
+
import { MAX_TEMPLATE_WEIGHT, templateWeight } from "@usethrottle/builder-schema";
|
|
857
|
+
var MAX_RENDERED_NODES = MAX_TEMPLATE_WEIGHT;
|
|
858
|
+
var RenderBudget = class {
|
|
859
|
+
constructor(limit = MAX_RENDERED_NODES) {
|
|
860
|
+
this.limit = limit;
|
|
861
|
+
__publicField(this, "spent", 0);
|
|
862
|
+
}
|
|
863
|
+
/** Takes `count` nodes. False, and nothing taken, when that would pass the limit. */
|
|
864
|
+
take(count = 1) {
|
|
865
|
+
if (this.spent + count > this.limit) return false;
|
|
866
|
+
this.spent += count;
|
|
867
|
+
return true;
|
|
868
|
+
}
|
|
869
|
+
get used() {
|
|
870
|
+
return this.spent;
|
|
871
|
+
}
|
|
872
|
+
get exhausted() {
|
|
873
|
+
return this.spent >= this.limit;
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
var fitsBudget = (ast, limit = MAX_RENDERED_NODES) => templateWeight(ast) <= limit;
|
|
877
|
+
|
|
878
|
+
// src/part-view.tsx
|
|
879
|
+
import { Component } from "react";
|
|
880
|
+
|
|
881
|
+
// src/renderer.tsx
|
|
882
|
+
import { Fragment as Fragment13 } from "react";
|
|
883
|
+
import {
|
|
884
|
+
COMMON_WIDGET_SETTINGS as COMMON_WIDGET_SETTINGS2,
|
|
885
|
+
resolveResponsive as resolveResponsive3,
|
|
886
|
+
safeUrl as safeUrl9,
|
|
887
|
+
upgradeNodes,
|
|
888
|
+
walkNodes as walkNodes2
|
|
889
|
+
} from "@usethrottle/builder-schema";
|
|
890
|
+
|
|
891
|
+
// src/css-compiler.ts
|
|
892
|
+
import {
|
|
893
|
+
COMMON_WIDGET_SETTINGS,
|
|
894
|
+
resolveColumnProps,
|
|
895
|
+
resolveColumnWidths,
|
|
896
|
+
resolveResponsive as resolveResponsive2,
|
|
897
|
+
safeUrl as safeUrl8,
|
|
898
|
+
wrapColumnRows
|
|
899
|
+
} from "@usethrottle/builder-schema";
|
|
900
|
+
var TABLET_QUERY = "(max-width:1024px)";
|
|
901
|
+
var PHONE_QUERY = "(max-width:767px)";
|
|
902
|
+
var SAFE_VALUE = /^[A-Za-z0-9#%.,()\-+*/_: ]{1,200}$/;
|
|
903
|
+
var URL_QUOTE_SAFE = /^[^\s"'\\()<>{};]+$/;
|
|
904
|
+
var ID_RE2 = /^[a-z0-9]{8,24}$/;
|
|
905
|
+
var PROPERTY_RE = /^--(?:b|w|tb)-[A-Za-z][A-Za-z0-9-]{0,39}$/;
|
|
906
|
+
var COLOR_TOKEN = /* @__PURE__ */ new Set([
|
|
907
|
+
"primary",
|
|
908
|
+
"primary-foreground",
|
|
909
|
+
"background",
|
|
910
|
+
"surface",
|
|
911
|
+
"foreground",
|
|
912
|
+
"muted",
|
|
913
|
+
"muted-foreground",
|
|
914
|
+
"border",
|
|
915
|
+
"border-control",
|
|
916
|
+
"accent",
|
|
917
|
+
"sale",
|
|
918
|
+
"success",
|
|
919
|
+
"warning",
|
|
920
|
+
"danger"
|
|
921
|
+
]);
|
|
922
|
+
var SPACING_TOKEN = /* @__PURE__ */ new Set(["xs", "s", "m", "l", "xl", "2xl"]);
|
|
923
|
+
var SIZE_TOKEN = /* @__PURE__ */ new Set(["xs", "s", "m", "l", "xl", "2xl", "3xl"]);
|
|
924
|
+
var ALIGN = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]);
|
|
925
|
+
var SELECT_OPTION = /^[a-z0-9][a-z0-9:-]{0,39}$/;
|
|
926
|
+
var px = (value) => `${String(Math.round(value * 100) / 100)}px`;
|
|
927
|
+
function colour(value) {
|
|
928
|
+
if (typeof value !== "string") return null;
|
|
929
|
+
if (value.startsWith("token:")) {
|
|
930
|
+
const name = value.slice(6);
|
|
931
|
+
return COLOR_TOKEN.has(name) ? `var(--tb-color-${name})` : null;
|
|
932
|
+
}
|
|
933
|
+
return /^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/.test(value) ? value : null;
|
|
934
|
+
}
|
|
935
|
+
function spacing(value) {
|
|
936
|
+
if (value === "none") return "0px";
|
|
937
|
+
if (typeof value === "string") return SPACING_TOKEN.has(value) ? `var(--tb-space-${value})` : null;
|
|
938
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 400 ? px(value) : null;
|
|
939
|
+
}
|
|
940
|
+
function fontSize(value) {
|
|
941
|
+
if (typeof value === "string") return SIZE_TOKEN.has(value) ? `var(--tb-text-${value})` : null;
|
|
942
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 8 && value <= 200 ? px(value) : null;
|
|
943
|
+
}
|
|
944
|
+
function cssValue(control, value) {
|
|
945
|
+
switch (control) {
|
|
946
|
+
case "color":
|
|
947
|
+
return colour(value);
|
|
948
|
+
case "spacing":
|
|
949
|
+
return spacing(value);
|
|
950
|
+
case "font-size":
|
|
951
|
+
return fontSize(value);
|
|
952
|
+
case "alignment":
|
|
953
|
+
return typeof value === "string" && ALIGN.has(value) ? value : null;
|
|
954
|
+
case "number":
|
|
955
|
+
return typeof value === "number" && Number.isFinite(value) ? String(value) : null;
|
|
956
|
+
case "toggle":
|
|
957
|
+
return typeof value === "boolean" ? value ? "1" : "0" : null;
|
|
958
|
+
case "select":
|
|
959
|
+
return typeof value === "string" && SELECT_OPTION.test(value) ? value : null;
|
|
960
|
+
default:
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function put(out, property, value) {
|
|
965
|
+
if (value === null) return;
|
|
966
|
+
if (!PROPERTY_RE.test(property) || !SAFE_VALUE.test(value)) {
|
|
967
|
+
if (isDevelopment()) warnOnce(`css:${property}`, `Dropped an unsafe value for ${property}`);
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
out.set(property, value);
|
|
971
|
+
}
|
|
972
|
+
var COMMON_BY_KEY = new Map(COMMON_WIDGET_SETTINGS.map((field) => [field.key, field]));
|
|
973
|
+
function widgetDecls(node, device, registry) {
|
|
974
|
+
const out = /* @__PURE__ */ new Map();
|
|
975
|
+
const def = registry.widget(node.type, node.v);
|
|
976
|
+
if (def === void 0) return out;
|
|
977
|
+
const fields = new Map([...COMMON_BY_KEY, ...def.settings.map((f) => [f.key, f])]);
|
|
978
|
+
const defaults = {};
|
|
979
|
+
for (const field of fields.values()) if (field.output === "css") defaults[field.key] = field.default;
|
|
980
|
+
const resolved = resolveResponsive2({ ...defaults, ...node.props }, node.responsive, device);
|
|
981
|
+
const prefix = node.type.startsWith("custom.") ? "--w-" : "--b-";
|
|
982
|
+
for (const field of fields.values()) {
|
|
983
|
+
if (field.output !== "css") continue;
|
|
984
|
+
const value = resolved[field.key];
|
|
985
|
+
if (value === null || value === void 0) continue;
|
|
986
|
+
if (field.key === "hidden") {
|
|
987
|
+
if (value === true) put(out, "--tb-hide", "none");
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
put(out, `${prefix}${field.key}`, cssValue(field.control, value));
|
|
991
|
+
}
|
|
992
|
+
return out;
|
|
993
|
+
}
|
|
994
|
+
var ALIGN_ITEMS = { top: "flex-start", center: "center", bottom: "flex-end", stretch: "stretch" };
|
|
995
|
+
var BG_POSITION = /* @__PURE__ */ new Set(["center", "top", "bottom", "left", "right", "top left", "top right", "bottom left", "bottom right"]);
|
|
996
|
+
var BG_SIZE = /* @__PURE__ */ new Set(["cover", "contain", "auto"]);
|
|
997
|
+
function backgroundDecls(out, bg, assets, mediaOrigin) {
|
|
998
|
+
if (bg === void 0) return;
|
|
999
|
+
put(out, "--tb-bg", bg.color === void 0 ? null : colour(bg.color));
|
|
1000
|
+
put(out, "--tb-overlay", bg.overlay === void 0 ? null : colour(bg.overlay));
|
|
1001
|
+
if (bg.position !== void 0 && BG_POSITION.has(bg.position)) put(out, "--tb-bgpos", bg.position);
|
|
1002
|
+
if (bg.size !== void 0 && BG_SIZE.has(bg.size)) put(out, "--tb-bgsize", bg.size);
|
|
1003
|
+
const asset = bg.image === void 0 || assets === void 0 || !Object.hasOwn(assets, bg.image) ? void 0 : assets[bg.image];
|
|
1004
|
+
if (asset !== void 0 && safeUrl8(asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
|
|
1005
|
+
out.set("--tb-bgimg", `url("${asset.url}")`);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
function sectionDecls(section, device, assets, mediaOrigin) {
|
|
1009
|
+
const out = /* @__PURE__ */ new Map();
|
|
1010
|
+
const p = resolveResponsive2(section.props, section.responsive, device);
|
|
1011
|
+
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
1012
|
+
const full = p.width === "full";
|
|
1013
|
+
put(out, "--tb-maxw", full ? "none" : px(typeof p.contentWidth === "number" ? p.contentWidth : 1200));
|
|
1014
|
+
put(out, "--tb-gap", p.gap === void 0 ? null : spacing(p.gap));
|
|
1015
|
+
put(out, "--tb-pady", p.paddingY === void 0 ? null : spacing(p.paddingY));
|
|
1016
|
+
put(out, "--tb-padx", p.paddingX === void 0 ? null : spacing(p.paddingX));
|
|
1017
|
+
if (typeof p.minHeight === "number" && p.minHeight > 0 && p.minHeight <= 2e3) put(out, "--tb-minh", px(p.minHeight));
|
|
1018
|
+
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-valign", ALIGN_ITEMS[p.verticalAlign]);
|
|
1019
|
+
backgroundDecls(out, p.background, assets, mediaOrigin);
|
|
1020
|
+
const widths = resolveColumnWidths(section, device);
|
|
1021
|
+
const rows = wrapColumnRows(widths);
|
|
1022
|
+
const stacked = rows.every((row) => row.length === 1);
|
|
1023
|
+
put(out, "--tb-flow", stacked && p.stackOrder === "reverse" ? "column-reverse nowrap" : "row wrap");
|
|
1024
|
+
return out;
|
|
1025
|
+
}
|
|
1026
|
+
function columnWidthDecls(section, device) {
|
|
1027
|
+
const widths = resolveColumnWidths(section, device);
|
|
1028
|
+
const result = section.columns.map(() => /* @__PURE__ */ new Map());
|
|
1029
|
+
for (const row of wrapColumnRows(widths)) {
|
|
1030
|
+
for (const index of row) {
|
|
1031
|
+
put(result[index], "--tb-cw", String(Math.round(widths[index] / 100 * 1e4) / 1e4));
|
|
1032
|
+
put(result[index], "--tb-cn", String(row.length - 1));
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return result;
|
|
1036
|
+
}
|
|
1037
|
+
function columnDecls(section, index, device, assets, mediaOrigin, widths) {
|
|
1038
|
+
const column = section.columns[index];
|
|
1039
|
+
const out = new Map(widths);
|
|
1040
|
+
const p = resolveColumnProps(column.props, column.responsive, device);
|
|
1041
|
+
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
1042
|
+
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-self", ALIGN_ITEMS[p.verticalAlign]);
|
|
1043
|
+
put(out, "--tb-pad", p.padding === void 0 ? null : spacing(p.padding));
|
|
1044
|
+
backgroundDecls(out, p.background, assets, mediaOrigin);
|
|
1045
|
+
return out;
|
|
1046
|
+
}
|
|
1047
|
+
function collect(doc, registry, assets, mediaOrigin) {
|
|
1048
|
+
const nodes = [];
|
|
1049
|
+
const widget = (node) => {
|
|
1050
|
+
if (!ID_RE2.test(node.id)) return;
|
|
1051
|
+
nodes.push({
|
|
1052
|
+
id: node.id,
|
|
1053
|
+
decls: {
|
|
1054
|
+
desktop: widgetDecls(node, "desktop", registry),
|
|
1055
|
+
tablet: widgetDecls(node, "tablet", registry),
|
|
1056
|
+
phone: widgetDecls(node, "phone", registry)
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
1059
|
+
};
|
|
1060
|
+
const section = (node) => {
|
|
1061
|
+
if (ID_RE2.test(node.id)) {
|
|
1062
|
+
nodes.push({
|
|
1063
|
+
id: node.id,
|
|
1064
|
+
decls: {
|
|
1065
|
+
desktop: sectionDecls(node, "desktop", assets, mediaOrigin),
|
|
1066
|
+
tablet: sectionDecls(node, "tablet", assets, mediaOrigin),
|
|
1067
|
+
phone: sectionDecls(node, "phone", assets, mediaOrigin)
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
const widths = { desktop: columnWidthDecls(node, "desktop"), tablet: columnWidthDecls(node, "tablet"), phone: columnWidthDecls(node, "phone") };
|
|
1072
|
+
node.columns.forEach((column, index) => {
|
|
1073
|
+
if (ID_RE2.test(column.id)) {
|
|
1074
|
+
nodes.push({
|
|
1075
|
+
id: column.id,
|
|
1076
|
+
decls: {
|
|
1077
|
+
desktop: columnDecls(node, index, "desktop", assets, mediaOrigin, widths.desktop[index]),
|
|
1078
|
+
tablet: columnDecls(node, index, "tablet", assets, mediaOrigin, widths.tablet[index]),
|
|
1079
|
+
phone: columnDecls(node, index, "phone", assets, mediaOrigin, widths.phone[index])
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
for (const child of column.children) {
|
|
1084
|
+
if (child.type === "inner-section") section(child);
|
|
1085
|
+
else widget(child);
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
};
|
|
1089
|
+
doc.sections.forEach(section);
|
|
1090
|
+
return nodes;
|
|
1091
|
+
}
|
|
1092
|
+
var block = (id, decls) => {
|
|
1093
|
+
const body = [...decls].map(([property, value]) => `${property}:${value}`).join(";");
|
|
1094
|
+
return body === "" ? "" : `[data-b-id="${id}"]{${body}}`;
|
|
1095
|
+
};
|
|
1096
|
+
function changed(prev, next) {
|
|
1097
|
+
const out = [...next].filter(([property, value]) => prev.get(property) !== value);
|
|
1098
|
+
for (const property of prev.keys()) if (!next.has(property)) out.push([property, "initial"]);
|
|
1099
|
+
return out;
|
|
1100
|
+
}
|
|
1101
|
+
function compileResponsiveCss(doc, registry, assets = doc.assets, mediaOrigin = "") {
|
|
1102
|
+
const nodes = collect(doc, registry, assets, mediaOrigin);
|
|
1103
|
+
const base = nodes.map((n) => block(n.id, n.decls.desktop)).join("");
|
|
1104
|
+
const tablet = nodes.map((n) => block(n.id, changed(n.decls.desktop, n.decls.tablet))).join("");
|
|
1105
|
+
const phone = nodes.map((n) => block(n.id, changed(n.decls.tablet, n.decls.phone))).join("");
|
|
1106
|
+
return base + (tablet === "" ? "" : `@media ${TABLET_QUERY}{${tablet}}`) + (phone === "" ? "" : `@media ${PHONE_QUERY}{${phone}}`);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// src/node-wrapper.tsx
|
|
1110
|
+
import { ANCHOR_RE } from "@usethrottle/builder-schema";
|
|
1111
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
1112
|
+
var CUSTOM_WIDGET_CONTAINMENT = {
|
|
1113
|
+
contain: "layout paint",
|
|
1114
|
+
isolation: "isolate",
|
|
1115
|
+
overflow: "clip"
|
|
1116
|
+
};
|
|
1117
|
+
var PART_NAME = {
|
|
1118
|
+
section: "builder-section",
|
|
1119
|
+
column: "builder-column",
|
|
1120
|
+
widget: "builder-widget"
|
|
1121
|
+
};
|
|
1122
|
+
function NodeWrapper(props) {
|
|
1123
|
+
const { id, part, type, className, anchor, custom, missing, edit, children } = props;
|
|
1124
|
+
const Tag = props.as ?? "div";
|
|
1125
|
+
const handlers = edit === void 0 ? {} : {
|
|
1126
|
+
onClickCapture: (event) => {
|
|
1127
|
+
const target = event.target;
|
|
1128
|
+
if (target?.closest?.("a[href]") != null) event.preventDefault();
|
|
1129
|
+
},
|
|
1130
|
+
onClick: (event) => {
|
|
1131
|
+
event.stopPropagation();
|
|
1132
|
+
edit.onSelect(id);
|
|
1133
|
+
},
|
|
1134
|
+
onMouseOver: (event) => {
|
|
1135
|
+
event.stopPropagation();
|
|
1136
|
+
edit.onHover(id);
|
|
1137
|
+
},
|
|
1138
|
+
onMouseLeave: () => edit.onHover(null)
|
|
1139
|
+
};
|
|
1140
|
+
return /* @__PURE__ */ jsx16(
|
|
1141
|
+
Tag,
|
|
1142
|
+
{
|
|
1143
|
+
className,
|
|
1144
|
+
"data-b-id": id,
|
|
1145
|
+
"data-throttle-part": PART_NAME[part],
|
|
1146
|
+
...type === void 0 ? {} : { "data-b-type": type },
|
|
1147
|
+
...custom === true && type !== void 0 ? { "data-b-w": type } : {},
|
|
1148
|
+
...missing === true ? { "data-b-missing": "" } : {},
|
|
1149
|
+
...typeof anchor === "string" && ANCHOR_RE.test(anchor) ? { id: anchor } : {},
|
|
1150
|
+
...custom === true ? { style: CUSTOM_WIDGET_CONTAINMENT } : {},
|
|
1151
|
+
...handlers,
|
|
1152
|
+
children
|
|
1153
|
+
}
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// src/styles.ts
|
|
1158
|
+
var BASE_CSS = `@layer throttle{
|
|
1159
|
+
:root{--tb-scale:1;--tb-space-xs:calc(.25rem*var(--tb-scale));--tb-space-s:calc(.5rem*var(--tb-scale));--tb-space-m:calc(1rem*var(--tb-scale));--tb-space-l:calc(1.5rem*var(--tb-scale));--tb-space-xl:calc(2.5rem*var(--tb-scale));--tb-space-2xl:calc(4rem*var(--tb-scale));
|
|
1160
|
+
--tb-text-xs:.75rem;--tb-text-s:.875rem;--tb-text-m:1rem;--tb-text-l:1.25rem;--tb-text-xl:1.5rem;--tb-text-2xl:2rem;--tb-text-3xl:2.75rem}
|
|
1161
|
+
.tb-root{display:block;inline-size:100%}
|
|
1162
|
+
.tb-section,.tb-col,.tb-w{--tb-hide:initial}
|
|
1163
|
+
.tb-section,.tb-col{--tb-bg:initial;--tb-bgimg:initial;--tb-bgpos:initial;--tb-bgsize:initial;--tb-overlay:initial}
|
|
1164
|
+
.tb-section{--tb-valign:initial;--tb-minh:initial;--tb-pady:initial;--tb-padx:initial;--tb-gap:initial;--tb-maxw:initial;--tb-flow:initial}
|
|
1165
|
+
.tb-col{--tb-pad:initial;--tb-self:initial}
|
|
1166
|
+
.tb-section{box-sizing:border-box;position:relative;display:var(--tb-hide,flex);flex-direction:column;justify-content:var(--tb-valign,flex-start);min-block-size:var(--tb-minh,0px);padding-block:var(--tb-pady,0px);padding-inline:var(--tb-padx,0px);background-color:var(--tb-bg,transparent);background-image:var(--tb-bgimg,none);background-position:var(--tb-bgpos,center);background-size:var(--tb-bgsize,cover);background-repeat:no-repeat}
|
|
1167
|
+
.tb-section::before{content:"";position:absolute;inset:0;background:var(--tb-overlay,transparent);pointer-events:none}
|
|
1168
|
+
.tb-inner{box-sizing:border-box;position:relative;inline-size:100%;max-inline-size:var(--tb-maxw,1200px);margin-inline:auto}
|
|
1169
|
+
.tb-row{display:flex;flex-flow:var(--tb-flow,row wrap);gap:var(--tb-gap,0px);align-items:stretch}
|
|
1170
|
+
.tb-col{box-sizing:border-box;display:var(--tb-hide,flex);flex-direction:column;flex:0 0 auto;inline-size:calc((100% - var(--tb-cn,0)*var(--tb-gap,0px))*var(--tb-cw,1));min-inline-size:0;align-self:var(--tb-self,stretch);padding:var(--tb-pad,0px);background-color:var(--tb-bg,transparent);background-image:var(--tb-bgimg,none);background-position:var(--tb-bgpos,center);background-size:var(--tb-bgsize,cover);background-repeat:no-repeat}
|
|
1171
|
+
.tb-w{display:var(--tb-hide,block);min-inline-size:0;margin-block-start:var(--b-spacingTop,var(--w-spacingTop,0px));margin-block-end:var(--b-spacingBottom,var(--w-spacingBottom,0px))}
|
|
1172
|
+
.tb-missing{padding:var(--tb-space-s);border:1px dashed var(--tb-color-border-control,currentColor);font-size:var(--tb-text-s)}
|
|
1173
|
+
@media (min-width:1025px){.tb-v:not(.tb-only-desktop){display:none!important}}
|
|
1174
|
+
@media (min-width:768px) and (max-width:1024px){.tb-v:not(.tb-only-tablet){display:none!important}}
|
|
1175
|
+
@media (max-width:767px){.tb-v:not(.tb-only-phone){display:none!important}}
|
|
1176
|
+
}`;
|
|
1177
|
+
|
|
1178
|
+
// src/renderer.tsx
|
|
1179
|
+
import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1180
|
+
var DEVICES2 = ["desktop", "tablet", "phone"];
|
|
1181
|
+
var COMMON_BY_KEY2 = new Map(COMMON_WIDGET_SETTINGS2.map((f) => [f.key, f]));
|
|
1182
|
+
var withCustomCache = /* @__PURE__ */ new WeakMap();
|
|
1183
|
+
function registryFor(doc, base) {
|
|
1184
|
+
const snapshots = doc.customWidgets;
|
|
1185
|
+
if (snapshots === void 0) return base;
|
|
1186
|
+
let perDocument = withCustomCache.get(base);
|
|
1187
|
+
if (perDocument === void 0) {
|
|
1188
|
+
perDocument = /* @__PURE__ */ new WeakMap();
|
|
1189
|
+
withCustomCache.set(base, perDocument);
|
|
1190
|
+
}
|
|
1191
|
+
let registry = perDocument.get(snapshots);
|
|
1192
|
+
if (registry === void 0) {
|
|
1193
|
+
try {
|
|
1194
|
+
registry = base.withCustom(Object.values(snapshots));
|
|
1195
|
+
} catch (error) {
|
|
1196
|
+
warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
|
|
1197
|
+
registry = base;
|
|
1198
|
+
}
|
|
1199
|
+
perDocument.set(snapshots, registry);
|
|
1200
|
+
}
|
|
1201
|
+
return registry;
|
|
1202
|
+
}
|
|
1203
|
+
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1204
|
+
function pickLocale(value, locale) {
|
|
1205
|
+
const lang = locale.split("-")[0] ?? locale;
|
|
1206
|
+
for (const key of [locale, lang, "en"]) {
|
|
1207
|
+
const text = Object.hasOwn(value, key) ? value[key] : void 0;
|
|
1208
|
+
if (typeof text === "string" && text !== "") return text;
|
|
1209
|
+
}
|
|
1210
|
+
for (const text of Object.values(value)) if (typeof text === "string" && text !== "") return text;
|
|
1211
|
+
return "";
|
|
1212
|
+
}
|
|
1213
|
+
function onOrigin(asset, mediaOrigin) {
|
|
1214
|
+
if (safeUrl9(asset.url, "src", { mediaOrigin }) === null) return null;
|
|
1215
|
+
return { ...asset, variants: asset.variants.filter((v) => safeUrl9(v.url, "src", { mediaOrigin }) !== null) };
|
|
1216
|
+
}
|
|
1217
|
+
function prepare(field, value, ctx) {
|
|
1218
|
+
if (field === void 0 || value === null) return value;
|
|
1219
|
+
if (field.translatable === true && isRecord2(value)) return pickLocale(value, ctx.locale);
|
|
1220
|
+
if (field.control === "image" && typeof value === "string") {
|
|
1221
|
+
const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
|
|
1222
|
+
return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
|
|
1223
|
+
}
|
|
1224
|
+
if (field.control === "link" && isRecord2(value) && typeof value.kind === "string") {
|
|
1225
|
+
const target = value;
|
|
1226
|
+
const raw = ctx.resolveLink?.(target) ?? (target.kind === "url" ? target.href : null);
|
|
1227
|
+
return { ...value, href: safeUrl9(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
|
|
1228
|
+
}
|
|
1229
|
+
return value;
|
|
1230
|
+
}
|
|
1231
|
+
function settingsAt(node, fields, device, ctx) {
|
|
1232
|
+
const base = {};
|
|
1233
|
+
for (const field of fields.values()) base[field.key] = field.default;
|
|
1234
|
+
const resolved = resolveResponsive3({ ...base, ...node.props }, node.responsive, device);
|
|
1235
|
+
const out = {};
|
|
1236
|
+
for (const [key, value] of Object.entries(resolved)) out[key] = prepare(fields.get(key), value, ctx);
|
|
1237
|
+
return out;
|
|
1238
|
+
}
|
|
1239
|
+
function variantsOf(node, def, fields, ctx) {
|
|
1240
|
+
const markup = [...fields.values()].filter((f) => f.output === "markup").map((f) => f.key);
|
|
1241
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1242
|
+
for (const device of DEVICES2) {
|
|
1243
|
+
const props = settingsAt(node, fields, device, ctx);
|
|
1244
|
+
const signature = stable(markup.map((key) => props[key] ?? null));
|
|
1245
|
+
const group = groups.get(signature);
|
|
1246
|
+
if (group === void 0) groups.set(signature, { devices: [device], props });
|
|
1247
|
+
else group.devices.push(device);
|
|
1248
|
+
}
|
|
1249
|
+
void def;
|
|
1250
|
+
return [...groups.values()];
|
|
1251
|
+
}
|
|
1252
|
+
function hiddenEverywhere(props, responsive) {
|
|
1253
|
+
return DEVICES2.every(
|
|
1254
|
+
(device) => resolveResponsive3({ hidden: props.hidden ?? false }, responsive, device).hidden === true
|
|
1255
|
+
);
|
|
1256
|
+
}
|
|
1257
|
+
var variantClass = (variant) => `tb-v ${variant.devices.map((d) => `tb-only-${d}`).join(" ")}`;
|
|
1258
|
+
function renderWidget(node, ctx, registry) {
|
|
1259
|
+
const def = registry.widget(node.type, node.v);
|
|
1260
|
+
const Component2 = def === void 0 ? void 0 : registry.component(node);
|
|
1261
|
+
if (def === void 0 || Component2 === void 0) {
|
|
1262
|
+
if (isDevelopment()) {
|
|
1263
|
+
warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
|
|
1264
|
+
}
|
|
1265
|
+
return /* @__PURE__ */ jsx17(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ jsx17("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
|
|
1266
|
+
}
|
|
1267
|
+
if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
|
|
1268
|
+
const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
|
|
1269
|
+
const variants = variantsOf(node, def, fields, ctx);
|
|
1270
|
+
const data = {};
|
|
1271
|
+
for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
|
|
1272
|
+
const key = bindingKey(binding);
|
|
1273
|
+
const value = Object.hasOwn(ctx.data, key) ? ctx.data[key] : void 0;
|
|
1274
|
+
if (value !== void 0) data[name] = value;
|
|
1275
|
+
}
|
|
1276
|
+
const custom = node.type.startsWith("custom.");
|
|
1277
|
+
const edit = ctx.edit;
|
|
1278
|
+
return variants.map((variant, index) => {
|
|
1279
|
+
const anchor = variant.props.anchor;
|
|
1280
|
+
return /* @__PURE__ */ jsx17(
|
|
1281
|
+
NodeWrapper,
|
|
1282
|
+
{
|
|
1283
|
+
id: node.id,
|
|
1284
|
+
part: "widget",
|
|
1285
|
+
type: node.type,
|
|
1286
|
+
custom,
|
|
1287
|
+
edit,
|
|
1288
|
+
className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
|
|
1289
|
+
anchor: index === 0 && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
1290
|
+
children: /* @__PURE__ */ jsx17(
|
|
1291
|
+
Component2,
|
|
1292
|
+
{
|
|
1293
|
+
node,
|
|
1294
|
+
props: variant.props,
|
|
1295
|
+
data,
|
|
1296
|
+
editMode: edit !== void 0,
|
|
1297
|
+
locale: ctx.locale,
|
|
1298
|
+
mediaOrigin: ctx.mediaOrigin,
|
|
1299
|
+
resolveLink: ctx.resolveLink,
|
|
1300
|
+
inlineEdit: edit === void 0 ? void 0 : (key) => edit.inlineEdit(node.id, key),
|
|
1301
|
+
budget: custom ? new RenderBudget() : void 0
|
|
1302
|
+
}
|
|
1303
|
+
)
|
|
1304
|
+
},
|
|
1305
|
+
variant.devices.join("-")
|
|
1306
|
+
);
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
function renderColumn(column, ctx, registry) {
|
|
1310
|
+
if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
|
|
1311
|
+
return /* @__PURE__ */ jsx17(
|
|
1312
|
+
NodeWrapper,
|
|
1313
|
+
{
|
|
1314
|
+
id: column.id,
|
|
1315
|
+
part: "column",
|
|
1316
|
+
className: "tb-col",
|
|
1317
|
+
anchor: column.props.anchor,
|
|
1318
|
+
edit: ctx.edit,
|
|
1319
|
+
children: column.children.map(
|
|
1320
|
+
(child) => child.type === "inner-section" ? /* @__PURE__ */ jsx17(Fragment13, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ jsx17(Fragment13, { children: renderWidget(child, ctx, registry) }, child.id)
|
|
1321
|
+
)
|
|
1322
|
+
},
|
|
1323
|
+
column.id
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
function renderSection(section, ctx, registry, nested = false) {
|
|
1327
|
+
if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
|
|
1328
|
+
return /* @__PURE__ */ jsx17(
|
|
1329
|
+
NodeWrapper,
|
|
1330
|
+
{
|
|
1331
|
+
id: section.id,
|
|
1332
|
+
part: "section",
|
|
1333
|
+
as: nested ? "div" : "section",
|
|
1334
|
+
className: nested ? "tb-section tb-nested" : "tb-section",
|
|
1335
|
+
anchor: section.props.anchor,
|
|
1336
|
+
edit: ctx.edit,
|
|
1337
|
+
children: /* @__PURE__ */ jsx17("div", { className: "tb-inner", children: /* @__PURE__ */ jsx17("div", { className: "tb-row", children: section.columns.map((column) => renderColumn(column, ctx, registry)) }) })
|
|
1338
|
+
}
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
function BuilderRenderer(props) {
|
|
1342
|
+
const { document: source, registry: base, data, editMode, locale, assets, resolveLink } = props;
|
|
1343
|
+
const registry = registryFor(source, base);
|
|
1344
|
+
const { doc } = upgradeNodes(source, registry);
|
|
1345
|
+
const mediaOrigin = props.mediaOrigin ?? "";
|
|
1346
|
+
const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, edit: editMode };
|
|
1347
|
+
const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
|
|
1348
|
+
return /* @__PURE__ */ jsxs13("div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
|
|
1349
|
+
/* @__PURE__ */ jsx17("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
1350
|
+
css === "" ? null : /* @__PURE__ */ jsx17("style", { children: css }),
|
|
1351
|
+
doc.sections.map((section) => /* @__PURE__ */ jsx17(Fragment13, { children: renderSection(section, ctx, registry) }, section.id))
|
|
1352
|
+
] });
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
// src/part-view.tsx
|
|
1356
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
1357
|
+
var PartBoundary = class extends Component {
|
|
1358
|
+
constructor() {
|
|
1359
|
+
super(...arguments);
|
|
1360
|
+
__publicField(this, "state", { failed: false });
|
|
1361
|
+
}
|
|
1362
|
+
static getDerivedStateFromError() {
|
|
1363
|
+
return { failed: true };
|
|
1364
|
+
}
|
|
1365
|
+
componentDidCatch(error, _info) {
|
|
1366
|
+
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
1367
|
+
}
|
|
1368
|
+
render() {
|
|
1369
|
+
return this.state.failed ? null : this.props.children;
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
// src/custom/template-widget.tsx
|
|
1374
|
+
import { Suspense } from "react";
|
|
1375
|
+
import { MAX_TEMPLATE_WEIGHT as MAX_TEMPLATE_WEIGHT2, parseTemplate, templateWeight as templateWeight2, validateTemplate } from "@usethrottle/builder-schema";
|
|
1376
|
+
|
|
1377
|
+
// src/custom/custom-css.tsx
|
|
1378
|
+
import { sanitizeWidgetCss } from "@usethrottle/builder-schema";
|
|
1379
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
1380
|
+
function scopedCss(source, type) {
|
|
1381
|
+
if (source === void 0 || source === "") return "";
|
|
1382
|
+
if (typeof source !== "string") return null;
|
|
1383
|
+
const result = sanitizeWidgetCss(source, type);
|
|
1384
|
+
return result.ok ? result.css : null;
|
|
1385
|
+
}
|
|
1386
|
+
function CustomCss({ css }) {
|
|
1387
|
+
return /* @__PURE__ */ jsx19(WidgetStyle, { css });
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// src/custom/interpreter.tsx
|
|
1391
|
+
import { Fragment as Fragment14, createElement as createElement2 } from "react";
|
|
1392
|
+
import {
|
|
1393
|
+
ALLOWED_ATTRS,
|
|
1394
|
+
ALLOWED_ELEMENTS,
|
|
1395
|
+
ALLOWED_ROLES,
|
|
1396
|
+
CLASS_TOKEN_RE,
|
|
1397
|
+
DATA_ATTR_RE,
|
|
1398
|
+
EACH_ITERATION_CAP,
|
|
1399
|
+
RESERVED_DATA_PREFIX,
|
|
1400
|
+
VOID_ELEMENTS,
|
|
1401
|
+
isReservedClass,
|
|
1402
|
+
safeUrl as safeUrl10
|
|
1403
|
+
} from "@usethrottle/builder-schema";
|
|
1404
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
1405
|
+
var MAX_OUTPUT_CHARS = 1e6;
|
|
1406
|
+
var MAX_ATTR_CHARS = 2e3;
|
|
1407
|
+
var MAX_DEPTH3 = 24;
|
|
1408
|
+
function newEnv(env) {
|
|
1409
|
+
return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
|
|
1410
|
+
}
|
|
1411
|
+
var BLOCKED = /* @__PURE__ */ new Set([
|
|
1412
|
+
"__proto__",
|
|
1413
|
+
"constructor",
|
|
1414
|
+
"prototype",
|
|
1415
|
+
...Object.getOwnPropertyNames(Object.prototype)
|
|
1416
|
+
]);
|
|
1417
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1418
|
+
function step(value, key) {
|
|
1419
|
+
if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
|
|
1420
|
+
return value[key];
|
|
1421
|
+
}
|
|
1422
|
+
function lookup(path, env, scope) {
|
|
1423
|
+
const [root, ...rest] = path;
|
|
1424
|
+
if (root === void 0) return void 0;
|
|
1425
|
+
if (root === "locale") return rest.length === 0 ? env.locale : void 0;
|
|
1426
|
+
let value;
|
|
1427
|
+
if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
|
|
1428
|
+
else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
|
|
1429
|
+
else if (scope.has(root)) value = scope.get(root);
|
|
1430
|
+
else return void 0;
|
|
1431
|
+
for (const key of rest) {
|
|
1432
|
+
value = step(value, key);
|
|
1433
|
+
if (value === void 0) return void 0;
|
|
1434
|
+
}
|
|
1435
|
+
return value;
|
|
1436
|
+
}
|
|
1437
|
+
function truthy(value) {
|
|
1438
|
+
if (value === null || value === void 0 || value === false || value === "") return false;
|
|
1439
|
+
if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
|
|
1440
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
1441
|
+
return true;
|
|
1442
|
+
}
|
|
1443
|
+
function asText(value) {
|
|
1444
|
+
if (typeof value === "string") return value;
|
|
1445
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
1446
|
+
return "";
|
|
1447
|
+
}
|
|
1448
|
+
function filtered(value, filters) {
|
|
1449
|
+
let text = asText(value);
|
|
1450
|
+
for (const filter of filters) {
|
|
1451
|
+
switch (filter.name) {
|
|
1452
|
+
case "upper":
|
|
1453
|
+
text = text.toUpperCase();
|
|
1454
|
+
break;
|
|
1455
|
+
case "lower":
|
|
1456
|
+
text = text.toLowerCase();
|
|
1457
|
+
break;
|
|
1458
|
+
case "truncate": {
|
|
1459
|
+
const chars = Array.from(text);
|
|
1460
|
+
if (chars.length > filter.n) text = `${chars.slice(0, filter.n).join("")}\u2026`;
|
|
1461
|
+
break;
|
|
1462
|
+
}
|
|
1463
|
+
case "default":
|
|
1464
|
+
if (text === "") text = filter.text;
|
|
1465
|
+
break;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
return text;
|
|
1469
|
+
}
|
|
1470
|
+
function spend(env, count) {
|
|
1471
|
+
if (count > env.charsLeft) {
|
|
1472
|
+
env.stopped = true;
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
env.charsLeft -= count;
|
|
1476
|
+
return true;
|
|
1477
|
+
}
|
|
1478
|
+
var ELEMENTS = new Set(ALLOWED_ELEMENTS);
|
|
1479
|
+
var VOIDS = new Set(VOID_ELEMENTS);
|
|
1480
|
+
var ROLES = new Set(ALLOWED_ROLES);
|
|
1481
|
+
function attrAllowed(tag, name) {
|
|
1482
|
+
if (DATA_ATTR_RE.test(name)) return !name.startsWith(RESERVED_DATA_PREFIX);
|
|
1483
|
+
const own = Object.hasOwn(ALLOWED_ATTRS, tag) ? ALLOWED_ATTRS[tag] : void 0;
|
|
1484
|
+
return (ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
|
|
1485
|
+
}
|
|
1486
|
+
function attrText(attr, env, scope) {
|
|
1487
|
+
return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
|
|
1488
|
+
}
|
|
1489
|
+
function urlSource(attr, env, scope) {
|
|
1490
|
+
const [only] = attr.value;
|
|
1491
|
+
if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
|
|
1492
|
+
const value = lookup(only.path, env, scope);
|
|
1493
|
+
if (isPlainObject(value)) {
|
|
1494
|
+
if (typeof value.href === "string") return value.href;
|
|
1495
|
+
if (typeof value.url === "string") return value.url;
|
|
1496
|
+
return null;
|
|
1497
|
+
}
|
|
1498
|
+
return value;
|
|
1499
|
+
}
|
|
1500
|
+
function attrProp(tag, attr, env, scope) {
|
|
1501
|
+
const { name } = attr;
|
|
1502
|
+
if (!attrAllowed(tag, name)) return null;
|
|
1503
|
+
if (name === "href" || name === "src") {
|
|
1504
|
+
const safe = safeUrl10(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
|
|
1505
|
+
return safe === null || !spend(env, safe.length) ? null : [name, safe];
|
|
1506
|
+
}
|
|
1507
|
+
const text = attrText(attr, env, scope);
|
|
1508
|
+
if (text === "" || text.length > MAX_ATTR_CHARS) return null;
|
|
1509
|
+
let value = text;
|
|
1510
|
+
if (name === "class") {
|
|
1511
|
+
const tokens = text.split(/\s+/).filter((token) => CLASS_TOKEN_RE.test(token) && !isReservedClass(token));
|
|
1512
|
+
if (tokens.length === 0) return null;
|
|
1513
|
+
value = tokens.join(" ");
|
|
1514
|
+
} else if (name === "role") {
|
|
1515
|
+
if (!ROLES.has(text)) return null;
|
|
1516
|
+
} else if (name === "aria-hidden") {
|
|
1517
|
+
if (text !== "true" && text !== "false") return null;
|
|
1518
|
+
}
|
|
1519
|
+
if (!spend(env, value.length)) return null;
|
|
1520
|
+
return [name === "class" ? "className" : name, value];
|
|
1521
|
+
}
|
|
1522
|
+
function renderElement(node, env, scope, depth, key) {
|
|
1523
|
+
const tag = node.tag;
|
|
1524
|
+
if (!ELEMENTS.has(tag)) return null;
|
|
1525
|
+
const props = { key };
|
|
1526
|
+
for (const attr of node.attrs) {
|
|
1527
|
+
const prop = attrProp(tag, attr, env, scope);
|
|
1528
|
+
if (prop !== null) props[prop[0]] = prop[1];
|
|
1529
|
+
}
|
|
1530
|
+
if (VOIDS.has(tag)) return createElement2(tag, props);
|
|
1531
|
+
return createElement2(tag, props, renderNodes(node.children, env, scope, depth + 1));
|
|
1532
|
+
}
|
|
1533
|
+
function renderNodes(nodes, env, scope, depth) {
|
|
1534
|
+
const out = [];
|
|
1535
|
+
if (depth > MAX_DEPTH3) return out;
|
|
1536
|
+
for (const node of nodes) {
|
|
1537
|
+
if (env.stopped) break;
|
|
1538
|
+
if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
|
|
1539
|
+
env.stopped = true;
|
|
1540
|
+
break;
|
|
1541
|
+
}
|
|
1542
|
+
switch (node.type) {
|
|
1543
|
+
case "text":
|
|
1544
|
+
if (spend(env, node.value.length)) out.push(node.value);
|
|
1545
|
+
break;
|
|
1546
|
+
case "output": {
|
|
1547
|
+
const text = filtered(lookup(node.path, env, scope), node.filters);
|
|
1548
|
+
if (text !== "" && spend(env, text.length)) out.push(text);
|
|
1549
|
+
break;
|
|
1550
|
+
}
|
|
1551
|
+
case "if": {
|
|
1552
|
+
const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
|
|
1553
|
+
out.push(/* @__PURE__ */ jsx20(Fragment14, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
|
|
1554
|
+
break;
|
|
1555
|
+
}
|
|
1556
|
+
case "unless":
|
|
1557
|
+
if (!truthy(lookup(node.path, env, scope))) {
|
|
1558
|
+
out.push(/* @__PURE__ */ jsx20(Fragment14, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
|
|
1559
|
+
}
|
|
1560
|
+
break;
|
|
1561
|
+
case "each": {
|
|
1562
|
+
const list = lookup(node.path, env, scope);
|
|
1563
|
+
if (!Array.isArray(list)) break;
|
|
1564
|
+
const count = Math.min(list.length, EACH_ITERATION_CAP);
|
|
1565
|
+
for (let i = 0; i < count && !env.stopped; i += 1) {
|
|
1566
|
+
const inner = new Map(scope).set(node.as, list[i]);
|
|
1567
|
+
out.push(/* @__PURE__ */ jsx20(Fragment14, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
|
|
1568
|
+
}
|
|
1569
|
+
break;
|
|
1570
|
+
}
|
|
1571
|
+
case "element":
|
|
1572
|
+
out.push(renderElement(node, env, scope, depth, out.length));
|
|
1573
|
+
break;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
return out;
|
|
1577
|
+
}
|
|
1578
|
+
function renderTemplate(ast, env) {
|
|
1579
|
+
return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
// src/custom/template-widget.tsx
|
|
1583
|
+
import { Fragment as Fragment15, jsx as jsx21, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1584
|
+
var componentWeights = /* @__PURE__ */ new WeakMap();
|
|
1585
|
+
var compiled = /* @__PURE__ */ new WeakMap();
|
|
1586
|
+
function compileTemplate(snapshot, registry) {
|
|
1587
|
+
let perRegistry = compiled.get(snapshot);
|
|
1588
|
+
if (perRegistry === void 0) {
|
|
1589
|
+
perRegistry = /* @__PURE__ */ new WeakMap();
|
|
1590
|
+
compiled.set(snapshot, perRegistry);
|
|
1591
|
+
}
|
|
1592
|
+
if (perRegistry.has(registry)) return perRegistry.get(registry) ?? null;
|
|
1593
|
+
const result = compile(snapshot, registry);
|
|
1594
|
+
perRegistry.set(registry, result);
|
|
1595
|
+
return result;
|
|
1596
|
+
}
|
|
1597
|
+
function compile(snapshot, registry) {
|
|
1598
|
+
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
1599
|
+
const refuse = (why) => {
|
|
1600
|
+
warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
1601
|
+
return null;
|
|
1602
|
+
};
|
|
1603
|
+
if (snapshot.kind !== "template") return refuse("not a template widget");
|
|
1604
|
+
const source = snapshot.template;
|
|
1605
|
+
if (typeof source !== "string") return refuse("no template source");
|
|
1606
|
+
const parsed = parseTemplate(source);
|
|
1607
|
+
if (!parsed.ok) return refuse(`template does not parse: ${parsed.issues[0]?.message ?? "invalid"}`);
|
|
1608
|
+
const data = snapshot.data;
|
|
1609
|
+
const issues = validateTemplate(parsed.ast, {
|
|
1610
|
+
settings: snapshot.settings,
|
|
1611
|
+
data: typeof data === "object" && data !== null ? data : {},
|
|
1612
|
+
sources: registry.sources()
|
|
1613
|
+
});
|
|
1614
|
+
if (issues.length > 0) return refuse(`template does not validate: ${issues[0]?.message ?? "invalid"}`);
|
|
1615
|
+
if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(MAX_TEMPLATE_WEIGHT2)} nodes`);
|
|
1616
|
+
const css = scopedCss(snapshot.css, snapshot.type);
|
|
1617
|
+
if (css === null) return refuse("its css does not pass the sanitiser");
|
|
1618
|
+
return { ast: parsed.ast, css, weight: templateWeight2(parsed.ast) };
|
|
1619
|
+
}
|
|
1620
|
+
function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
|
|
1621
|
+
const template = compileTemplate(snapshot, registry);
|
|
1622
|
+
if (template === null) return null;
|
|
1623
|
+
const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
|
|
1624
|
+
return /* @__PURE__ */ jsxs14(Fragment15, { children: [
|
|
1625
|
+
template.css === "" ? null : /* @__PURE__ */ jsx21(CustomCss, { css: template.css }),
|
|
1626
|
+
renderTemplate(template.ast, env)
|
|
1627
|
+
] });
|
|
1628
|
+
}
|
|
1629
|
+
function TemplateWidget(props) {
|
|
1630
|
+
return /* @__PURE__ */ jsx21(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx21(Suspense, { fallback: null, children: /* @__PURE__ */ jsx21(TemplateBody, { ...props }) }) });
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
// src/custom/composite-widget.tsx
|
|
1634
|
+
import { jsx as jsx22 } from "react/jsx-runtime";
|
|
1635
|
+
var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
|
|
1636
|
+
var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
|
|
1637
|
+
var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
|
|
1638
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1639
|
+
var compiled2 = /* @__PURE__ */ new WeakMap();
|
|
1640
|
+
function parseBody(raw) {
|
|
1641
|
+
if (!isRecord3(raw)) return null;
|
|
1642
|
+
const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
|
|
1643
|
+
const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
|
|
1644
|
+
if (columns === void 0 === (stack === void 0)) return null;
|
|
1645
|
+
const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : stack ?? [];
|
|
1646
|
+
if (stack?.some((node) => isRecord3(node) && node.type === "inner-section")) return null;
|
|
1647
|
+
const parsed = pageDocumentSchema.safeParse({
|
|
1648
|
+
schemaVersion: 1,
|
|
1649
|
+
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1650
|
+
});
|
|
1651
|
+
if (!parsed.success) return null;
|
|
1652
|
+
const first = parsed.data.sections[0]?.columns[0]?.children ?? [];
|
|
1653
|
+
if (columns !== void 0) {
|
|
1654
|
+
const inner = first[0];
|
|
1655
|
+
return inner?.type === "inner-section" ? { columns: inner.columns } : null;
|
|
1656
|
+
}
|
|
1657
|
+
return { stack: first.filter((node) => node.type !== "inner-section") };
|
|
1658
|
+
}
|
|
1659
|
+
function compileComposite(snapshot) {
|
|
1660
|
+
if (compiled2.has(snapshot)) return compiled2.get(snapshot) ?? null;
|
|
1661
|
+
const result = compile2(snapshot);
|
|
1662
|
+
compiled2.set(snapshot, result);
|
|
1663
|
+
return result;
|
|
1664
|
+
}
|
|
1665
|
+
function compile2(snapshot) {
|
|
1666
|
+
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
1667
|
+
const refuse = (why) => {
|
|
1668
|
+
warnOnce(`composite:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
1669
|
+
return null;
|
|
1670
|
+
};
|
|
1671
|
+
if (snapshot.kind !== "composite") return refuse("not a composite widget");
|
|
1672
|
+
const extra = snapshot;
|
|
1673
|
+
const body = parseBody(extra.body);
|
|
1674
|
+
if (body === null) return refuse("its body does not pass the document grammar");
|
|
1675
|
+
const bindings = [];
|
|
1676
|
+
if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
|
|
1677
|
+
for (const raw of extra.bindings ?? []) {
|
|
1678
|
+
if (!isRecord3(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
|
|
1679
|
+
return refuse("a binding is malformed");
|
|
1680
|
+
}
|
|
1681
|
+
const targets = [];
|
|
1682
|
+
for (const target of raw.targets) {
|
|
1683
|
+
if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
|
|
1684
|
+
return refuse("a binding target is malformed");
|
|
1685
|
+
}
|
|
1686
|
+
targets.push({ node: target.node, prop: target.prop });
|
|
1687
|
+
}
|
|
1688
|
+
bindings.push({ setting: raw.setting, targets });
|
|
1689
|
+
}
|
|
1690
|
+
const data = [];
|
|
1691
|
+
if (extra.data !== void 0 && !isRecord3(extra.data)) return refuse("data is not a record");
|
|
1692
|
+
for (const [name, raw] of Object.entries(extra.data ?? {})) {
|
|
1693
|
+
if (!SETTING_KEY_RE.test(name) || !isRecord3(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
|
|
1694
|
+
const targets = [];
|
|
1695
|
+
for (const target of raw.targets) {
|
|
1696
|
+
if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
|
|
1697
|
+
return refuse("a data target is malformed");
|
|
1698
|
+
}
|
|
1699
|
+
targets.push({ node: target.node, input: target.input });
|
|
1700
|
+
}
|
|
1701
|
+
data.push([name, { targets }]);
|
|
1702
|
+
}
|
|
1703
|
+
return { body, bindings, data };
|
|
1704
|
+
}
|
|
1705
|
+
var DEVICES3 = ["tablet", "phone"];
|
|
1706
|
+
function withoutAnchor(node) {
|
|
1707
|
+
delete node.props.anchor;
|
|
1708
|
+
const responsive = node.responsive;
|
|
1709
|
+
for (const device of DEVICES3) if (responsive?.[device] !== void 0) delete responsive[device].anchor;
|
|
1710
|
+
}
|
|
1711
|
+
function instanceId(outer, inner) {
|
|
1712
|
+
let a = 3735928559;
|
|
1713
|
+
let b = 1103547991;
|
|
1714
|
+
for (const char of `${outer}:${inner}`) {
|
|
1715
|
+
const code = char.charCodeAt(0);
|
|
1716
|
+
a = Math.imul(a ^ code, 2654435761);
|
|
1717
|
+
b = Math.imul(b ^ code, 1597334677);
|
|
1718
|
+
}
|
|
1719
|
+
a = Math.imul(a ^ a >>> 16, 2246822507) ^ Math.imul(b ^ b >>> 13, 3266489909);
|
|
1720
|
+
b = Math.imul(b ^ b >>> 16, 2246822507) ^ Math.imul(a ^ a >>> 13, 3266489909);
|
|
1721
|
+
return `i${(a >>> 0).toString(36).padStart(7, "0")}${(b >>> 0).toString(36).padStart(7, "0")}${(outer.length + inner.length).toString(36)}`;
|
|
1722
|
+
}
|
|
1723
|
+
function build(input) {
|
|
1724
|
+
const { snapshot, registry, node: outer, props, data } = input;
|
|
1725
|
+
const body = structuredClone(input.compiled.body);
|
|
1726
|
+
const assets = {};
|
|
1727
|
+
const hrefs = /* @__PURE__ */ new Map();
|
|
1728
|
+
const innerData = {};
|
|
1729
|
+
const keep = (child) => registry.widget(child.type, child.v)?.kind !== "composite";
|
|
1730
|
+
const columns = body.columns?.map((column2) => ({ ...column2, children: column2.children.filter(keep) }));
|
|
1731
|
+
const stack = body.stack?.filter(keep);
|
|
1732
|
+
const widgets2 = columns !== void 0 ? columns.flatMap((column2) => column2.children) : stack ?? [];
|
|
1733
|
+
for (const widget of widgets2) {
|
|
1734
|
+
withoutAnchor(widget);
|
|
1735
|
+
delete widget.data;
|
|
1736
|
+
}
|
|
1737
|
+
for (const column2 of columns ?? []) withoutAnchor(column2);
|
|
1738
|
+
const byId = new Map(widgets2.map((widget) => [widget.id, widget]));
|
|
1739
|
+
const fields = new Map(snapshot.settings.map((field) => [field.key, field]));
|
|
1740
|
+
let assetCount = 0;
|
|
1741
|
+
const convert = (field, value) => {
|
|
1742
|
+
if (value === null) return null;
|
|
1743
|
+
if (field.translatable === true) return typeof value === "string" ? { en: value } : null;
|
|
1744
|
+
if (field.control === "image") {
|
|
1745
|
+
if (!isFrozenAsset(value)) return null;
|
|
1746
|
+
assetCount += 1;
|
|
1747
|
+
const id = `bound${String(assetCount)}`;
|
|
1748
|
+
assets[id] = value;
|
|
1749
|
+
return id;
|
|
1750
|
+
}
|
|
1751
|
+
if (field.control === "link") {
|
|
1752
|
+
if (!isRecord3(value) || typeof value.kind !== "string") return null;
|
|
1753
|
+
const { href, ...target } = value;
|
|
1754
|
+
if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
|
|
1755
|
+
hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
|
|
1756
|
+
return target;
|
|
1757
|
+
}
|
|
1758
|
+
return value;
|
|
1759
|
+
};
|
|
1760
|
+
for (const binding of input.compiled.bindings) {
|
|
1761
|
+
const field = fields.get(binding.setting);
|
|
1762
|
+
if (field === void 0 || !Object.hasOwn(props, binding.setting)) continue;
|
|
1763
|
+
const value = props[binding.setting];
|
|
1764
|
+
for (const target of binding.targets) {
|
|
1765
|
+
const inner = byId.get(target.node);
|
|
1766
|
+
const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target.prop);
|
|
1767
|
+
if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
|
|
1768
|
+
const converted = convert(field, value);
|
|
1769
|
+
if (validateSettingValue(innerField, converted) !== null) continue;
|
|
1770
|
+
inner.props[target.prop] = converted;
|
|
1771
|
+
const responsive = inner.responsive;
|
|
1772
|
+
for (const device of DEVICES3) {
|
|
1773
|
+
if (responsive?.[device] !== void 0) delete responsive[device][target.prop];
|
|
1774
|
+
const raw = outer.responsive?.[device];
|
|
1775
|
+
const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
|
|
1776
|
+
if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && validateSettingValue(innerField, raw[binding.setting]) === null) {
|
|
1777
|
+
const target$ = inner.responsive ?? (inner.responsive = {});
|
|
1778
|
+
(target$[device] ?? (target$[device] = {}))[target.prop] = raw[binding.setting];
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
for (const [name, input$] of input.compiled.data) {
|
|
1784
|
+
if (!Object.hasOwn(data, name) || data[name] === void 0) continue;
|
|
1785
|
+
const key = `composite.${name}`;
|
|
1786
|
+
for (const target of input$.targets) {
|
|
1787
|
+
const inner = byId.get(target.node);
|
|
1788
|
+
const def = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v);
|
|
1789
|
+
if (inner === void 0 || def?.data === void 0 || !Object.hasOwn(def.data, target.input)) continue;
|
|
1790
|
+
inner.data = { ...inner.data ?? {}, [target.input]: { source: key } };
|
|
1791
|
+
innerData[key] = data[name];
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
for (const widget of widgets2) widget.id = instanceId(outer.id, widget.id);
|
|
1795
|
+
for (const column2 of columns ?? []) column2.id = instanceId(outer.id, column2.id);
|
|
1796
|
+
const ids = { section: instanceId(outer.id, WRAP.section), column: instanceId(outer.id, WRAP.column), inner: instanceId(outer.id, WRAP.inner) };
|
|
1797
|
+
const column = {
|
|
1798
|
+
id: ids.column,
|
|
1799
|
+
type: "column",
|
|
1800
|
+
props: { width: 100 },
|
|
1801
|
+
children: columns !== void 0 ? [{ id: ids.inner, type: "inner-section", props: { width: "full" }, columns }] : stack ?? []
|
|
1802
|
+
};
|
|
1803
|
+
const document = {
|
|
1804
|
+
schemaVersion: 1,
|
|
1805
|
+
sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
|
|
1806
|
+
};
|
|
1807
|
+
let weight = 2 + (columns?.length ?? 0) + (columns === void 0 ? 0 : 1);
|
|
1808
|
+
for (const widget of widgets2) {
|
|
1809
|
+
const component = registry.component(widget);
|
|
1810
|
+
weight += 1 + (component === void 0 ? 0 : componentWeights.get(component) ?? 0);
|
|
1811
|
+
}
|
|
1812
|
+
return { document, assets, data: innerData, hrefs, weight };
|
|
1813
|
+
}
|
|
1814
|
+
function CompositeBody(props) {
|
|
1815
|
+
const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink } = props;
|
|
1816
|
+
const composite = compileComposite(snapshot);
|
|
1817
|
+
if (composite === null) return null;
|
|
1818
|
+
const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
|
|
1819
|
+
if (!(budget ?? new RenderBudget()).take(built.weight)) {
|
|
1820
|
+
warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
|
|
1821
|
+
return null;
|
|
1822
|
+
}
|
|
1823
|
+
return /* @__PURE__ */ jsx22(
|
|
1824
|
+
BuilderRenderer,
|
|
1825
|
+
{
|
|
1826
|
+
document: built.document,
|
|
1827
|
+
registry,
|
|
1828
|
+
data: built.data,
|
|
1829
|
+
locale,
|
|
1830
|
+
assets: built.assets,
|
|
1831
|
+
mediaOrigin,
|
|
1832
|
+
resolveLink: (target) => built.hrefs.get(JSON.stringify(target)) ?? resolveLink?.(target) ?? null
|
|
1833
|
+
}
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
function CompositeWidget(props) {
|
|
1837
|
+
return /* @__PURE__ */ jsx22(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx22(Suspense2, { fallback: null, children: /* @__PURE__ */ jsx22(CompositeBody, { ...props }) }) });
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
// src/custom/factory.ts
|
|
1841
|
+
var isDisabled = (snapshot) => snapshot.status === "disabled";
|
|
1842
|
+
var Disabled = ({ editMode }) => editMode ? createElement3("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
|
|
1843
|
+
var customWidgetFactory = (snapshot, registry) => {
|
|
1844
|
+
if (isDisabled(snapshot)) return Disabled;
|
|
1845
|
+
if (snapshot.kind === "template") {
|
|
1846
|
+
const template = compileTemplate(snapshot, registry);
|
|
1847
|
+
if (template === null) return null;
|
|
1848
|
+
const Component2 = (props) => createElement3(TemplateWidget, { ...props, snapshot, registry });
|
|
1849
|
+
componentWeights.set(Component2, template.weight);
|
|
1850
|
+
return Component2;
|
|
1851
|
+
}
|
|
1852
|
+
if (compileComposite(snapshot) === null) return null;
|
|
1853
|
+
return (props) => createElement3(CompositeWidget, { ...props, snapshot, registry });
|
|
1854
|
+
};
|
|
1855
|
+
|
|
1856
|
+
// src/registry.ts
|
|
1857
|
+
var BUILTIN_PACKS = [basicPack];
|
|
1858
|
+
var DEFAULT_CUSTOM_WIDGET = customWidgetFactory;
|
|
1859
|
+
var customKey = (type, v) => `${type}@${String(v)}`;
|
|
1860
|
+
function createRendererRegistry(packs, options = {}) {
|
|
1861
|
+
const all = [...BUILTIN_PACKS, ...packs];
|
|
1862
|
+
const components = /* @__PURE__ */ new Map();
|
|
1863
|
+
const definitions = [];
|
|
1864
|
+
const sources = [];
|
|
1865
|
+
const resolvers = /* @__PURE__ */ new Map();
|
|
1866
|
+
for (const pack of all) {
|
|
1867
|
+
for (const { Component: Component2, ...definition } of pack.widgets) {
|
|
1868
|
+
const key = customKey(definition.type, definition.v);
|
|
1869
|
+
if (components.has(key)) continue;
|
|
1870
|
+
components.set(key, Component2);
|
|
1871
|
+
definitions.push(definition);
|
|
1872
|
+
}
|
|
1873
|
+
for (const { resolve, ...descriptor } of pack.dataSources) {
|
|
1874
|
+
if (resolvers.has(descriptor.id)) continue;
|
|
1875
|
+
resolvers.set(descriptor.id, resolve);
|
|
1876
|
+
sources.push(descriptor);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
const factory = options.customWidget ?? DEFAULT_CUSTOM_WIDGET;
|
|
1880
|
+
const build2 = (custom) => {
|
|
1881
|
+
const schema = createRegistry(definitions, sources, custom);
|
|
1882
|
+
const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
|
|
1883
|
+
const built = /* @__PURE__ */ new Map();
|
|
1884
|
+
const registry = {
|
|
1885
|
+
widget: schema.widget,
|
|
1886
|
+
latest: schema.latest,
|
|
1887
|
+
source: schema.source,
|
|
1888
|
+
sources: schema.sources,
|
|
1889
|
+
all: schema.all,
|
|
1890
|
+
resolver: (id) => resolvers.get(id),
|
|
1891
|
+
component: (node) => {
|
|
1892
|
+
const key = customKey(node.type, node.v);
|
|
1893
|
+
const own = components.get(key);
|
|
1894
|
+
if (own !== void 0) return own;
|
|
1895
|
+
if (!node.type.startsWith("custom.") || factory === void 0) return void 0;
|
|
1896
|
+
const snapshot = snapshots.get(key);
|
|
1897
|
+
if (snapshot === void 0) return void 0;
|
|
1898
|
+
if (!built.has(key)) built.set(key, factory(snapshot, registry));
|
|
1899
|
+
return built.get(key) ?? void 0;
|
|
1900
|
+
},
|
|
1901
|
+
withCustom: (more) => build2([...custom, ...more])
|
|
1902
|
+
};
|
|
1903
|
+
return registry;
|
|
1904
|
+
};
|
|
1905
|
+
return build2([]);
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
// src/server/load-page.ts
|
|
1909
|
+
import { BuilderNotFoundError } from "@usethrottle/builder";
|
|
1910
|
+
async function loadBuilderPage(options) {
|
|
1911
|
+
const { slug, locale, packs = [], slots } = options;
|
|
1912
|
+
const bundle = await getBundle({ client: clientOf(options), locale, page: slug, slots });
|
|
1913
|
+
const found = bundle.page;
|
|
1914
|
+
if (found === void 0) throw new BuilderNotFoundError(slug);
|
|
1915
|
+
if (isRedirect(found)) return { kind: "redirect", redirectTo: found.redirectTo };
|
|
1916
|
+
const data = await staticDataFor([found.document], createRendererRegistry(packs), locale);
|
|
1917
|
+
return pageOf(found, data);
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
export {
|
|
1921
|
+
warnOnce,
|
|
1922
|
+
createRendererRegistry,
|
|
1923
|
+
staticDataFor,
|
|
1924
|
+
partOf,
|
|
1925
|
+
isRedirect,
|
|
1926
|
+
getBundle,
|
|
1927
|
+
clientOf,
|
|
1928
|
+
loadBuilderPage
|
|
1929
|
+
};
|