@usethrottle/builder-schema 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1622 -0
- package/dist/index.d.cts +3600 -0
- package/dist/index.d.ts +3600 -0
- package/dist/index.js +1599 -0
- package/package.json +46 -3
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1599 @@
|
|
|
1
|
+
// src/ids.ts
|
|
2
|
+
var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
|
|
3
|
+
var ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
4
|
+
var ID_LENGTH = 16;
|
|
5
|
+
function newNodeId() {
|
|
6
|
+
const source = globalThis.crypto;
|
|
7
|
+
if (source === void 0) {
|
|
8
|
+
throw new Error("newNodeId needs a global crypto.getRandomValues");
|
|
9
|
+
}
|
|
10
|
+
const bytes = source.getRandomValues(new Uint8Array(ID_LENGTH));
|
|
11
|
+
let id = "";
|
|
12
|
+
for (const byte of bytes) id += ALPHABET[byte % ALPHABET.length];
|
|
13
|
+
return id;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/issues.ts
|
|
17
|
+
var ISSUE_CODES = [
|
|
18
|
+
"INVALID_SHAPE",
|
|
19
|
+
"INVALID_VALUE",
|
|
20
|
+
"REQUIRED",
|
|
21
|
+
"UNKNOWN_KEY",
|
|
22
|
+
"FORBIDDEN_KEY",
|
|
23
|
+
"DUPLICATE_ID",
|
|
24
|
+
"LIMIT_EXCEEDED",
|
|
25
|
+
"UNSUPPORTED_SCHEMA_VERSION",
|
|
26
|
+
"INVALID_WIDGET_TYPE",
|
|
27
|
+
"INVALID_COLUMN_WIDTHS",
|
|
28
|
+
"INNER_IN_INNER"
|
|
29
|
+
// <task-8>
|
|
30
|
+
// </task-8>
|
|
31
|
+
// <task-9>
|
|
32
|
+
// </task-9>
|
|
33
|
+
];
|
|
34
|
+
var MAX_ISSUES = 50;
|
|
35
|
+
function formatPath(segments) {
|
|
36
|
+
let out = "";
|
|
37
|
+
for (const segment of segments) {
|
|
38
|
+
if (typeof segment === "number") out += `[${String(segment)}]`;
|
|
39
|
+
else out += out === "" ? segment : `.${segment}`;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function makeIssue(path, code, message) {
|
|
44
|
+
return {
|
|
45
|
+
path: typeof path === "string" ? path : formatPath(path),
|
|
46
|
+
code,
|
|
47
|
+
message
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function capIssues(issues) {
|
|
51
|
+
return issues.length > MAX_ISSUES ? issues.slice(0, MAX_ISSUES) : issues;
|
|
52
|
+
}
|
|
53
|
+
var KNOWN_CODES = new Set(ISSUE_CODES);
|
|
54
|
+
function codeFor(issue) {
|
|
55
|
+
if (issue.code === "custom") {
|
|
56
|
+
const params = issue.params;
|
|
57
|
+
if (typeof params?.code === "string" && KNOWN_CODES.has(params.code)) {
|
|
58
|
+
return params.code;
|
|
59
|
+
}
|
|
60
|
+
return "INVALID_VALUE";
|
|
61
|
+
}
|
|
62
|
+
if (issue.code === "unrecognized_keys") return "UNKNOWN_KEY";
|
|
63
|
+
if (issue.code === "too_big") return "LIMIT_EXCEEDED";
|
|
64
|
+
if (issue.code === "invalid_type") {
|
|
65
|
+
return /received undefined/.test(issue.message) ? "REQUIRED" : "INVALID_SHAPE";
|
|
66
|
+
}
|
|
67
|
+
return "INVALID_VALUE";
|
|
68
|
+
}
|
|
69
|
+
function flatten(issue, out, prefix = []) {
|
|
70
|
+
if (issue.code === "invalid_union") {
|
|
71
|
+
let best;
|
|
72
|
+
for (const branch of issue.errors) {
|
|
73
|
+
if (best === void 0 || branch.length < best.length) {
|
|
74
|
+
best = branch;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (best !== void 0) {
|
|
78
|
+
for (const inner of best) flatten(inner, out, [...prefix, ...issue.path]);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const path = [...prefix, ...issue.path].map(
|
|
83
|
+
(p) => typeof p === "symbol" ? String(p) : p
|
|
84
|
+
);
|
|
85
|
+
out.push(makeIssue(path, codeFor(issue), issue.message));
|
|
86
|
+
}
|
|
87
|
+
function zodIssues(error) {
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const issue of error.issues) {
|
|
90
|
+
flatten(issue, out);
|
|
91
|
+
if (out.length >= MAX_ISSUES) break;
|
|
92
|
+
}
|
|
93
|
+
return capIssues(dropShadowed(out));
|
|
94
|
+
}
|
|
95
|
+
function dropShadowed(issues) {
|
|
96
|
+
const roots = issues.filter((i) => i.code === "INNER_IN_INNER" && i.path.endsWith(".type")).map((i) => i.path.slice(0, -".type".length));
|
|
97
|
+
if (roots.length === 0) return issues;
|
|
98
|
+
return issues.filter(
|
|
99
|
+
(i) => i.code === "INNER_IN_INNER" || !roots.some((root) => i.path === root || i.path.startsWith(`${root}.`))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/document.ts
|
|
104
|
+
import { z as z3 } from "zod";
|
|
105
|
+
|
|
106
|
+
// src/walk.ts
|
|
107
|
+
function walkNodes(doc, visit) {
|
|
108
|
+
const walkWidgets = (nodes, path) => {
|
|
109
|
+
nodes.forEach((widget, i) => visit(widget, [...path, i]));
|
|
110
|
+
};
|
|
111
|
+
const walkInnerSection = (section, path) => {
|
|
112
|
+
visit(section, path);
|
|
113
|
+
section.columns.forEach((column, j) => {
|
|
114
|
+
const columnPath = [...path, "columns", j];
|
|
115
|
+
visit(column, columnPath);
|
|
116
|
+
walkWidgets(column.children, [...columnPath, "children"]);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
doc.sections.forEach((section, i) => {
|
|
120
|
+
const sectionPath = ["sections", i];
|
|
121
|
+
visit(section, sectionPath);
|
|
122
|
+
section.columns.forEach((column, j) => {
|
|
123
|
+
const columnPath = [...sectionPath, "columns", j];
|
|
124
|
+
visit(column, columnPath);
|
|
125
|
+
column.children.forEach((child, k) => {
|
|
126
|
+
const childPath = [...columnPath, "children", k];
|
|
127
|
+
if (child.type === "inner-section") walkInnerSection(child, childPath);
|
|
128
|
+
else visit(child, childPath);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/limits.ts
|
|
135
|
+
var KB = 1024;
|
|
136
|
+
var SECOND = 1e3;
|
|
137
|
+
var MINUTE = 60 * SECOND;
|
|
138
|
+
var LIMITS = {
|
|
139
|
+
// Page document
|
|
140
|
+
documentBytes: 512 * KB,
|
|
141
|
+
nodes: 2e3,
|
|
142
|
+
sections: 200,
|
|
143
|
+
childrenPerColumn: 100,
|
|
144
|
+
columnsMin: 1,
|
|
145
|
+
columnsMax: 6,
|
|
146
|
+
localizedTextChars: 2e4,
|
|
147
|
+
// Site
|
|
148
|
+
pagesPerSite: 500,
|
|
149
|
+
slotsPerSite: 20,
|
|
150
|
+
partsPerSite: 2,
|
|
151
|
+
/** `header` and `footer` always exist, plus up to this many more. */
|
|
152
|
+
namedMenusMax: 10,
|
|
153
|
+
menuDepth: 3,
|
|
154
|
+
menuItems: 60,
|
|
155
|
+
// Widgets
|
|
156
|
+
widgetSettings: 40,
|
|
157
|
+
templateSourceBytes: 20 * KB,
|
|
158
|
+
widgetCssBytes: 10 * KB,
|
|
159
|
+
widgetDefinitionBytes: 64 * KB,
|
|
160
|
+
templateAstNodes: 2e3,
|
|
161
|
+
templateAstDepth: 12,
|
|
162
|
+
eachDepth: 2,
|
|
163
|
+
eachIterations: 100,
|
|
164
|
+
customWidgetDataInputs: 5,
|
|
165
|
+
customWidgetTypesPerSite: 200,
|
|
166
|
+
customWidgetVersionsPerType: 50,
|
|
167
|
+
// Editor
|
|
168
|
+
undoSteps: 150,
|
|
169
|
+
undoCoalesceMs: 1400,
|
|
170
|
+
autosaveDebounceMs: 800,
|
|
171
|
+
autosaveMaxIntervalMs: 3 * SECOND,
|
|
172
|
+
versionsPerDocument: 100,
|
|
173
|
+
// Rate limits (per minute)
|
|
174
|
+
mcpCallsPerMinute: 120,
|
|
175
|
+
mcpWritesPerMinute: 60,
|
|
176
|
+
widgetApiWritesPerMinute: 30,
|
|
177
|
+
canvasProxyRequestsPerMinute: 300,
|
|
178
|
+
// Caches and timers
|
|
179
|
+
siteLookupCacheEntries: 1e3,
|
|
180
|
+
siteLookupCacheTtlMs: 30 * SECOND,
|
|
181
|
+
presenceCacheMs: 5 * MINUTE,
|
|
182
|
+
grantStatusCacheMs: 60 * SECOND,
|
|
183
|
+
jwksCacheMs: 10 * MINUTE,
|
|
184
|
+
previewTokenMs: 60 * MINUTE,
|
|
185
|
+
noticeCoalesceMs: 2 * SECOND
|
|
186
|
+
};
|
|
187
|
+
function utf8Length(text) {
|
|
188
|
+
let bytes = 0;
|
|
189
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
190
|
+
const code = text.charCodeAt(i);
|
|
191
|
+
if (code < 128) bytes += 1;
|
|
192
|
+
else if (code < 2048) bytes += 2;
|
|
193
|
+
else if (code >= 55296 && code <= 56319) {
|
|
194
|
+
bytes += 4;
|
|
195
|
+
i += 1;
|
|
196
|
+
} else bytes += 3;
|
|
197
|
+
}
|
|
198
|
+
return bytes;
|
|
199
|
+
}
|
|
200
|
+
function limit(path, what, max, actual) {
|
|
201
|
+
return makeIssue(
|
|
202
|
+
path,
|
|
203
|
+
"LIMIT_EXCEEDED",
|
|
204
|
+
`${what}: ${String(actual)} is over the limit of ${String(max)}`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
function longStrings(value, path, out, depth = 0) {
|
|
208
|
+
if (out.length >= 50 || depth > 12) return;
|
|
209
|
+
if (typeof value === "string") {
|
|
210
|
+
if (value.length > LIMITS.localizedTextChars) {
|
|
211
|
+
out.push(
|
|
212
|
+
limit(
|
|
213
|
+
formatPath(path),
|
|
214
|
+
"Text length",
|
|
215
|
+
LIMITS.localizedTextChars,
|
|
216
|
+
value.length
|
|
217
|
+
)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
} else if (Array.isArray(value)) {
|
|
221
|
+
value.forEach((item, i) => longStrings(item, [...path, i], out, depth + 1));
|
|
222
|
+
} else if (typeof value === "object" && value !== null) {
|
|
223
|
+
for (const [key, item] of Object.entries(value)) {
|
|
224
|
+
longStrings(item, [...path, key], out, depth + 1);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function checkLimits(doc) {
|
|
229
|
+
const issues = [];
|
|
230
|
+
const bytes = utf8Length(JSON.stringify(doc));
|
|
231
|
+
if (bytes > LIMITS.documentBytes) {
|
|
232
|
+
issues.push(limit("", "Document size in bytes", LIMITS.documentBytes, bytes));
|
|
233
|
+
}
|
|
234
|
+
if (doc.sections.length > LIMITS.sections) {
|
|
235
|
+
issues.push(limit("sections", "Sections", LIMITS.sections, doc.sections.length));
|
|
236
|
+
}
|
|
237
|
+
let nodes = 0;
|
|
238
|
+
walkNodes(doc, (node, path) => {
|
|
239
|
+
nodes += 1;
|
|
240
|
+
if (node.type === "section" || node.type === "inner-section") {
|
|
241
|
+
const n = node.columns.length;
|
|
242
|
+
if (n > LIMITS.columnsMax || n < LIMITS.columnsMin) {
|
|
243
|
+
issues.push(
|
|
244
|
+
makeIssue(
|
|
245
|
+
[...path, "columns"],
|
|
246
|
+
"LIMIT_EXCEEDED",
|
|
247
|
+
`A section has ${String(LIMITS.columnsMin)} to ${String(LIMITS.columnsMax)} columns, not ${String(n)}`
|
|
248
|
+
)
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
} else if (node.type === "column") {
|
|
252
|
+
if (node.children.length > LIMITS.childrenPerColumn) {
|
|
253
|
+
issues.push(
|
|
254
|
+
limit(
|
|
255
|
+
formatPath([...path, "children"]),
|
|
256
|
+
"Children per column",
|
|
257
|
+
LIMITS.childrenPerColumn,
|
|
258
|
+
node.children.length
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
const strings = [];
|
|
264
|
+
longStrings(node.props, [...path, "props"], strings);
|
|
265
|
+
if (node.responsive !== void 0) {
|
|
266
|
+
longStrings(node.responsive, [...path, "responsive"], strings);
|
|
267
|
+
}
|
|
268
|
+
if (node.data !== void 0) longStrings(node.data, [...path, "data"], strings);
|
|
269
|
+
issues.push(...strings);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
if (nodes > LIMITS.nodes) {
|
|
273
|
+
issues.push(limit("", "Nodes", LIMITS.nodes, nodes));
|
|
274
|
+
}
|
|
275
|
+
return issues.slice(0, 50);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/site-settings.ts
|
|
279
|
+
import { z as z2 } from "zod";
|
|
280
|
+
|
|
281
|
+
// src/fonts.ts
|
|
282
|
+
var WEIGHTS_100_900 = [100, 200, 300, 400, 500, 600, 700, 800, 900];
|
|
283
|
+
var WEIGHTS_300_800 = [300, 400, 500, 600, 700, 800];
|
|
284
|
+
var WEIGHTS_400_700 = [400, 500, 600, 700];
|
|
285
|
+
var font = (family, category, weights) => ({ family, category, weights, google: true });
|
|
286
|
+
var system = (family, category) => ({
|
|
287
|
+
family,
|
|
288
|
+
category: "system",
|
|
289
|
+
weights: category === "mono" ? [400, 700] : [400, 500, 600, 700],
|
|
290
|
+
google: false
|
|
291
|
+
});
|
|
292
|
+
var FONT_DEFINITIONS = [
|
|
293
|
+
font("Instrument Serif", "serif", [400]),
|
|
294
|
+
font("Playfair Display", "serif", WEIGHTS_400_700),
|
|
295
|
+
font("Lora", "serif", WEIGHTS_400_700),
|
|
296
|
+
font("Merriweather", "serif", [300, 400, 700, 900]),
|
|
297
|
+
font("Cormorant Garamond", "serif", [300, 400, 500, 600, 700]),
|
|
298
|
+
font("EB Garamond", "serif", [400, 500, 600, 700, 800]),
|
|
299
|
+
font("Libre Baskerville", "serif", [400, 700]),
|
|
300
|
+
font("Source Serif 4", "serif", [300, 400, 500, 600, 700, 800, 900]),
|
|
301
|
+
font("Fraunces", "serif", WEIGHTS_100_900),
|
|
302
|
+
font("DM Serif Display", "serif", [400]),
|
|
303
|
+
font("Inter", "sans", WEIGHTS_100_900),
|
|
304
|
+
font("Schibsted Grotesk", "sans", [400, 500, 600, 700, 800, 900]),
|
|
305
|
+
font("DM Sans", "sans", WEIGHTS_100_900),
|
|
306
|
+
font("Manrope", "sans", [200, 300, 400, 500, 600, 700, 800]),
|
|
307
|
+
font("Poppins", "sans", WEIGHTS_100_900),
|
|
308
|
+
font("Montserrat", "sans", WEIGHTS_100_900),
|
|
309
|
+
font("Work Sans", "sans", WEIGHTS_100_900),
|
|
310
|
+
font("Rubik", "sans", [300, 400, 500, 600, 700, 800, 900]),
|
|
311
|
+
font("Nunito Sans", "sans", [200, 300, 400, 500, 600, 700, 800, 900]),
|
|
312
|
+
font("Open Sans", "sans", WEIGHTS_300_800),
|
|
313
|
+
font("Lato", "sans", [100, 300, 400, 700, 900]),
|
|
314
|
+
font("Raleway", "sans", WEIGHTS_100_900),
|
|
315
|
+
font("Outfit", "sans", WEIGHTS_100_900),
|
|
316
|
+
font("Plus Jakarta Sans", "sans", [200, 300, 400, 500, 600, 700, 800]),
|
|
317
|
+
font("Figtree", "sans", [300, 400, 500, 600, 700, 800, 900]),
|
|
318
|
+
font("Karla", "sans", [200, 300, 400, 500, 600, 700, 800]),
|
|
319
|
+
font("DM Mono", "mono", [300, 400, 500]),
|
|
320
|
+
font("JetBrains Mono", "mono", [100, 200, 300, 400, 500, 600, 700, 800]),
|
|
321
|
+
font("IBM Plex Mono", "mono", [100, 200, 300, 400, 500, 600, 700]),
|
|
322
|
+
font("Space Mono", "mono", [400, 700]),
|
|
323
|
+
font("Bebas Neue", "display", [400]),
|
|
324
|
+
font("Oswald", "display", [200, 300, 400, 500, 600, 700]),
|
|
325
|
+
font("Archivo Black", "display", [400]),
|
|
326
|
+
font("Space Grotesk", "display", [300, 400, 500, 600, 700]),
|
|
327
|
+
font("Syne", "display", [400, 500, 600, 700, 800]),
|
|
328
|
+
system("system-sans", "sans"),
|
|
329
|
+
system("system-serif", "serif"),
|
|
330
|
+
system("system-mono", "mono")
|
|
331
|
+
];
|
|
332
|
+
var SITE_FONTS = FONT_DEFINITIONS;
|
|
333
|
+
var SITE_FONT_FAMILIES = FONT_DEFINITIONS.map((f) => f.family);
|
|
334
|
+
|
|
335
|
+
// src/safe.ts
|
|
336
|
+
import { z } from "zod";
|
|
337
|
+
var customIssue = (ctx, code, message, path = []) => {
|
|
338
|
+
ctx.addIssue({ code: "custom", message, path, params: { code } });
|
|
339
|
+
};
|
|
340
|
+
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set([
|
|
341
|
+
"__proto__",
|
|
342
|
+
"constructor",
|
|
343
|
+
"prototype"
|
|
344
|
+
]);
|
|
345
|
+
function safeRecord(value, keySchema = z.string().max(64)) {
|
|
346
|
+
return z.preprocess((input, ctx) => {
|
|
347
|
+
if (typeof input === "object" && input !== null && !Array.isArray(input)) {
|
|
348
|
+
for (const key of Object.getOwnPropertyNames(input)) {
|
|
349
|
+
if (FORBIDDEN_KEYS.has(key)) {
|
|
350
|
+
ctx.addIssue({
|
|
351
|
+
code: "custom",
|
|
352
|
+
message: `The key "${key}" is not allowed`,
|
|
353
|
+
path: [key],
|
|
354
|
+
params: { code: "FORBIDDEN_KEY" }
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return input;
|
|
360
|
+
}, z.record(keySchema, value));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/strings.ts
|
|
364
|
+
var SITE_STRING_NAMESPACES = [
|
|
365
|
+
"announcement",
|
|
366
|
+
"footer",
|
|
367
|
+
"nav",
|
|
368
|
+
"page",
|
|
369
|
+
"site"
|
|
370
|
+
];
|
|
371
|
+
var SITE_STRING_DEFAULTS = {
|
|
372
|
+
"footer.copyright": "\xA9 {year} {store}. All rights reserved.",
|
|
373
|
+
"nav.menu": "Menu",
|
|
374
|
+
"nav.account": "Account",
|
|
375
|
+
"announcement.dismiss": "Dismiss",
|
|
376
|
+
"site.skipToContent": "Skip to content",
|
|
377
|
+
"page.breadcrumbHome": "Home"
|
|
378
|
+
};
|
|
379
|
+
var SITE_STRING_KEYS = Object.keys(SITE_STRING_DEFAULTS);
|
|
380
|
+
var CATALOG_STRING_KEYS = [
|
|
381
|
+
"shop.title",
|
|
382
|
+
"shop.description",
|
|
383
|
+
"search.title",
|
|
384
|
+
"search.placeholder",
|
|
385
|
+
"search.results",
|
|
386
|
+
"empty.search",
|
|
387
|
+
"empty.listing",
|
|
388
|
+
"empty.category",
|
|
389
|
+
"empty.collection",
|
|
390
|
+
"empty.cart",
|
|
391
|
+
"cart.title",
|
|
392
|
+
"cart.checkout",
|
|
393
|
+
"cart.continueShopping",
|
|
394
|
+
"filters.title",
|
|
395
|
+
"filters.clearAll",
|
|
396
|
+
"filters.apply",
|
|
397
|
+
"filters.showMore",
|
|
398
|
+
"filters.showLess",
|
|
399
|
+
"filters.priceMin",
|
|
400
|
+
"filters.priceMax",
|
|
401
|
+
"boolean.yes",
|
|
402
|
+
"boolean.no",
|
|
403
|
+
"sort.label",
|
|
404
|
+
"listing.count",
|
|
405
|
+
"listing.loadMore",
|
|
406
|
+
"listing.loading",
|
|
407
|
+
"listing.previous",
|
|
408
|
+
"listing.next",
|
|
409
|
+
"product.addToCart",
|
|
410
|
+
"product.quantity",
|
|
411
|
+
"product.selectOption",
|
|
412
|
+
"product.sku",
|
|
413
|
+
"product.description",
|
|
414
|
+
"product.specs",
|
|
415
|
+
"product.shipping",
|
|
416
|
+
"product.tags",
|
|
417
|
+
"product.categories",
|
|
418
|
+
"product.related",
|
|
419
|
+
"product.reviews",
|
|
420
|
+
"product.noReviews",
|
|
421
|
+
"product.writeReview",
|
|
422
|
+
"home.shopAll",
|
|
423
|
+
"home.featured",
|
|
424
|
+
"home.newest",
|
|
425
|
+
"home.bestRated",
|
|
426
|
+
"home.categories",
|
|
427
|
+
"nav.cart",
|
|
428
|
+
"error.notFound",
|
|
429
|
+
"error.generic"
|
|
430
|
+
];
|
|
431
|
+
|
|
432
|
+
// src/site-settings.ts
|
|
433
|
+
var LOCALE_TAG_RE = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8}){0,3}$/;
|
|
434
|
+
var localeTagSchema = z2.string().regex(LOCALE_TAG_RE);
|
|
435
|
+
var localizedTextSchema = safeRecord(z2.string().max(2e3), localeTagSchema);
|
|
436
|
+
var assetIdSchema = z2.string().min(1).max(64).regex(/^[A-Za-z0-9_-]+$/);
|
|
437
|
+
var THROTTLE_PK_RE = /^pk_[a-z0-9]+_[A-Za-z0-9]{8,}$/;
|
|
438
|
+
var SAFE_HREF = (
|
|
439
|
+
// eslint-disable-next-line no-control-regex
|
|
440
|
+
/^(?:https?:\/\/[^\s\\\u0000-\u001F\u007F]+|\/(?![/\\])[^\s\\\u0000-\u001F\u007F]*)$/iu
|
|
441
|
+
);
|
|
442
|
+
var ULID_RE = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
443
|
+
var menuTargetSchema = z2.discriminatedUnion("kind", [
|
|
444
|
+
z2.object({ kind: z2.literal("page"), id: z2.string().regex(ULID_RE) }).strict(),
|
|
445
|
+
z2.object({ kind: z2.literal("category"), id: z2.string().min(1).max(64) }).strict(),
|
|
446
|
+
z2.object({ kind: z2.literal("collection"), id: z2.string().min(1).max(64) }).strict(),
|
|
447
|
+
z2.object({ kind: z2.literal("product"), id: z2.string().min(1).max(64) }).strict(),
|
|
448
|
+
z2.object({
|
|
449
|
+
kind: z2.literal("search"),
|
|
450
|
+
q: z2.string().min(1).max(200).regex(/^[^\u0000-\u001F\u007F]+$/u)
|
|
451
|
+
}).strict(),
|
|
452
|
+
z2.object({
|
|
453
|
+
kind: z2.literal("url"),
|
|
454
|
+
href: z2.string().max(2e3).regex(SAFE_HREF)
|
|
455
|
+
}).strict()
|
|
456
|
+
]);
|
|
457
|
+
var itemBase = { label: localizedTextSchema, target: menuTargetSchema };
|
|
458
|
+
var menuItemLevel3 = z2.object({ ...itemBase, children: z2.array(z2.unknown()).optional() }).strict().superRefine((item, ctx) => {
|
|
459
|
+
if (item.children !== void 0 && item.children.length > 0) {
|
|
460
|
+
customIssue(
|
|
461
|
+
ctx,
|
|
462
|
+
"LIMIT_EXCEEDED",
|
|
463
|
+
`A menu has at most ${String(LIMITS.menuDepth)} levels`,
|
|
464
|
+
["children"]
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
var menuItemLevel2 = z2.object({ ...itemBase, children: z2.array(menuItemLevel3).optional() }).strict();
|
|
469
|
+
var menuItemLevel1 = z2.object({ ...itemBase, children: z2.array(menuItemLevel2).optional() }).strict();
|
|
470
|
+
var menuItemSchema = menuItemLevel1;
|
|
471
|
+
function countItems(items) {
|
|
472
|
+
let count = 0;
|
|
473
|
+
for (const item of items) {
|
|
474
|
+
count += 1;
|
|
475
|
+
if (item.children !== void 0) count += countItems(item.children);
|
|
476
|
+
}
|
|
477
|
+
return count;
|
|
478
|
+
}
|
|
479
|
+
var menuSchema = z2.array(menuItemSchema).superRefine((items, ctx) => {
|
|
480
|
+
if (countItems(items) > LIMITS.menuItems) {
|
|
481
|
+
customIssue(
|
|
482
|
+
ctx,
|
|
483
|
+
"LIMIT_EXCEEDED",
|
|
484
|
+
`A menu has at most ${String(LIMITS.menuItems)} items`
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
var MENU_NAME_RE = /^[a-z][a-z0-9-]{0,39}$/;
|
|
489
|
+
var menusSchema = z2.object({
|
|
490
|
+
header: menuSchema.default(() => []),
|
|
491
|
+
footer: menuSchema.default(() => [])
|
|
492
|
+
}).catchall(menuSchema).superRefine((menus, ctx) => {
|
|
493
|
+
const extra = Object.keys(menus).filter(
|
|
494
|
+
(name) => name !== "header" && name !== "footer"
|
|
495
|
+
);
|
|
496
|
+
for (const name of extra) {
|
|
497
|
+
if (!MENU_NAME_RE.test(name)) {
|
|
498
|
+
customIssue(ctx, "INVALID_VALUE", `"${name}" is not a valid menu name`, [name]);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (extra.length > LIMITS.namedMenusMax) {
|
|
502
|
+
customIssue(
|
|
503
|
+
ctx,
|
|
504
|
+
"LIMIT_EXCEEDED",
|
|
505
|
+
`A site has the header and footer menus and at most ${String(LIMITS.namedMenusMax)} more`
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
var colour = z2.string().regex(/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/u);
|
|
510
|
+
var paletteSchema = z2.object({
|
|
511
|
+
colorPrimary: colour,
|
|
512
|
+
colorPrimaryForeground: colour,
|
|
513
|
+
colorBackground: colour,
|
|
514
|
+
colorSurface: colour,
|
|
515
|
+
colorForeground: colour,
|
|
516
|
+
colorMuted: colour,
|
|
517
|
+
colorMutedForeground: colour,
|
|
518
|
+
colorBorder: colour,
|
|
519
|
+
colorBorderControl: colour,
|
|
520
|
+
colorAccent: colour,
|
|
521
|
+
colorSale: colour,
|
|
522
|
+
colorSuccess: colour,
|
|
523
|
+
colorWarning: colour,
|
|
524
|
+
colorDanger: colour
|
|
525
|
+
});
|
|
526
|
+
var defaultLight = () => ({
|
|
527
|
+
colorPrimary: "#18181b",
|
|
528
|
+
colorPrimaryForeground: "#fafafa",
|
|
529
|
+
colorBackground: "#ffffff",
|
|
530
|
+
colorSurface: "#f4f4f5",
|
|
531
|
+
colorForeground: "#18181b",
|
|
532
|
+
colorMuted: "#f4f4f5",
|
|
533
|
+
colorMutedForeground: "#71717a",
|
|
534
|
+
colorBorder: "#e4e4e7",
|
|
535
|
+
colorBorderControl: "#d4d4d8",
|
|
536
|
+
colorAccent: "#2563eb",
|
|
537
|
+
colorSale: "#b91c1c",
|
|
538
|
+
colorSuccess: "#15803d",
|
|
539
|
+
colorWarning: "#b45309",
|
|
540
|
+
colorDanger: "#b91c1c"
|
|
541
|
+
});
|
|
542
|
+
var defaultDark = () => ({
|
|
543
|
+
colorPrimary: "#fafafa",
|
|
544
|
+
colorPrimaryForeground: "#18181b",
|
|
545
|
+
colorBackground: "#09090b",
|
|
546
|
+
colorSurface: "#18181b",
|
|
547
|
+
colorForeground: "#fafafa",
|
|
548
|
+
colorMuted: "#27272a",
|
|
549
|
+
colorMutedForeground: "#a1a1aa",
|
|
550
|
+
colorBorder: "#27272a",
|
|
551
|
+
colorBorderControl: "#3f3f46",
|
|
552
|
+
colorAccent: "#60a5fa",
|
|
553
|
+
colorSale: "#f87171",
|
|
554
|
+
colorSuccess: "#4ade80",
|
|
555
|
+
colorWarning: "#fbbf24",
|
|
556
|
+
colorDanger: "#f87171"
|
|
557
|
+
});
|
|
558
|
+
var fontFamily = z2.enum(SITE_FONT_FAMILIES);
|
|
559
|
+
var themeSchema = z2.object({
|
|
560
|
+
preset: z2.enum(["clean", "editorial", "bold"]).default("clean"),
|
|
561
|
+
// When false the preset's tokens apply, when true the merchant's values do.
|
|
562
|
+
customized: z2.boolean().default(false),
|
|
563
|
+
light: paletteSchema.default(defaultLight),
|
|
564
|
+
dark: paletteSchema.default(defaultDark),
|
|
565
|
+
fonts: z2.object({
|
|
566
|
+
heading: fontFamily.default("system-sans"),
|
|
567
|
+
body: fontFamily.default("system-sans"),
|
|
568
|
+
mono: fontFamily.default("system-mono")
|
|
569
|
+
}).strict().prefault({}),
|
|
570
|
+
radius: z2.number().int().min(0).max(32).default(8),
|
|
571
|
+
spacingScale: z2.enum(["compact", "comfortable", "roomy"]).default("comfortable"),
|
|
572
|
+
colorScheme: z2.enum(["light", "dark", "auto"]).default("auto")
|
|
573
|
+
}).strict();
|
|
574
|
+
var brandSchema = z2.object({
|
|
575
|
+
storeName: z2.string().max(100).regex(/^[^\u0000-\u001F\u007F]*$/u).default(""),
|
|
576
|
+
logo: z2.object({
|
|
577
|
+
light: assetIdSchema.nullable().default(null),
|
|
578
|
+
dark: assetIdSchema.nullable().default(null)
|
|
579
|
+
}).strict().prefault({}),
|
|
580
|
+
favicon: assetIdSchema.nullable().default(null)
|
|
581
|
+
}).strict();
|
|
582
|
+
var isoInstant = z2.iso.datetime({ offset: true });
|
|
583
|
+
var announcementSchema = z2.object({
|
|
584
|
+
enabled: z2.boolean().default(false),
|
|
585
|
+
message: localizedTextSchema.default({}),
|
|
586
|
+
target: menuTargetSchema.nullable().default(null),
|
|
587
|
+
startsAt: isoInstant.nullable().default(null),
|
|
588
|
+
endsAt: isoInstant.nullable().default(null)
|
|
589
|
+
}).strict();
|
|
590
|
+
var seoSchema = z2.object({
|
|
591
|
+
titleTemplate: z2.string().min(1).max(200).default("{page} \u2013 {store}"),
|
|
592
|
+
defaultDescription: localizedTextSchema.default({}),
|
|
593
|
+
shareImage: assetIdSchema.nullable().default(null)
|
|
594
|
+
}).strict();
|
|
595
|
+
var stringsSchema = z2.object(
|
|
596
|
+
Object.fromEntries(
|
|
597
|
+
SITE_STRING_KEYS.map((key) => [key, localizedTextSchema.optional()])
|
|
598
|
+
)
|
|
599
|
+
).strict();
|
|
600
|
+
var routesSchema = z2.object({
|
|
601
|
+
page: z2.string().max(200).regex(/^\/(?!\/)[^\s\\]*\{handle\}[^\s\\]*$/).default("/pages/{handle}"),
|
|
602
|
+
home: z2.literal("/").default("/")
|
|
603
|
+
}).strict();
|
|
604
|
+
var connectionsSchema = z2.object({
|
|
605
|
+
throttlePublishableKey: z2.string().regex(THROTTLE_PK_RE).nullable().default(null)
|
|
606
|
+
}).strict();
|
|
607
|
+
var localesSchema = z2.object({
|
|
608
|
+
default: localeTagSchema.default("en"),
|
|
609
|
+
list: z2.array(localeTagSchema).min(1).max(50).default(["en"])
|
|
610
|
+
}).strict().superRefine((locales, ctx) => {
|
|
611
|
+
if (!locales.list.includes(locales.default)) {
|
|
612
|
+
customIssue(ctx, "INVALID_VALUE", "The default locale must be in the list", ["list"]);
|
|
613
|
+
}
|
|
614
|
+
if (new Set(locales.list).size !== locales.list.length) {
|
|
615
|
+
customIssue(ctx, "INVALID_VALUE", "Locales must be unique", ["list"]);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
var SITE_SETTINGS_SCHEMA_VERSION = 1;
|
|
619
|
+
var siteSettingsSchema = z2.object({
|
|
620
|
+
schemaVersion: z2.literal(1).default(1),
|
|
621
|
+
brand: brandSchema.prefault({}),
|
|
622
|
+
theme: themeSchema.prefault({}),
|
|
623
|
+
menus: menusSchema.prefault({}),
|
|
624
|
+
announcement: announcementSchema.prefault({}),
|
|
625
|
+
seo: seoSchema.prefault({}),
|
|
626
|
+
strings: stringsSchema.prefault({}),
|
|
627
|
+
routes: routesSchema.prefault({}),
|
|
628
|
+
connections: connectionsSchema.prefault({}),
|
|
629
|
+
locales: localesSchema.prefault({}),
|
|
630
|
+
/** The store origin, for editor links and the default notice endpoint. */
|
|
631
|
+
storeUrl: z2.string().max(2e3).regex(/^https?:\/\/[^\s/\\]+$/i).nullable().default(null)
|
|
632
|
+
}).strict();
|
|
633
|
+
function defaultSiteSettings() {
|
|
634
|
+
return siteSettingsSchema.parse({});
|
|
635
|
+
}
|
|
636
|
+
var SITE_ASSET_PATHS = [
|
|
637
|
+
"brand.logo.light",
|
|
638
|
+
"brand.logo.dark",
|
|
639
|
+
"brand.favicon",
|
|
640
|
+
"seo.shareImage"
|
|
641
|
+
];
|
|
642
|
+
|
|
643
|
+
// src/document.ts
|
|
644
|
+
var MAX_VALUE_DEPTH = 8;
|
|
645
|
+
function isSettingValue(value, depth = 0) {
|
|
646
|
+
if (value === null) return true;
|
|
647
|
+
switch (typeof value) {
|
|
648
|
+
case "string":
|
|
649
|
+
case "boolean":
|
|
650
|
+
return true;
|
|
651
|
+
case "number":
|
|
652
|
+
return Number.isFinite(value);
|
|
653
|
+
case "object": {
|
|
654
|
+
if (depth >= MAX_VALUE_DEPTH) return false;
|
|
655
|
+
if (Array.isArray(value)) {
|
|
656
|
+
return value.every((item) => isSettingValue(item, depth + 1));
|
|
657
|
+
}
|
|
658
|
+
const proto = Object.getPrototypeOf(value);
|
|
659
|
+
if (proto !== Object.prototype && proto !== null) return false;
|
|
660
|
+
return Object.values(value).every((item) => isSettingValue(item, depth + 1));
|
|
661
|
+
}
|
|
662
|
+
default:
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
var settingValueSchema = z3.preprocess((input, ctx) => {
|
|
667
|
+
if (!isSettingValue(input)) {
|
|
668
|
+
ctx.addIssue({
|
|
669
|
+
code: "custom",
|
|
670
|
+
message: "Expected a JSON value (at most 8 levels deep)",
|
|
671
|
+
params: { code: "INVALID_VALUE" }
|
|
672
|
+
});
|
|
673
|
+
return null;
|
|
674
|
+
}
|
|
675
|
+
return input;
|
|
676
|
+
}, z3.json());
|
|
677
|
+
var nodeIdSchema = z3.string().regex(NODE_ID_RE);
|
|
678
|
+
var COLOR_VALUE_RE = /^(?:token:[a-z][a-z0-9-]{0,30}|#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?)$/;
|
|
679
|
+
var colorValueSchema = z3.string().regex(COLOR_VALUE_RE);
|
|
680
|
+
var SPACING_TOKENS = ["none", "xs", "s", "m", "l", "xl", "2xl"];
|
|
681
|
+
var spacingValueSchema = z3.union([
|
|
682
|
+
z3.enum(SPACING_TOKENS),
|
|
683
|
+
z3.number().min(0).max(400)
|
|
684
|
+
]);
|
|
685
|
+
var ANCHOR_RE = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
686
|
+
var anchorSchema = z3.string().regex(ANCHOR_RE);
|
|
687
|
+
var VERTICAL_ALIGN = ["top", "center", "bottom", "stretch"];
|
|
688
|
+
var backgroundSchema = z3.object({
|
|
689
|
+
color: colorValueSchema.optional(),
|
|
690
|
+
image: assetIdSchema.optional(),
|
|
691
|
+
overlay: colorValueSchema.optional(),
|
|
692
|
+
position: z3.enum([
|
|
693
|
+
"center",
|
|
694
|
+
"top",
|
|
695
|
+
"bottom",
|
|
696
|
+
"left",
|
|
697
|
+
"right",
|
|
698
|
+
"top left",
|
|
699
|
+
"top right",
|
|
700
|
+
"bottom left",
|
|
701
|
+
"bottom right"
|
|
702
|
+
]).optional(),
|
|
703
|
+
size: z3.enum(["cover", "contain", "auto"]).optional()
|
|
704
|
+
}).strict();
|
|
705
|
+
var sectionPropsSchema = z3.object({
|
|
706
|
+
width: z3.enum(["boxed", "full"]),
|
|
707
|
+
contentWidth: z3.number().int().min(600).max(1600),
|
|
708
|
+
gap: spacingValueSchema,
|
|
709
|
+
paddingY: spacingValueSchema,
|
|
710
|
+
paddingX: spacingValueSchema,
|
|
711
|
+
minHeight: z3.number().min(0).max(2e3),
|
|
712
|
+
verticalAlign: z3.enum(VERTICAL_ALIGN),
|
|
713
|
+
background: backgroundSchema,
|
|
714
|
+
stackOrder: z3.enum(["normal", "reverse"]),
|
|
715
|
+
hidden: z3.boolean(),
|
|
716
|
+
anchor: anchorSchema
|
|
717
|
+
}).partial().strict();
|
|
718
|
+
var columnWidth = z3.number().min(10).max(100).refine((w) => Math.abs(w * 100 - Math.round(w * 100)) < 1e-6, {
|
|
719
|
+
message: "A column width has at most 2 decimals"
|
|
720
|
+
});
|
|
721
|
+
var columnPropsShape = {
|
|
722
|
+
width: columnWidth,
|
|
723
|
+
verticalAlign: z3.enum(VERTICAL_ALIGN),
|
|
724
|
+
padding: spacingValueSchema,
|
|
725
|
+
background: backgroundSchema,
|
|
726
|
+
hidden: z3.boolean(),
|
|
727
|
+
anchor: anchorSchema
|
|
728
|
+
};
|
|
729
|
+
var columnPropsSchema = z3.object({ ...columnPropsShape, width: columnPropsShape.width }).partial({ verticalAlign: true, padding: true, background: true, hidden: true, anchor: true }).strict();
|
|
730
|
+
function overridesOf(shape) {
|
|
731
|
+
const entries = Object.entries(shape).map(
|
|
732
|
+
([key, schema]) => [key, schema.nullable().optional()]
|
|
733
|
+
);
|
|
734
|
+
return Object.fromEntries(entries);
|
|
735
|
+
}
|
|
736
|
+
function responsiveOf(shape) {
|
|
737
|
+
const device = z3.object(overridesOf(shape)).strict();
|
|
738
|
+
return z3.object({ tablet: device.optional(), phone: device.optional() }).strict();
|
|
739
|
+
}
|
|
740
|
+
var sectionResponsive = responsiveOf(sectionPropsSchema.shape);
|
|
741
|
+
var columnResponsive = responsiveOf(columnPropsShape);
|
|
742
|
+
var WIDGET_TYPE_RE = /^(?:basic|catalog|commerce|custom)\.[a-z][a-z0-9-]{0,63}$/;
|
|
743
|
+
var widgetTypeSchema = z3.string().superRefine((value, ctx) => {
|
|
744
|
+
if (value === "inner-section") {
|
|
745
|
+
customIssue(
|
|
746
|
+
ctx,
|
|
747
|
+
"INNER_IN_INNER",
|
|
748
|
+
"An inner section can't go inside another inner section."
|
|
749
|
+
);
|
|
750
|
+
} else if (!WIDGET_TYPE_RE.test(value)) {
|
|
751
|
+
customIssue(
|
|
752
|
+
ctx,
|
|
753
|
+
"INVALID_WIDGET_TYPE",
|
|
754
|
+
"A widget type starts with basic., catalog., commerce. or custom."
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
var dataNameSchema = z3.string().regex(/^[a-z][A-Za-z0-9_]{0,39}$/);
|
|
759
|
+
var dataBindingSchema = z3.union([
|
|
760
|
+
z3.object({ source: z3.string().regex(/^context\.[a-z][a-z0-9-]{0,39}$/) }).strict(),
|
|
761
|
+
z3.object({
|
|
762
|
+
source: z3.string().regex(/^(?!context\.)[a-z][a-z0-9]*\.[a-z][a-z0-9-]{0,39}$/),
|
|
763
|
+
params: safeRecord(settingValueSchema)
|
|
764
|
+
}).strict()
|
|
765
|
+
]);
|
|
766
|
+
var settingsRecord = safeRecord(settingValueSchema);
|
|
767
|
+
var widgetNodeSchema = z3.object({
|
|
768
|
+
id: nodeIdSchema,
|
|
769
|
+
type: widgetTypeSchema,
|
|
770
|
+
v: z3.number().int().min(1).max(9999),
|
|
771
|
+
props: settingsRecord,
|
|
772
|
+
responsive: z3.object({
|
|
773
|
+
tablet: safeRecord(settingValueSchema).optional(),
|
|
774
|
+
phone: safeRecord(settingValueSchema).optional()
|
|
775
|
+
}).strict().optional(),
|
|
776
|
+
data: safeRecord(dataBindingSchema, dataNameSchema).optional()
|
|
777
|
+
}).strict();
|
|
778
|
+
var innerColumnNodeSchema = z3.object({
|
|
779
|
+
id: nodeIdSchema,
|
|
780
|
+
type: z3.literal("column"),
|
|
781
|
+
props: columnPropsSchema,
|
|
782
|
+
responsive: columnResponsive.optional(),
|
|
783
|
+
children: z3.array(widgetNodeSchema).max(LIMITS.childrenPerColumn)
|
|
784
|
+
}).strict();
|
|
785
|
+
function checkColumnWidths(columns, ctx) {
|
|
786
|
+
const sum = columns.reduce((total, column) => total + column.props.width, 0);
|
|
787
|
+
if (Math.abs(sum - 100) > 0.05) {
|
|
788
|
+
customIssue(
|
|
789
|
+
ctx,
|
|
790
|
+
"INVALID_COLUMN_WIDTHS",
|
|
791
|
+
`Column widths add up to ${String(Math.round(sum * 100) / 100)}, not 100`,
|
|
792
|
+
["columns"]
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
for (const device of ["tablet", "phone"]) {
|
|
796
|
+
const set = columns.filter((column) => {
|
|
797
|
+
const width = column.responsive?.[device]?.width;
|
|
798
|
+
return typeof width === "number";
|
|
799
|
+
}).length;
|
|
800
|
+
if (set > 0 && set < columns.length) {
|
|
801
|
+
customIssue(
|
|
802
|
+
ctx,
|
|
803
|
+
"INVALID_COLUMN_WIDTHS",
|
|
804
|
+
`A ${device} width override must set every column of the section, or none`,
|
|
805
|
+
["columns"]
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
var columnsLength = { min: LIMITS.columnsMin, max: LIMITS.columnsMax };
|
|
811
|
+
var innerSectionNodeSchema = z3.object({
|
|
812
|
+
id: nodeIdSchema,
|
|
813
|
+
type: z3.literal("inner-section"),
|
|
814
|
+
props: sectionPropsSchema,
|
|
815
|
+
responsive: sectionResponsive.optional(),
|
|
816
|
+
columns: z3.array(innerColumnNodeSchema).min(columnsLength.min).max(columnsLength.max)
|
|
817
|
+
}).strict().superRefine((section, ctx) => checkColumnWidths(section.columns, ctx));
|
|
818
|
+
var columnNodeSchema = z3.object({
|
|
819
|
+
id: nodeIdSchema,
|
|
820
|
+
type: z3.literal("column"),
|
|
821
|
+
props: columnPropsSchema,
|
|
822
|
+
responsive: columnResponsive.optional(),
|
|
823
|
+
children: z3.array(z3.union([innerSectionNodeSchema, widgetNodeSchema])).max(LIMITS.childrenPerColumn)
|
|
824
|
+
}).strict();
|
|
825
|
+
var sectionNodeSchema = z3.object({
|
|
826
|
+
id: nodeIdSchema,
|
|
827
|
+
type: z3.literal("section"),
|
|
828
|
+
props: sectionPropsSchema,
|
|
829
|
+
responsive: sectionResponsive.optional(),
|
|
830
|
+
columns: z3.array(columnNodeSchema).min(columnsLength.min).max(columnsLength.max)
|
|
831
|
+
}).strict().superRefine((section, ctx) => checkColumnWidths(section.columns, ctx));
|
|
832
|
+
var assetUrl = z3.string().max(2e3).regex(SAFE_HREF);
|
|
833
|
+
var frozenAssetSchema = z3.object({
|
|
834
|
+
url: assetUrl,
|
|
835
|
+
width: z3.number().int().min(1).max(2e4),
|
|
836
|
+
height: z3.number().int().min(1).max(2e4),
|
|
837
|
+
variants: z3.array(
|
|
838
|
+
z3.object({ width: z3.number().int().min(1).max(2e4), url: assetUrl }).strict()
|
|
839
|
+
).max(12)
|
|
840
|
+
}).strict();
|
|
841
|
+
var CUSTOM_SNAPSHOT_KEY_RE = /^custom\.[a-z][a-z0-9-]{0,63}@[1-9][0-9]{0,3}$/;
|
|
842
|
+
var customWidgetSnapshotSchema = z3.object({
|
|
843
|
+
kind: z3.enum(["composite", "template"]),
|
|
844
|
+
type: z3.string().regex(/^custom\.[a-z][a-z0-9-]{0,63}$/),
|
|
845
|
+
v: z3.number().int().min(1).max(9999),
|
|
846
|
+
title: z3.string().max(100),
|
|
847
|
+
description: z3.string().max(500),
|
|
848
|
+
icon: z3.string().max(40),
|
|
849
|
+
group: z3.literal("custom"),
|
|
850
|
+
settings: z3.array(z3.record(z3.string(), z3.unknown())).max(LIMITS.widgetSettings),
|
|
851
|
+
renamed: z3.record(z3.string(), z3.string()).optional(),
|
|
852
|
+
removed: z3.array(z3.string()).optional()
|
|
853
|
+
}).loose();
|
|
854
|
+
var CURRENT_SCHEMA_VERSION = 1;
|
|
855
|
+
var pageDocumentSchema = z3.object({
|
|
856
|
+
schemaVersion: z3.literal(1),
|
|
857
|
+
sections: z3.array(sectionNodeSchema).max(LIMITS.sections),
|
|
858
|
+
// Published snapshots only.
|
|
859
|
+
customWidgets: safeRecord(
|
|
860
|
+
customWidgetSnapshotSchema,
|
|
861
|
+
z3.string().regex(CUSTOM_SNAPSHOT_KEY_RE)
|
|
862
|
+
).optional(),
|
|
863
|
+
assets: safeRecord(frozenAssetSchema, assetIdSchema).optional()
|
|
864
|
+
}).strict().superRefine((doc, ctx) => {
|
|
865
|
+
const seen = /* @__PURE__ */ new Set();
|
|
866
|
+
walkNodes(doc, (node, path) => {
|
|
867
|
+
if (seen.has(node.id)) {
|
|
868
|
+
customIssue(ctx, "DUPLICATE_ID", `Duplicate node id "${node.id}"`, [...path, "id"]);
|
|
869
|
+
}
|
|
870
|
+
seen.add(node.id);
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
function emptyDocument() {
|
|
874
|
+
return { schemaVersion: 1, sections: [] };
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/responsive.ts
|
|
878
|
+
var BREAKPOINTS = {
|
|
879
|
+
desktopMin: 1025,
|
|
880
|
+
tabletMin: 768,
|
|
881
|
+
tabletMax: 1024,
|
|
882
|
+
phoneMax: 767
|
|
883
|
+
};
|
|
884
|
+
var PREVIEW_WIDTHS = {
|
|
885
|
+
desktop: 1280,
|
|
886
|
+
tablet: 768,
|
|
887
|
+
phone: 390
|
|
888
|
+
};
|
|
889
|
+
var ROW_SLACK = 0.05;
|
|
890
|
+
function layer(into, overrides, skip) {
|
|
891
|
+
if (overrides === void 0) return;
|
|
892
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
893
|
+
if (value !== null && value !== void 0 && !skip.includes(key)) into[key] = value;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
function resolveResponsive(props, responsive, device, options = {}) {
|
|
897
|
+
if (device === "desktop" || responsive === void 0) return props;
|
|
898
|
+
const skip = options.skip ?? [];
|
|
899
|
+
const out = { ...props };
|
|
900
|
+
layer(out, responsive.tablet, skip);
|
|
901
|
+
if (device === "phone") {
|
|
902
|
+
layer(out, responsive.phone, skip);
|
|
903
|
+
}
|
|
904
|
+
return out;
|
|
905
|
+
}
|
|
906
|
+
function resolveColumnProps(props, responsive, device) {
|
|
907
|
+
return resolveResponsive(props, responsive, device, { skip: ["width"] });
|
|
908
|
+
}
|
|
909
|
+
function resolveColumnWidths(section, device) {
|
|
910
|
+
const columns = section.columns;
|
|
911
|
+
if (device === "desktop") return columns.map((c) => c.props.width);
|
|
912
|
+
return columns.map((column) => {
|
|
913
|
+
const override = column.responsive?.[device]?.width;
|
|
914
|
+
if (typeof override === "number") return override;
|
|
915
|
+
return device === "tablet" ? column.props.width : 100;
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
function wrapColumnRows(widths) {
|
|
919
|
+
const rows = [];
|
|
920
|
+
let row = [];
|
|
921
|
+
let used = 0;
|
|
922
|
+
widths.forEach((width, index) => {
|
|
923
|
+
if (row.length > 0 && used + width > 100 + ROW_SLACK) {
|
|
924
|
+
rows.push(row);
|
|
925
|
+
row = [];
|
|
926
|
+
used = 0;
|
|
927
|
+
}
|
|
928
|
+
row.push(index);
|
|
929
|
+
used += width;
|
|
930
|
+
});
|
|
931
|
+
if (row.length > 0) rows.push(row);
|
|
932
|
+
return rows;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// src/upgrade.ts
|
|
936
|
+
var MIGRATIONS = {};
|
|
937
|
+
function upgradeDocument(input) {
|
|
938
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
939
|
+
return {
|
|
940
|
+
ok: false,
|
|
941
|
+
issues: [makeIssue("", "INVALID_SHAPE", "A document is an object")]
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
let current = input;
|
|
945
|
+
const version = current.schemaVersion;
|
|
946
|
+
if (typeof version !== "number" || !Number.isInteger(version) || version < 1) {
|
|
947
|
+
return {
|
|
948
|
+
ok: false,
|
|
949
|
+
issues: [
|
|
950
|
+
makeIssue("schemaVersion", "INVALID_SHAPE", "schemaVersion is a positive integer")
|
|
951
|
+
]
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
if (version > CURRENT_SCHEMA_VERSION) {
|
|
955
|
+
return {
|
|
956
|
+
ok: false,
|
|
957
|
+
issues: [
|
|
958
|
+
makeIssue(
|
|
959
|
+
"schemaVersion",
|
|
960
|
+
"UNSUPPORTED_SCHEMA_VERSION",
|
|
961
|
+
`This document is schemaVersion ${String(version)}; this build reads up to ${String(CURRENT_SCHEMA_VERSION)}`
|
|
962
|
+
)
|
|
963
|
+
]
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
for (let from = version; from < CURRENT_SCHEMA_VERSION; from += 1) {
|
|
967
|
+
const step = MIGRATIONS[from];
|
|
968
|
+
if (step === void 0) {
|
|
969
|
+
return {
|
|
970
|
+
ok: false,
|
|
971
|
+
issues: [
|
|
972
|
+
makeIssue(
|
|
973
|
+
"schemaVersion",
|
|
974
|
+
"UNSUPPORTED_SCHEMA_VERSION",
|
|
975
|
+
`No migration from schemaVersion ${String(from)}`
|
|
976
|
+
)
|
|
977
|
+
]
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
current = { ...step(current), schemaVersion: from + 1 };
|
|
981
|
+
}
|
|
982
|
+
const parsed = pageDocumentSchema.safeParse(current);
|
|
983
|
+
if (!parsed.success) return { ok: false, issues: zodIssues(parsed.error) };
|
|
984
|
+
return { ok: true, doc: parsed.data };
|
|
985
|
+
}
|
|
986
|
+
function validateDocument(input) {
|
|
987
|
+
const upgraded = upgradeDocument(input);
|
|
988
|
+
if (!upgraded.ok) return upgraded;
|
|
989
|
+
const issues = checkLimits(upgraded.doc);
|
|
990
|
+
return issues.length > 0 ? { ok: false, issues } : upgraded;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// src/widgets.ts
|
|
994
|
+
import { z as z4 } from "zod";
|
|
995
|
+
var WIDGET_GROUPS = ["layout", "basic", "catalog", "commerce", "custom"];
|
|
996
|
+
var SETTING_TABS = ["content", "style", "advanced"];
|
|
997
|
+
var SETTING_CONTROLS = [
|
|
998
|
+
"text",
|
|
999
|
+
"richtext",
|
|
1000
|
+
"number",
|
|
1001
|
+
"select",
|
|
1002
|
+
"toggle",
|
|
1003
|
+
"color",
|
|
1004
|
+
"spacing",
|
|
1005
|
+
"image",
|
|
1006
|
+
"link",
|
|
1007
|
+
"icon",
|
|
1008
|
+
"alignment",
|
|
1009
|
+
"font-size"
|
|
1010
|
+
];
|
|
1011
|
+
var DATA_RESULT_TYPES = [
|
|
1012
|
+
"product[]",
|
|
1013
|
+
"product",
|
|
1014
|
+
"collection",
|
|
1015
|
+
"category[]",
|
|
1016
|
+
"review[]",
|
|
1017
|
+
"customer",
|
|
1018
|
+
"cart"
|
|
1019
|
+
];
|
|
1020
|
+
var settingValue = settingValueSchema;
|
|
1021
|
+
var settingFieldSchema = z4.object({
|
|
1022
|
+
key: z4.string().regex(/^[a-z][A-Za-z0-9]{0,39}$/),
|
|
1023
|
+
label: z4.string().min(1).max(100),
|
|
1024
|
+
tab: z4.enum(SETTING_TABS),
|
|
1025
|
+
output: z4.enum(["css", "markup"]),
|
|
1026
|
+
control: z4.enum(SETTING_CONTROLS),
|
|
1027
|
+
translatable: z4.boolean().optional(),
|
|
1028
|
+
default: settingValue,
|
|
1029
|
+
min: z4.number().optional(),
|
|
1030
|
+
max: z4.number().optional(),
|
|
1031
|
+
options: z4.array(z4.object({ value: z4.string().max(60), label: z4.string().max(100) }).strict()).max(50).optional(),
|
|
1032
|
+
maxLength: z4.number().int().min(1).max(2e4).optional()
|
|
1033
|
+
}).strict();
|
|
1034
|
+
var fieldSpecSchema = z4.object({
|
|
1035
|
+
/** A dotted path a template may read, such as `price.display`. */
|
|
1036
|
+
name: z4.string().regex(/^[a-z][A-Za-z0-9]*(?:\.[a-z][A-Za-z0-9]*)*$/),
|
|
1037
|
+
type: z4.enum(["string", "number", "boolean", "money", "image", "url", "date", "list"]),
|
|
1038
|
+
example: settingValue.optional()
|
|
1039
|
+
}).strict();
|
|
1040
|
+
var dataSourceDescriptorSchema = z4.object({
|
|
1041
|
+
id: z4.string().regex(/^[a-z][a-z0-9]*\.[a-z][a-z0-9-]*$/),
|
|
1042
|
+
provider: z4.enum(["catalog", "commerce"]),
|
|
1043
|
+
title: z4.string().min(1).max(100),
|
|
1044
|
+
description: z4.string().max(500),
|
|
1045
|
+
params: z4.array(settingFieldSchema).max(LIMITS.widgetSettings),
|
|
1046
|
+
result: z4.enum(DATA_RESULT_TYPES),
|
|
1047
|
+
fields: z4.array(fieldSpecSchema).max(200),
|
|
1048
|
+
perShopper: z4.boolean(),
|
|
1049
|
+
cacheKind: z4.enum(["listings", "product", "reviews", "none"])
|
|
1050
|
+
}).strict();
|
|
1051
|
+
var widgetDefinitionSchema = z4.object({
|
|
1052
|
+
type: z4.string().regex(WIDGET_TYPE_RE),
|
|
1053
|
+
v: z4.number().int().min(1).max(9999),
|
|
1054
|
+
title: z4.string().min(1).max(100),
|
|
1055
|
+
group: z4.enum(WIDGET_GROUPS),
|
|
1056
|
+
icon: z4.string().min(1).max(40),
|
|
1057
|
+
description: z4.string().min(1).max(500),
|
|
1058
|
+
settings: z4.array(settingFieldSchema).max(LIMITS.widgetSettings),
|
|
1059
|
+
data: z4.record(
|
|
1060
|
+
z4.string(),
|
|
1061
|
+
z4.object({
|
|
1062
|
+
accepts: z4.array(z4.enum(DATA_RESULT_TYPES)).min(1),
|
|
1063
|
+
required: z4.boolean(),
|
|
1064
|
+
default: dataBindingSchema.optional(),
|
|
1065
|
+
label: z4.string().min(1).max(100)
|
|
1066
|
+
}).strict()
|
|
1067
|
+
).optional(),
|
|
1068
|
+
placement: z4.object({
|
|
1069
|
+
slotsOnly: z4.boolean().optional(),
|
|
1070
|
+
notIn: z4.array(z4.enum(["header", "footer", "slot"])).optional()
|
|
1071
|
+
}).strict().optional()
|
|
1072
|
+
}).strict();
|
|
1073
|
+
var SIZE_TOKENS = ["xs", "s", "m", "l", "xl", "2xl", "3xl"];
|
|
1074
|
+
var ALIGNMENTS = ["left", "center", "right", "justify"];
|
|
1075
|
+
var LOCALE_KEY = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8}){0,3}$/;
|
|
1076
|
+
function fitsText(value, field2) {
|
|
1077
|
+
const max = field2.maxLength ?? 2e3;
|
|
1078
|
+
if (field2.translatable === true) {
|
|
1079
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1080
|
+
return "Expected a map of locale to text";
|
|
1081
|
+
}
|
|
1082
|
+
for (const [locale, text] of Object.entries(value)) {
|
|
1083
|
+
if (!LOCALE_KEY.test(locale)) return `"${locale}" is not a locale tag`;
|
|
1084
|
+
if (typeof text !== "string") return `The text for "${locale}" must be a string`;
|
|
1085
|
+
if (text.length > max) return `The text for "${locale}" is over ${String(max)} characters`;
|
|
1086
|
+
}
|
|
1087
|
+
return null;
|
|
1088
|
+
}
|
|
1089
|
+
if (typeof value !== "string") return "Expected text";
|
|
1090
|
+
if (value.length > max) return `Text is over ${String(max)} characters`;
|
|
1091
|
+
return null;
|
|
1092
|
+
}
|
|
1093
|
+
function validateSettingValue(field2, value) {
|
|
1094
|
+
if (value === null) {
|
|
1095
|
+
return field2.default === null ? null : "This setting cannot be empty";
|
|
1096
|
+
}
|
|
1097
|
+
switch (field2.control) {
|
|
1098
|
+
case "text":
|
|
1099
|
+
case "richtext":
|
|
1100
|
+
if (field2.key === "anchor") {
|
|
1101
|
+
return typeof value === "string" && ANCHOR_RE.test(value) ? null : "An anchor starts with a letter and uses letters, digits, - and _ (64 at most)";
|
|
1102
|
+
}
|
|
1103
|
+
return fitsText(value, field2);
|
|
1104
|
+
case "icon":
|
|
1105
|
+
return typeof value === "string" && /^[a-z][a-z0-9-]{0,39}$/.test(value) ? null : "Expected an icon name";
|
|
1106
|
+
case "number": {
|
|
1107
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return "Expected a number";
|
|
1108
|
+
if (field2.min !== void 0 && value < field2.min) return `Must be at least ${String(field2.min)}`;
|
|
1109
|
+
if (field2.max !== void 0 && value > field2.max) return `Must be at most ${String(field2.max)}`;
|
|
1110
|
+
return null;
|
|
1111
|
+
}
|
|
1112
|
+
case "select":
|
|
1113
|
+
return typeof value === "string" && (field2.options ?? []).some((o) => o.value === value) ? null : "Expected one of the listed options";
|
|
1114
|
+
case "toggle":
|
|
1115
|
+
return typeof value === "boolean" ? null : "Expected true or false";
|
|
1116
|
+
case "color":
|
|
1117
|
+
return typeof value === "string" && COLOR_VALUE_RE.test(value) ? null : "Expected token:name or #rrggbb[aa]";
|
|
1118
|
+
case "spacing":
|
|
1119
|
+
return typeof value === "string" && SPACING_TOKENS.includes(value) || typeof value === "number" && value >= 0 && value <= 400 ? null : "Expected a spacing token or 0 to 400 px";
|
|
1120
|
+
case "font-size":
|
|
1121
|
+
return typeof value === "string" && SIZE_TOKENS.includes(value) || typeof value === "number" && value >= 8 && value <= 200 ? null : "Expected a size token or 8 to 200 px";
|
|
1122
|
+
case "alignment":
|
|
1123
|
+
return typeof value === "string" && ALIGNMENTS.includes(value) ? null : "Expected an alignment";
|
|
1124
|
+
case "image":
|
|
1125
|
+
return typeof value === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(value) ? null : "Expected a media asset id";
|
|
1126
|
+
case "link":
|
|
1127
|
+
return menuTargetSchema.safeParse(value).success ? null : "Expected a link target";
|
|
1128
|
+
default:
|
|
1129
|
+
return "Unknown control";
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
function validateWidgetProps(def, props) {
|
|
1133
|
+
const byKey = new Map(def.settings.map((s) => [s.key, s]));
|
|
1134
|
+
const problems = [];
|
|
1135
|
+
for (const [key, value] of Object.entries(props)) {
|
|
1136
|
+
const field2 = byKey.get(key);
|
|
1137
|
+
if (field2 === void 0) {
|
|
1138
|
+
problems.push({ path: key, message: `Unknown setting "${key}"` });
|
|
1139
|
+
continue;
|
|
1140
|
+
}
|
|
1141
|
+
const message = validateSettingValue(field2, value);
|
|
1142
|
+
if (message !== null) problems.push({ path: key, message });
|
|
1143
|
+
}
|
|
1144
|
+
return problems;
|
|
1145
|
+
}
|
|
1146
|
+
function definitionOfSnapshot(snapshot) {
|
|
1147
|
+
const { type, v, title, description, icon, settings } = snapshot;
|
|
1148
|
+
const data = snapshot.data;
|
|
1149
|
+
return {
|
|
1150
|
+
type,
|
|
1151
|
+
v,
|
|
1152
|
+
title,
|
|
1153
|
+
group: "custom",
|
|
1154
|
+
icon,
|
|
1155
|
+
description,
|
|
1156
|
+
settings,
|
|
1157
|
+
...data === void 0 ? {} : { data }
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
function createRegistry(defs, sources, custom = []) {
|
|
1161
|
+
const byType = /* @__PURE__ */ new Map();
|
|
1162
|
+
const add = (def) => {
|
|
1163
|
+
let versions = byType.get(def.type);
|
|
1164
|
+
if (versions === void 0) {
|
|
1165
|
+
versions = /* @__PURE__ */ new Map();
|
|
1166
|
+
byType.set(def.type, versions);
|
|
1167
|
+
}
|
|
1168
|
+
if (versions.has(def.v)) {
|
|
1169
|
+
throw new Error(`Duplicate widget definition ${def.type}@${String(def.v)}`);
|
|
1170
|
+
}
|
|
1171
|
+
versions.set(def.v, def);
|
|
1172
|
+
};
|
|
1173
|
+
for (const def of defs) add(def);
|
|
1174
|
+
for (const snapshot of custom) add(definitionOfSnapshot(snapshot));
|
|
1175
|
+
const sourcesById = /* @__PURE__ */ new Map();
|
|
1176
|
+
for (const source of sources) {
|
|
1177
|
+
if (sourcesById.has(source.id)) throw new Error(`Duplicate data source ${source.id}`);
|
|
1178
|
+
sourcesById.set(source.id, source);
|
|
1179
|
+
}
|
|
1180
|
+
const latest = (type) => {
|
|
1181
|
+
const versions = byType.get(type);
|
|
1182
|
+
if (versions === void 0) return void 0;
|
|
1183
|
+
let best;
|
|
1184
|
+
for (const def of versions.values()) if (best === void 0 || def.v > best.v) best = def;
|
|
1185
|
+
return best;
|
|
1186
|
+
};
|
|
1187
|
+
return {
|
|
1188
|
+
widget: (type, v) => byType.get(type)?.get(v),
|
|
1189
|
+
latest,
|
|
1190
|
+
source: (id) => sourcesById.get(id),
|
|
1191
|
+
all: () => [...byType.keys()].sort().map((type) => latest(type)).filter((def) => def !== void 0)
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// src/basics.ts
|
|
1196
|
+
var opts = (...values) => values.map((value) => ({ value, label: value.charAt(0).toUpperCase() + value.slice(1) }));
|
|
1197
|
+
var field = (f) => f;
|
|
1198
|
+
var translatableText = (key, label, fallback, extra = {}) => field({
|
|
1199
|
+
key,
|
|
1200
|
+
label,
|
|
1201
|
+
tab: "content",
|
|
1202
|
+
output: "markup",
|
|
1203
|
+
control: "text",
|
|
1204
|
+
translatable: true,
|
|
1205
|
+
default: { en: fallback },
|
|
1206
|
+
maxLength: 500,
|
|
1207
|
+
...extra
|
|
1208
|
+
});
|
|
1209
|
+
var align = (fallback = "left") => field({
|
|
1210
|
+
key: "align",
|
|
1211
|
+
label: "Alignment",
|
|
1212
|
+
tab: "style",
|
|
1213
|
+
output: "css",
|
|
1214
|
+
control: "alignment",
|
|
1215
|
+
default: fallback
|
|
1216
|
+
});
|
|
1217
|
+
var color = (key = "color", label = "Colour") => field({ key, label, tab: "style", output: "css", control: "color", default: null });
|
|
1218
|
+
var size = (fallback) => field({
|
|
1219
|
+
key: "size",
|
|
1220
|
+
label: "Size",
|
|
1221
|
+
tab: "style",
|
|
1222
|
+
output: "css",
|
|
1223
|
+
control: "font-size",
|
|
1224
|
+
default: fallback
|
|
1225
|
+
});
|
|
1226
|
+
var link = (label = "Link") => field({ key: "link", label, tab: "content", output: "markup", control: "link", default: null });
|
|
1227
|
+
var COMMON_WIDGET_SETTINGS = [
|
|
1228
|
+
field({
|
|
1229
|
+
key: "hidden",
|
|
1230
|
+
label: "Hide",
|
|
1231
|
+
tab: "advanced",
|
|
1232
|
+
output: "css",
|
|
1233
|
+
control: "toggle",
|
|
1234
|
+
default: false
|
|
1235
|
+
}),
|
|
1236
|
+
field({
|
|
1237
|
+
key: "anchor",
|
|
1238
|
+
label: "Anchor",
|
|
1239
|
+
tab: "advanced",
|
|
1240
|
+
output: "markup",
|
|
1241
|
+
control: "text",
|
|
1242
|
+
default: null,
|
|
1243
|
+
maxLength: 64
|
|
1244
|
+
}),
|
|
1245
|
+
field({
|
|
1246
|
+
key: "spacingTop",
|
|
1247
|
+
label: "Space above",
|
|
1248
|
+
tab: "style",
|
|
1249
|
+
output: "css",
|
|
1250
|
+
control: "spacing",
|
|
1251
|
+
default: "none"
|
|
1252
|
+
}),
|
|
1253
|
+
field({
|
|
1254
|
+
key: "spacingBottom",
|
|
1255
|
+
label: "Space below",
|
|
1256
|
+
tab: "style",
|
|
1257
|
+
output: "css",
|
|
1258
|
+
control: "spacing",
|
|
1259
|
+
default: "none"
|
|
1260
|
+
})
|
|
1261
|
+
];
|
|
1262
|
+
function basic(slug, title, icon, description, settings) {
|
|
1263
|
+
return {
|
|
1264
|
+
type: `basic.${slug}`,
|
|
1265
|
+
v: 1,
|
|
1266
|
+
title,
|
|
1267
|
+
group: "basic",
|
|
1268
|
+
icon,
|
|
1269
|
+
description,
|
|
1270
|
+
settings: [...settings, ...COMMON_WIDGET_SETTINGS],
|
|
1271
|
+
migrations: {}
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
var BASIC_WIDGET_DEFINITIONS = [
|
|
1275
|
+
basic("heading", "Heading", "heading", "A heading of level 1 to 6.", [
|
|
1276
|
+
translatableText("text", "Text", "Heading"),
|
|
1277
|
+
field({
|
|
1278
|
+
key: "level",
|
|
1279
|
+
label: "Level",
|
|
1280
|
+
tab: "content",
|
|
1281
|
+
output: "markup",
|
|
1282
|
+
control: "select",
|
|
1283
|
+
options: opts("h1", "h2", "h3", "h4", "h5", "h6"),
|
|
1284
|
+
default: "h2"
|
|
1285
|
+
}),
|
|
1286
|
+
align(),
|
|
1287
|
+
color(),
|
|
1288
|
+
size("l")
|
|
1289
|
+
]),
|
|
1290
|
+
basic("text", "Text", "text", "Rich text: paragraphs, lists, links and basic emphasis.", [
|
|
1291
|
+
field({
|
|
1292
|
+
key: "html",
|
|
1293
|
+
label: "Text",
|
|
1294
|
+
tab: "content",
|
|
1295
|
+
output: "markup",
|
|
1296
|
+
control: "richtext",
|
|
1297
|
+
translatable: true,
|
|
1298
|
+
default: { en: "<p>Write something here.</p>" },
|
|
1299
|
+
maxLength: 2e4
|
|
1300
|
+
}),
|
|
1301
|
+
align(),
|
|
1302
|
+
color(),
|
|
1303
|
+
size("m")
|
|
1304
|
+
]),
|
|
1305
|
+
basic("image", "Image", "image", "An image from the media library, with optional link.", [
|
|
1306
|
+
field({
|
|
1307
|
+
key: "image",
|
|
1308
|
+
label: "Image",
|
|
1309
|
+
tab: "content",
|
|
1310
|
+
output: "markup",
|
|
1311
|
+
control: "image",
|
|
1312
|
+
default: null
|
|
1313
|
+
}),
|
|
1314
|
+
translatableText("alt", "Alt text", "", { maxLength: 300 }),
|
|
1315
|
+
field({
|
|
1316
|
+
key: "decorative",
|
|
1317
|
+
label: "Decorative (no alt text)",
|
|
1318
|
+
tab: "content",
|
|
1319
|
+
output: "markup",
|
|
1320
|
+
control: "toggle",
|
|
1321
|
+
default: false
|
|
1322
|
+
}),
|
|
1323
|
+
link(),
|
|
1324
|
+
field({
|
|
1325
|
+
key: "width",
|
|
1326
|
+
label: "Width (%)",
|
|
1327
|
+
tab: "style",
|
|
1328
|
+
output: "css",
|
|
1329
|
+
control: "number",
|
|
1330
|
+
min: 1,
|
|
1331
|
+
max: 100,
|
|
1332
|
+
default: 100
|
|
1333
|
+
}),
|
|
1334
|
+
field({
|
|
1335
|
+
key: "height",
|
|
1336
|
+
label: "Height (px)",
|
|
1337
|
+
tab: "style",
|
|
1338
|
+
output: "css",
|
|
1339
|
+
control: "number",
|
|
1340
|
+
min: 20,
|
|
1341
|
+
max: 2e3,
|
|
1342
|
+
default: null
|
|
1343
|
+
}),
|
|
1344
|
+
field({
|
|
1345
|
+
key: "radius",
|
|
1346
|
+
label: "Corner radius",
|
|
1347
|
+
tab: "style",
|
|
1348
|
+
output: "css",
|
|
1349
|
+
control: "select",
|
|
1350
|
+
options: opts("none", "s", "m", "l", "full"),
|
|
1351
|
+
default: "none"
|
|
1352
|
+
}),
|
|
1353
|
+
field({
|
|
1354
|
+
key: "fit",
|
|
1355
|
+
label: "Fit",
|
|
1356
|
+
tab: "style",
|
|
1357
|
+
output: "css",
|
|
1358
|
+
control: "select",
|
|
1359
|
+
options: opts("cover", "contain"),
|
|
1360
|
+
default: "cover"
|
|
1361
|
+
}),
|
|
1362
|
+
align()
|
|
1363
|
+
]),
|
|
1364
|
+
basic("button", "Button", "button", "A button or link with a label.", [
|
|
1365
|
+
translatableText("label", "Label", "Button", { maxLength: 100 }),
|
|
1366
|
+
link(),
|
|
1367
|
+
field({
|
|
1368
|
+
key: "style",
|
|
1369
|
+
label: "Style",
|
|
1370
|
+
tab: "style",
|
|
1371
|
+
output: "markup",
|
|
1372
|
+
control: "select",
|
|
1373
|
+
options: opts("primary", "secondary", "outline", "link"),
|
|
1374
|
+
default: "primary"
|
|
1375
|
+
}),
|
|
1376
|
+
field({
|
|
1377
|
+
key: "size",
|
|
1378
|
+
label: "Size",
|
|
1379
|
+
tab: "style",
|
|
1380
|
+
output: "markup",
|
|
1381
|
+
control: "select",
|
|
1382
|
+
options: opts("s", "m", "l"),
|
|
1383
|
+
default: "m"
|
|
1384
|
+
}),
|
|
1385
|
+
align(),
|
|
1386
|
+
field({
|
|
1387
|
+
key: "fullWidth",
|
|
1388
|
+
label: "Full width",
|
|
1389
|
+
tab: "style",
|
|
1390
|
+
output: "css",
|
|
1391
|
+
control: "toggle",
|
|
1392
|
+
default: false
|
|
1393
|
+
})
|
|
1394
|
+
]),
|
|
1395
|
+
basic("spacer", "Spacer", "spacer", "Empty vertical space.", [
|
|
1396
|
+
field({
|
|
1397
|
+
key: "height",
|
|
1398
|
+
label: "Height",
|
|
1399
|
+
tab: "style",
|
|
1400
|
+
output: "css",
|
|
1401
|
+
control: "spacing",
|
|
1402
|
+
default: "l"
|
|
1403
|
+
})
|
|
1404
|
+
]),
|
|
1405
|
+
basic("divider", "Divider", "divider", "A horizontal line.", [
|
|
1406
|
+
color(),
|
|
1407
|
+
field({
|
|
1408
|
+
key: "thickness",
|
|
1409
|
+
label: "Thickness (px)",
|
|
1410
|
+
tab: "style",
|
|
1411
|
+
output: "css",
|
|
1412
|
+
control: "number",
|
|
1413
|
+
min: 1,
|
|
1414
|
+
max: 20,
|
|
1415
|
+
default: 1
|
|
1416
|
+
}),
|
|
1417
|
+
field({
|
|
1418
|
+
key: "width",
|
|
1419
|
+
label: "Width (%)",
|
|
1420
|
+
tab: "style",
|
|
1421
|
+
output: "css",
|
|
1422
|
+
control: "number",
|
|
1423
|
+
min: 1,
|
|
1424
|
+
max: 100,
|
|
1425
|
+
default: 100
|
|
1426
|
+
}),
|
|
1427
|
+
field({
|
|
1428
|
+
key: "style",
|
|
1429
|
+
label: "Style",
|
|
1430
|
+
tab: "style",
|
|
1431
|
+
output: "css",
|
|
1432
|
+
control: "select",
|
|
1433
|
+
options: opts("solid", "dashed", "dotted"),
|
|
1434
|
+
default: "solid"
|
|
1435
|
+
})
|
|
1436
|
+
]),
|
|
1437
|
+
basic("video", "Video", "video", "A YouTube or Vimeo video behind a click-to-load poster.", [
|
|
1438
|
+
field({
|
|
1439
|
+
key: "url",
|
|
1440
|
+
label: "YouTube or Vimeo URL",
|
|
1441
|
+
tab: "content",
|
|
1442
|
+
output: "markup",
|
|
1443
|
+
control: "text",
|
|
1444
|
+
default: "",
|
|
1445
|
+
maxLength: 500
|
|
1446
|
+
}),
|
|
1447
|
+
field({
|
|
1448
|
+
key: "ratio",
|
|
1449
|
+
label: "Aspect ratio",
|
|
1450
|
+
tab: "style",
|
|
1451
|
+
output: "css",
|
|
1452
|
+
control: "select",
|
|
1453
|
+
options: [
|
|
1454
|
+
{ value: "16:9", label: "16:9" },
|
|
1455
|
+
{ value: "4:3", label: "4:3" },
|
|
1456
|
+
{ value: "1:1", label: "1:1" },
|
|
1457
|
+
{ value: "9:16", label: "9:16" }
|
|
1458
|
+
],
|
|
1459
|
+
default: "16:9"
|
|
1460
|
+
}),
|
|
1461
|
+
field({
|
|
1462
|
+
key: "autoplayMuted",
|
|
1463
|
+
label: "Autoplay muted",
|
|
1464
|
+
tab: "content",
|
|
1465
|
+
output: "markup",
|
|
1466
|
+
control: "toggle",
|
|
1467
|
+
default: false
|
|
1468
|
+
})
|
|
1469
|
+
]),
|
|
1470
|
+
basic("logo", "Logo", "logo", "The store's logo from Site settings, linked to the home page.", [
|
|
1471
|
+
field({
|
|
1472
|
+
key: "height",
|
|
1473
|
+
label: "Height (px)",
|
|
1474
|
+
tab: "style",
|
|
1475
|
+
output: "css",
|
|
1476
|
+
control: "number",
|
|
1477
|
+
min: 16,
|
|
1478
|
+
max: 200,
|
|
1479
|
+
default: 40
|
|
1480
|
+
}),
|
|
1481
|
+
link("Link (home by default)"),
|
|
1482
|
+
align()
|
|
1483
|
+
]),
|
|
1484
|
+
basic("menu", "Menu", "menu", "A named menu from Site settings.", [
|
|
1485
|
+
field({
|
|
1486
|
+
key: "menu",
|
|
1487
|
+
label: "Menu name",
|
|
1488
|
+
tab: "content",
|
|
1489
|
+
output: "markup",
|
|
1490
|
+
control: "text",
|
|
1491
|
+
default: "header",
|
|
1492
|
+
maxLength: 40
|
|
1493
|
+
}),
|
|
1494
|
+
field({
|
|
1495
|
+
key: "layout",
|
|
1496
|
+
label: "Layout",
|
|
1497
|
+
tab: "content",
|
|
1498
|
+
output: "markup",
|
|
1499
|
+
control: "select",
|
|
1500
|
+
options: [
|
|
1501
|
+
{ value: "horizontal", label: "Horizontal" },
|
|
1502
|
+
{ value: "vertical", label: "Vertical" },
|
|
1503
|
+
{ value: "drawer-on-phone", label: "Drawer on phone" }
|
|
1504
|
+
],
|
|
1505
|
+
default: "horizontal"
|
|
1506
|
+
}),
|
|
1507
|
+
align(),
|
|
1508
|
+
color(),
|
|
1509
|
+
size("m")
|
|
1510
|
+
]),
|
|
1511
|
+
basic("announcement", "Announcement", "megaphone", "The store's announcement bar from Site settings.", [
|
|
1512
|
+
field({
|
|
1513
|
+
key: "dismissible",
|
|
1514
|
+
label: "Visitors can dismiss it",
|
|
1515
|
+
tab: "content",
|
|
1516
|
+
output: "markup",
|
|
1517
|
+
control: "toggle",
|
|
1518
|
+
default: true
|
|
1519
|
+
}),
|
|
1520
|
+
align("center"),
|
|
1521
|
+
color(),
|
|
1522
|
+
color("background", "Background")
|
|
1523
|
+
]),
|
|
1524
|
+
basic("copyright", "Copyright", "copyright", "The copyright line from the site wording.", [
|
|
1525
|
+
align("center"),
|
|
1526
|
+
color(),
|
|
1527
|
+
size("s")
|
|
1528
|
+
])
|
|
1529
|
+
];
|
|
1530
|
+
export {
|
|
1531
|
+
ANCHOR_RE,
|
|
1532
|
+
BASIC_WIDGET_DEFINITIONS,
|
|
1533
|
+
BREAKPOINTS,
|
|
1534
|
+
CATALOG_STRING_KEYS,
|
|
1535
|
+
COLOR_VALUE_RE,
|
|
1536
|
+
COMMON_WIDGET_SETTINGS,
|
|
1537
|
+
CURRENT_SCHEMA_VERSION,
|
|
1538
|
+
DATA_RESULT_TYPES,
|
|
1539
|
+
ISSUE_CODES,
|
|
1540
|
+
LIMITS,
|
|
1541
|
+
LOCALE_TAG_RE,
|
|
1542
|
+
MAX_ISSUES,
|
|
1543
|
+
NODE_ID_RE,
|
|
1544
|
+
PREVIEW_WIDTHS,
|
|
1545
|
+
SAFE_HREF,
|
|
1546
|
+
SETTING_CONTROLS,
|
|
1547
|
+
SETTING_TABS,
|
|
1548
|
+
SITE_ASSET_PATHS,
|
|
1549
|
+
SITE_FONTS,
|
|
1550
|
+
SITE_FONT_FAMILIES,
|
|
1551
|
+
SITE_SETTINGS_SCHEMA_VERSION,
|
|
1552
|
+
SITE_STRING_DEFAULTS,
|
|
1553
|
+
SITE_STRING_KEYS,
|
|
1554
|
+
SITE_STRING_NAMESPACES,
|
|
1555
|
+
SPACING_TOKENS,
|
|
1556
|
+
THROTTLE_PK_RE,
|
|
1557
|
+
WIDGET_GROUPS,
|
|
1558
|
+
WIDGET_TYPE_RE,
|
|
1559
|
+
assetIdSchema,
|
|
1560
|
+
capIssues,
|
|
1561
|
+
checkLimits,
|
|
1562
|
+
colorValueSchema,
|
|
1563
|
+
columnPropsSchema,
|
|
1564
|
+
createRegistry,
|
|
1565
|
+
customWidgetSnapshotSchema,
|
|
1566
|
+
dataBindingSchema,
|
|
1567
|
+
dataSourceDescriptorSchema,
|
|
1568
|
+
defaultSiteSettings,
|
|
1569
|
+
emptyDocument,
|
|
1570
|
+
fieldSpecSchema,
|
|
1571
|
+
formatPath,
|
|
1572
|
+
frozenAssetSchema,
|
|
1573
|
+
isSettingValue,
|
|
1574
|
+
localeTagSchema,
|
|
1575
|
+
localizedTextSchema,
|
|
1576
|
+
makeIssue,
|
|
1577
|
+
menuItemSchema,
|
|
1578
|
+
menuTargetSchema,
|
|
1579
|
+
newNodeId,
|
|
1580
|
+
nodeIdSchema,
|
|
1581
|
+
pageDocumentSchema,
|
|
1582
|
+
resolveColumnProps,
|
|
1583
|
+
resolveColumnWidths,
|
|
1584
|
+
resolveResponsive,
|
|
1585
|
+
sectionPropsSchema,
|
|
1586
|
+
settingFieldSchema,
|
|
1587
|
+
settingValueSchema,
|
|
1588
|
+
siteSettingsSchema,
|
|
1589
|
+
spacingValueSchema,
|
|
1590
|
+
upgradeDocument,
|
|
1591
|
+
utf8Length,
|
|
1592
|
+
validateDocument,
|
|
1593
|
+
validateSettingValue,
|
|
1594
|
+
validateWidgetProps,
|
|
1595
|
+
walkNodes,
|
|
1596
|
+
widgetDefinitionSchema,
|
|
1597
|
+
wrapColumnRows,
|
|
1598
|
+
zodIssues
|
|
1599
|
+
};
|