@orion-studios/payload-studio 0.6.0-beta.16 → 0.6.0-beta.161

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.
Files changed (38) hide show
  1. package/dist/admin/client.js +2056 -543
  2. package/dist/admin/client.mjs +2101 -601
  3. package/dist/admin/index.js +124 -15
  4. package/dist/admin/index.mjs +2 -2
  5. package/dist/admin-app/client.js +14 -5
  6. package/dist/admin-app/client.mjs +1 -1
  7. package/dist/admin-app/styles.css +257 -0
  8. package/dist/admin.css +80 -0
  9. package/dist/builder-v2/client.d.mts +18 -0
  10. package/dist/builder-v2/client.d.ts +18 -0
  11. package/dist/builder-v2/client.js +4118 -0
  12. package/dist/builder-v2/client.mjs +3993 -0
  13. package/dist/builder-v2/index.d.mts +249 -0
  14. package/dist/builder-v2/index.d.ts +249 -0
  15. package/dist/builder-v2/index.js +805 -0
  16. package/dist/builder-v2/index.mjs +755 -0
  17. package/dist/builder-v2/styles.css +2693 -0
  18. package/dist/{chunk-XKUTZ7IU.mjs → chunk-276KAPGM.mjs} +56 -5
  19. package/dist/{chunk-PF3EBZXF.mjs → chunk-7ZMXZRBP.mjs} +39 -3
  20. package/dist/{chunk-XZQILJK3.mjs → chunk-KHK6RTGC.mjs} +127 -18
  21. package/dist/{chunk-KPIX7OSV.mjs → chunk-NF37A575.mjs} +14 -5
  22. package/dist/{chunk-OTHERBGX.mjs → chunk-ZADL33R6.mjs} +1 -1
  23. package/dist/{index-Cv-6qnrw.d.mts → index-D5zrOdyv.d.mts} +3 -1
  24. package/dist/{index-Crx_MtPw.d.ts → index-Dv-Alx4h.d.ts} +3 -1
  25. package/dist/index.d.mts +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +215 -19
  28. package/dist/index.mjs +10 -10
  29. package/dist/nextjs/index.js +39 -3
  30. package/dist/nextjs/index.mjs +2 -2
  31. package/dist/studio-pages/builder.css +66 -5
  32. package/dist/studio-pages/client.js +618 -73
  33. package/dist/studio-pages/client.mjs +641 -96
  34. package/dist/studio-pages/index.d.mts +1 -1
  35. package/dist/studio-pages/index.d.ts +1 -1
  36. package/dist/studio-pages/index.js +91 -4
  37. package/dist/studio-pages/index.mjs +3 -3
  38. package/package.json +22 -3
@@ -0,0 +1,755 @@
1
+ import "../chunk-6BWS3CLP.mjs";
2
+
3
+ // src/builder-v2/payload/builderFields.ts
4
+ var withHiddenAdmin = (field, hidden) => ({
5
+ ...field,
6
+ admin: {
7
+ ...field.admin || {},
8
+ hidden
9
+ }
10
+ });
11
+ var createBuilderV2PageFields = (options = {}) => {
12
+ const hidden = options.hidden ?? true;
13
+ return [
14
+ withHiddenAdmin(
15
+ {
16
+ name: "builderMode",
17
+ type: "select",
18
+ defaultValue: "studio-v1",
19
+ options: [
20
+ { label: "Classic Studio Builder", value: "studio-v1" },
21
+ { label: "Website Builder V2", value: "grapes-v2" }
22
+ ]
23
+ },
24
+ hidden
25
+ ),
26
+ withHiddenAdmin(
27
+ {
28
+ name: "builderProjectData",
29
+ type: "json"
30
+ },
31
+ hidden
32
+ ),
33
+ withHiddenAdmin(
34
+ {
35
+ name: "builderAutosaveProjectData",
36
+ type: "json"
37
+ },
38
+ hidden
39
+ ),
40
+ withHiddenAdmin(
41
+ {
42
+ name: "builderPublishedProjectData",
43
+ type: "json"
44
+ },
45
+ hidden
46
+ ),
47
+ withHiddenAdmin(
48
+ {
49
+ name: "compiledHtml",
50
+ type: "textarea"
51
+ },
52
+ hidden
53
+ ),
54
+ withHiddenAdmin(
55
+ {
56
+ name: "compiledCss",
57
+ type: "textarea"
58
+ },
59
+ hidden
60
+ ),
61
+ withHiddenAdmin(
62
+ {
63
+ name: "builderDynamicComponents",
64
+ type: "json"
65
+ },
66
+ hidden
67
+ ),
68
+ withHiddenAdmin(
69
+ {
70
+ name: "builderValidationIssues",
71
+ type: "json"
72
+ },
73
+ hidden
74
+ ),
75
+ withHiddenAdmin(
76
+ {
77
+ name: "builderVersions",
78
+ type: "json"
79
+ },
80
+ hidden
81
+ ),
82
+ withHiddenAdmin(
83
+ {
84
+ name: "builderPublishedSnapshot",
85
+ type: "json"
86
+ },
87
+ hidden
88
+ ),
89
+ withHiddenAdmin(
90
+ {
91
+ name: "builderReusableSections",
92
+ type: "json"
93
+ },
94
+ hidden
95
+ ),
96
+ withHiddenAdmin(
97
+ {
98
+ name: "builderThemeTokens",
99
+ type: "json"
100
+ },
101
+ hidden
102
+ ),
103
+ withHiddenAdmin(
104
+ {
105
+ name: "builderLockedAreas",
106
+ type: "json"
107
+ },
108
+ hidden
109
+ ),
110
+ withHiddenAdmin(
111
+ {
112
+ name: "builderSeo",
113
+ type: "json"
114
+ },
115
+ hidden
116
+ ),
117
+ withHiddenAdmin(
118
+ {
119
+ name: "builderLastSavedAt",
120
+ type: "date"
121
+ },
122
+ hidden
123
+ ),
124
+ withHiddenAdmin(
125
+ {
126
+ name: "builderLastPublishedAt",
127
+ type: "date"
128
+ },
129
+ hidden
130
+ )
131
+ ];
132
+ };
133
+ var appendBuilderV2PageFields = (fields, options) => [
134
+ ...fields,
135
+ ...createBuilderV2PageFields(options)
136
+ ];
137
+
138
+ // src/builder-v2/runtime/placeholders.ts
139
+ var placeholderPattern = /<(?<tag>[a-zA-Z][a-zA-Z0-9-]*)\b(?<attrs>[^>]*)data-orion-component=["'](?<component>[^"']+)["'](?<rest>[^>]*)>/gis;
140
+ var attrPattern = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)=(?:"([^"]*)"|'([^']*)')/g;
141
+ var decodeHtmlAttribute = (value) => value.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
142
+ var parseAttributes = (value) => {
143
+ const props = {};
144
+ let match;
145
+ while ((match = attrPattern.exec(value)) !== null) {
146
+ const name = match[1];
147
+ const rawValue = match[2] ?? match[3] ?? "";
148
+ if (!name.startsWith("data-")) {
149
+ continue;
150
+ }
151
+ if (name === "data-orion-component" || name === "data-orion-id") {
152
+ continue;
153
+ }
154
+ if (name === "data-orion-props") {
155
+ const decoded = decodeHtmlAttribute(rawValue);
156
+ try {
157
+ const parsed = JSON.parse(decoded);
158
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
159
+ Object.assign(props, parsed);
160
+ }
161
+ } catch {
162
+ props.propsJson = decoded;
163
+ }
164
+ continue;
165
+ }
166
+ const propName = name.replace(/^data-orion-/, "").replace(/^data-/, "").replace(/-([a-z])/g, (_, char) => char.toUpperCase());
167
+ props[propName] = decodeHtmlAttribute(rawValue);
168
+ }
169
+ return props;
170
+ };
171
+ var extractAttribute = (attrs, name) => {
172
+ attrPattern.lastIndex = 0;
173
+ let match;
174
+ while ((match = attrPattern.exec(attrs)) !== null) {
175
+ if (match[1] === name) {
176
+ return decodeHtmlAttribute(match[2] ?? match[3] ?? "");
177
+ }
178
+ }
179
+ return null;
180
+ };
181
+ var extractWrapperAttributes = (attrs) => {
182
+ const id = extractAttribute(attrs, "id") || void 0;
183
+ const className = extractAttribute(attrs, "class") || void 0;
184
+ const style = extractAttribute(attrs, "style") || void 0;
185
+ return id || className || style ? { className, id, style } : void 0;
186
+ };
187
+ var findPlaceholderEnd = (html, tag, startIndex) => {
188
+ const tagPattern = new RegExp(`<\\/?${tag}\\b[^>]*>`, "gi");
189
+ tagPattern.lastIndex = startIndex;
190
+ let depth = 1;
191
+ let match;
192
+ while ((match = tagPattern.exec(html)) !== null) {
193
+ const token = match[0];
194
+ const isClosing = token.startsWith("</");
195
+ const isSelfClosing = /\/\s*>$/.test(token);
196
+ if (isClosing) {
197
+ depth -= 1;
198
+ } else if (!isSelfClosing) {
199
+ depth += 1;
200
+ }
201
+ if (depth === 0) {
202
+ return tagPattern.lastIndex;
203
+ }
204
+ }
205
+ return startIndex;
206
+ };
207
+ var parseBuilderV2DynamicComponents = (html) => {
208
+ const instances = [];
209
+ let match;
210
+ while ((match = placeholderPattern.exec(html)) !== null) {
211
+ const attrs = `${match.groups?.attrs ?? ""} ${match.groups?.rest ?? ""}`;
212
+ const component = match.groups?.component ?? "";
213
+ if (!component) {
214
+ continue;
215
+ }
216
+ instances.push({
217
+ component,
218
+ id: extractAttribute(attrs, "data-orion-id") || `component-${instances.length + 1}`,
219
+ props: parseAttributes(attrs),
220
+ wrapperAttributes: extractWrapperAttributes(attrs)
221
+ });
222
+ }
223
+ return instances;
224
+ };
225
+ var splitBuilderV2HtmlIntoChunks = (html) => {
226
+ const chunks = [];
227
+ let lastIndex = 0;
228
+ let componentIndex = 0;
229
+ let match;
230
+ while ((match = placeholderPattern.exec(html)) !== null) {
231
+ const before = html.slice(lastIndex, match.index);
232
+ if (before.length > 0) {
233
+ chunks.push({ html: before, kind: "html" });
234
+ }
235
+ const attrs = `${match.groups?.attrs ?? ""} ${match.groups?.rest ?? ""}`;
236
+ const component = match.groups?.component ?? "";
237
+ const tag = match.groups?.tag ?? "";
238
+ const placeholderEnd = tag ? findPlaceholderEnd(html, tag, placeholderPattern.lastIndex) : placeholderPattern.lastIndex;
239
+ chunks.push({
240
+ instance: {
241
+ component,
242
+ id: extractAttribute(attrs, "data-orion-id") || `component-${componentIndex + 1}`,
243
+ props: parseAttributes(attrs),
244
+ wrapperAttributes: extractWrapperAttributes(attrs)
245
+ },
246
+ kind: "component"
247
+ });
248
+ componentIndex += 1;
249
+ lastIndex = placeholderEnd;
250
+ placeholderPattern.lastIndex = placeholderEnd;
251
+ }
252
+ const after = html.slice(lastIndex);
253
+ if (after.length > 0) {
254
+ chunks.push({ html: after, kind: "html" });
255
+ }
256
+ return chunks;
257
+ };
258
+
259
+ // src/builder-v2/sanitize.ts
260
+ import sanitizeHtml from "sanitize-html";
261
+ var allowedTags = sanitizeHtml.defaults.allowedTags.concat([
262
+ "article",
263
+ "aside",
264
+ "button",
265
+ "figure",
266
+ "figcaption",
267
+ "footer",
268
+ "header",
269
+ "main",
270
+ "nav",
271
+ "section",
272
+ "source",
273
+ "video"
274
+ ]);
275
+ var allowedAttributes = {
276
+ ...sanitizeHtml.defaults.allowedAttributes,
277
+ "*": [
278
+ "aria-*",
279
+ "class",
280
+ "data-*",
281
+ "id",
282
+ "role",
283
+ "style",
284
+ "title"
285
+ ],
286
+ a: ["aria-*", "class", "data-*", "href", "id", "name", "rel", "style", "target", "title"],
287
+ button: ["aria-*", "class", "data-*", "disabled", "id", "style", "title", "type"],
288
+ iframe: ["allow", "allowfullscreen", "class", "data-*", "height", "loading", "src", "style", "title", "width"],
289
+ img: ["alt", "class", "data-*", "height", "id", "loading", "sizes", "src", "srcset", "style", "title", "width"],
290
+ source: ["media", "src", "srcset", "type"],
291
+ video: ["autoplay", "class", "controls", "height", "loop", "muted", "playsinline", "poster", "preload", "src", "style", "width"]
292
+ };
293
+ var allowedIframeHosts = [
294
+ "calendar.google.com",
295
+ "calendly.com",
296
+ "player.vimeo.com",
297
+ "www.google.com",
298
+ "www.youtube.com",
299
+ "youtube.com"
300
+ ];
301
+ var sanitizeBuilderHtml = (value) => {
302
+ if (typeof value !== "string" || value.trim().length === 0) {
303
+ return "";
304
+ }
305
+ return sanitizeHtml(value, {
306
+ allowedAttributes,
307
+ allowedIframeHostnames: allowedIframeHosts,
308
+ allowedSchemes: ["http", "https", "mailto", "tel"],
309
+ allowedSchemesByTag: {
310
+ img: ["http", "https", "data"]
311
+ },
312
+ allowedTags,
313
+ allowProtocolRelative: false,
314
+ parseStyleAttributes: false
315
+ });
316
+ };
317
+ var sanitizeBuilderCss = (value) => {
318
+ if (typeof value !== "string" || value.trim().length === 0) {
319
+ return "";
320
+ }
321
+ return value.replace(/@import\s+[^;]+;/gi, "").replace(/expression\s*\(/gi, "").replace(/javascript\s*:/gi, "");
322
+ };
323
+ var scopeSelector = (selector, scope) => selector.split(",").map((part) => {
324
+ const trimmed = part.trim();
325
+ if (!trimmed || trimmed.startsWith(scope) || trimmed.startsWith("@")) {
326
+ return trimmed;
327
+ }
328
+ if (/^(html|body|:root)\b/i.test(trimmed)) {
329
+ return trimmed.replace(/^(html|body|:root)\b/i, scope);
330
+ }
331
+ return `${scope} ${trimmed}`;
332
+ }).filter(Boolean).join(", ");
333
+ var scopeBuilderCss = (value, scope = ".orion-builder-v2-runtime") => {
334
+ const css = sanitizeBuilderCss(value);
335
+ if (!css) {
336
+ return "";
337
+ }
338
+ let output = "";
339
+ let cursor = 0;
340
+ const rulePattern = /([^{}]+)\{/g;
341
+ let match;
342
+ while ((match = rulePattern.exec(css)) !== null) {
343
+ const selectorStart = match.index;
344
+ const selector = match[1];
345
+ output += css.slice(cursor, selectorStart);
346
+ const trimmedSelector = selector.trim();
347
+ if (trimmedSelector.startsWith("@keyframes") || trimmedSelector.startsWith("@font-face") || trimmedSelector.startsWith("@page")) {
348
+ output += `${selector}{`;
349
+ } else if (trimmedSelector.startsWith("@media") || trimmedSelector.startsWith("@supports")) {
350
+ output += `${selector}{`;
351
+ } else {
352
+ output += `${scopeSelector(selector, scope)} {`;
353
+ }
354
+ cursor = rulePattern.lastIndex;
355
+ }
356
+ output += css.slice(cursor);
357
+ return output;
358
+ };
359
+
360
+ // src/builder-v2/validation.ts
361
+ var hasMatch = (value, pattern) => pattern.test(value);
362
+ var validateBuilderV2Output = (input) => {
363
+ const html = typeof input.html === "string" ? input.html : "";
364
+ const css = typeof input.css === "string" ? input.css : "";
365
+ const issues = [];
366
+ if (!html.trim()) {
367
+ issues.push({
368
+ code: "empty-page",
369
+ message: "This page has no rendered content.",
370
+ path: "compiledHtml",
371
+ severity: "error"
372
+ });
373
+ }
374
+ if (!hasMatch(html, /<h1\b/i)) {
375
+ issues.push({
376
+ code: "missing-h1",
377
+ message: "Add one H1 so the published page has a clear primary heading.",
378
+ path: "compiledHtml",
379
+ severity: "warning"
380
+ });
381
+ }
382
+ if (hasMatch(html, /\son[a-z]+\s*=/i)) {
383
+ issues.push({
384
+ code: "inline-event-handler",
385
+ message: "Inline event handlers are not allowed in published builder HTML.",
386
+ path: "compiledHtml",
387
+ severity: "error"
388
+ });
389
+ }
390
+ if (hasMatch(html, /<(script|object|embed)\b/i)) {
391
+ issues.push({
392
+ code: "unsafe-element",
393
+ message: "Script, object, and embed tags are not allowed in builder content.",
394
+ path: "compiledHtml",
395
+ severity: "error"
396
+ });
397
+ }
398
+ if (hasMatch(html, /\b(?:href|src)=["']\s*javascript:/i)) {
399
+ issues.push({
400
+ code: "unsafe-url",
401
+ message: "Links and media cannot use javascript URLs.",
402
+ path: "compiledHtml",
403
+ severity: "error"
404
+ });
405
+ }
406
+ if (hasMatch(css, /@import\s/i)) {
407
+ issues.push({
408
+ code: "css-import",
409
+ message: "CSS imports are removed at publish time. Use the site font and theme managers instead.",
410
+ path: "compiledCss",
411
+ severity: "warning"
412
+ });
413
+ }
414
+ if (hasMatch(css, /position\s*:\s*fixed/i)) {
415
+ issues.push({
416
+ code: "fixed-position",
417
+ message: "Fixed positioning can cover site navigation or dialogs. Review this before publishing.",
418
+ path: "compiledCss",
419
+ severity: "warning"
420
+ });
421
+ }
422
+ return issues;
423
+ };
424
+ var hasBlockingBuilderV2Issues = (issues) => issues.some((issue) => issue.severity === "error");
425
+
426
+ // src/builder-v2/payload/compile.ts
427
+ var compileBuilderV2Output = (input) => {
428
+ const html = sanitizeBuilderHtml(input.html);
429
+ const css = scopeBuilderCss(input.css);
430
+ const validationIssues = validateBuilderV2Output({ css: input.css, html: input.html });
431
+ return {
432
+ css,
433
+ dynamicComponents: parseBuilderV2DynamicComponents(html),
434
+ html,
435
+ validationIssues
436
+ };
437
+ };
438
+
439
+ // src/builder-v2/projectData.ts
440
+ var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
441
+ var createEmptyBuilderV2ProjectData = (title = "Untitled Page") => ({
442
+ assets: [],
443
+ pages: [
444
+ {
445
+ component: {
446
+ components: [
447
+ {
448
+ attributes: {
449
+ class: "orion-builder-v2-section"
450
+ },
451
+ components: [
452
+ {
453
+ content: title,
454
+ tagName: "h1",
455
+ type: "text"
456
+ },
457
+ {
458
+ content: "Start building this page by dragging blocks from the panel.",
459
+ tagName: "p",
460
+ type: "text"
461
+ }
462
+ ],
463
+ tagName: "section"
464
+ }
465
+ ],
466
+ type: "wrapper"
467
+ },
468
+ id: "page",
469
+ name: title
470
+ }
471
+ ],
472
+ styles: []
473
+ });
474
+ var normalizeBuilderV2ProjectData = (value, fallbackTitle = "Untitled Page") => {
475
+ if (!isRecord(value)) {
476
+ return createEmptyBuilderV2ProjectData(fallbackTitle);
477
+ }
478
+ return value;
479
+ };
480
+
481
+ // src/builder-v2/payload/pageService.ts
482
+ var pageTitle = (page) => typeof page.title === "string" && page.title.trim().length > 0 ? page.title : "Untitled Page";
483
+ var normalizeVersions = (value) => Array.isArray(value) ? value.filter((item) => Boolean(item && typeof item === "object")) : [];
484
+ var createVersionSnapshot = ({
485
+ compiled,
486
+ label,
487
+ projectData,
488
+ published = false
489
+ }) => {
490
+ const createdAt = (/* @__PURE__ */ new Date()).toISOString();
491
+ return {
492
+ compiledCss: compiled.css,
493
+ compiledHtml: compiled.html,
494
+ createdAt,
495
+ id: `builder-v2-${createdAt.replace(/[^0-9]/g, "")}`,
496
+ label,
497
+ projectData,
498
+ published
499
+ };
500
+ };
501
+ var appendVersionSnapshot = (current, snapshot) => [snapshot, ...normalizeVersions(current)].slice(0, 50);
502
+ var toBuilderV2EditorInitialData = (page) => ({
503
+ projectData: normalizeBuilderV2ProjectData(
504
+ page.builderProjectData || page.builderPublishedProjectData,
505
+ pageTitle(page)
506
+ ),
507
+ title: pageTitle(page)
508
+ });
509
+ var createBuilderV2PageService = ({
510
+ collectionSlug = "pages",
511
+ payload,
512
+ user
513
+ }) => ({
514
+ getPageForBuilder: async (pageID) => {
515
+ const page = await payload.findByID({
516
+ collection: collectionSlug,
517
+ depth: 2,
518
+ draft: true,
519
+ id: pageID,
520
+ overrideAccess: false,
521
+ user
522
+ });
523
+ return {
524
+ id: String(page.id),
525
+ initialData: toBuilderV2EditorInitialData(page),
526
+ page
527
+ };
528
+ },
529
+ saveDraft: async (pageID, input) => {
530
+ const compiled = compileBuilderV2Output(input.compiled);
531
+ const existing = await payload.findByID({
532
+ collection: collectionSlug,
533
+ depth: 0,
534
+ draft: true,
535
+ id: pageID,
536
+ overrideAccess: false,
537
+ user
538
+ });
539
+ const validationIssues = input.validationIssues || compiled.validationIssues || [];
540
+ await payload.update({
541
+ collection: collectionSlug,
542
+ data: {
543
+ _status: "draft",
544
+ builderAutosaveProjectData: null,
545
+ builderDynamicComponents: compiled.dynamicComponents,
546
+ builderLastSavedAt: (/* @__PURE__ */ new Date()).toISOString(),
547
+ builderMode: "grapes-v2",
548
+ builderProjectData: input.projectData,
549
+ builderValidationIssues: validationIssues,
550
+ builderVersions: appendVersionSnapshot(
551
+ existing.builderVersions,
552
+ createVersionSnapshot({
553
+ compiled,
554
+ label: "Draft saved",
555
+ projectData: input.projectData
556
+ })
557
+ ),
558
+ compiledCss: compiled.css,
559
+ compiledHtml: compiled.html,
560
+ ...input.title ? { title: input.title } : {}
561
+ },
562
+ id: pageID,
563
+ overrideAccess: false,
564
+ user
565
+ });
566
+ return {
567
+ compiled,
568
+ id: pageID,
569
+ status: "draft"
570
+ };
571
+ },
572
+ publish: async (pageID, input) => {
573
+ const compiled = compileBuilderV2Output(input.compiled);
574
+ const existing = await payload.findByID({
575
+ collection: collectionSlug,
576
+ depth: 0,
577
+ draft: true,
578
+ id: pageID,
579
+ overrideAccess: false,
580
+ user
581
+ });
582
+ const validationIssues = input.validationIssues || compiled.validationIssues || [];
583
+ const snapshot = createVersionSnapshot({
584
+ compiled,
585
+ label: "Published",
586
+ projectData: input.projectData,
587
+ published: true
588
+ });
589
+ await payload.update({
590
+ collection: collectionSlug,
591
+ data: {
592
+ _status: "published",
593
+ builderAutosaveProjectData: null,
594
+ builderDynamicComponents: compiled.dynamicComponents,
595
+ builderLastPublishedAt: snapshot.createdAt,
596
+ builderLastSavedAt: snapshot.createdAt,
597
+ builderMode: "grapes-v2",
598
+ builderProjectData: input.projectData,
599
+ builderPublishedProjectData: input.projectData,
600
+ builderPublishedSnapshot: snapshot,
601
+ builderValidationIssues: validationIssues,
602
+ builderVersions: appendVersionSnapshot(existing.builderVersions, snapshot),
603
+ compiledCss: compiled.css,
604
+ compiledHtml: compiled.html,
605
+ ...input.title ? { title: input.title } : {}
606
+ },
607
+ id: pageID,
608
+ overrideAccess: false,
609
+ user
610
+ });
611
+ return {
612
+ compiled,
613
+ id: pageID,
614
+ status: "published"
615
+ };
616
+ }
617
+ });
618
+
619
+ // src/builder-v2/pageTree.ts
620
+ var relationId = (value) => {
621
+ if (typeof value === "number" || typeof value === "string") {
622
+ return value;
623
+ }
624
+ if (value && typeof value === "object") {
625
+ const id = value.id;
626
+ return typeof id === "number" || typeof id === "string" ? id : null;
627
+ }
628
+ return null;
629
+ };
630
+ var buildBuilderV2PageTree = (pages) => {
631
+ const nodes = /* @__PURE__ */ new Map();
632
+ const roots = [];
633
+ pages.forEach((page) => {
634
+ nodes.set(page.id, {
635
+ children: [],
636
+ id: page.id,
637
+ parentId: page.parentId ?? relationId(page.parent),
638
+ path: page.path || (page.slug ? `/${page.slug}` : "/"),
639
+ slug: page.slug || "",
640
+ status: page._status,
641
+ title: page.title || "Untitled page"
642
+ });
643
+ });
644
+ nodes.forEach((node) => {
645
+ if (node.parentId && nodes.has(node.parentId)) {
646
+ nodes.get(node.parentId)?.children?.push(node);
647
+ } else {
648
+ roots.push(node);
649
+ }
650
+ });
651
+ const sortNodes = (items) => {
652
+ items.sort((a, b) => a.path.localeCompare(b.path));
653
+ items.forEach((item) => sortNodes(item.children || []));
654
+ };
655
+ sortNodes(roots);
656
+ return roots;
657
+ };
658
+
659
+ // src/builder-v2/runtime/BuilderPageRuntime.tsx
660
+ import { createElement, Fragment } from "react";
661
+ import { jsx, jsxs } from "react/jsx-runtime";
662
+ var resolveRuntimeComponent = (adapter, type) => {
663
+ const definition = adapter?.components?.[type];
664
+ if (!definition) {
665
+ return null;
666
+ }
667
+ if (typeof definition === "function") {
668
+ return definition;
669
+ }
670
+ return definition.render;
671
+ };
672
+ var styleStringToReactStyle = (value) => {
673
+ if (!value) {
674
+ return void 0;
675
+ }
676
+ const style = value.split(";").map((declaration) => declaration.trim()).filter(Boolean).reduce((result, declaration) => {
677
+ const separatorIndex = declaration.indexOf(":");
678
+ if (separatorIndex <= 0) {
679
+ return result;
680
+ }
681
+ const property = declaration.slice(0, separatorIndex).trim();
682
+ const propertyValue = declaration.slice(separatorIndex + 1).trim();
683
+ if (!property || !propertyValue) {
684
+ return result;
685
+ }
686
+ const reactProperty = property.startsWith("--") ? property : property.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
687
+ result[reactProperty] = propertyValue;
688
+ return result;
689
+ }, {});
690
+ return Object.keys(style).length > 0 ? style : void 0;
691
+ };
692
+ function BuilderPageRuntime({ adapter, className, page }) {
693
+ const html = sanitizeBuilderHtml(page.compiledHtml);
694
+ const css = scopeBuilderCss(page.compiledCss);
695
+ const chunks = splitBuilderV2HtmlIntoChunks(html);
696
+ return /* @__PURE__ */ jsxs("div", { className: ["orion-builder-v2-runtime", className].filter(Boolean).join(" "), children: [
697
+ css ? /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: css } }) : null,
698
+ chunks.map((chunk, index) => {
699
+ if (chunk.kind === "html") {
700
+ return /* @__PURE__ */ jsx(
701
+ "div",
702
+ {
703
+ className: "orion-builder-v2-html-chunk",
704
+ dangerouslySetInnerHTML: { __html: chunk.html }
705
+ },
706
+ `html-${index}`
707
+ );
708
+ }
709
+ const Component = resolveRuntimeComponent(adapter, chunk.instance.component);
710
+ if (!Component) {
711
+ return /* @__PURE__ */ jsx(
712
+ "div",
713
+ {
714
+ className: "orion-builder-v2-missing-component",
715
+ "data-orion-missing-component": chunk.instance.component
716
+ },
717
+ `component-${chunk.instance.id}-${index}`
718
+ );
719
+ }
720
+ const renderedComponent = /* @__PURE__ */ jsx(Component, { instance: chunk.instance, page });
721
+ const wrapperAttributes = chunk.instance.wrapperAttributes;
722
+ if (wrapperAttributes?.id || wrapperAttributes?.className || wrapperAttributes?.style) {
723
+ return createElement(
724
+ "div",
725
+ {
726
+ className: wrapperAttributes.className,
727
+ id: wrapperAttributes.id,
728
+ key: `component-${chunk.instance.id}-${index}`,
729
+ style: styleStringToReactStyle(wrapperAttributes.style)
730
+ },
731
+ renderedComponent
732
+ );
733
+ }
734
+ return createElement(Fragment, { key: `component-${chunk.instance.id}-${index}` }, renderedComponent);
735
+ })
736
+ ] });
737
+ }
738
+ export {
739
+ BuilderPageRuntime,
740
+ appendBuilderV2PageFields,
741
+ buildBuilderV2PageTree,
742
+ compileBuilderV2Output,
743
+ createBuilderV2PageFields,
744
+ createBuilderV2PageService,
745
+ createEmptyBuilderV2ProjectData,
746
+ hasBlockingBuilderV2Issues,
747
+ normalizeBuilderV2ProjectData,
748
+ parseBuilderV2DynamicComponents,
749
+ sanitizeBuilderCss,
750
+ sanitizeBuilderHtml,
751
+ scopeBuilderCss,
752
+ splitBuilderV2HtmlIntoChunks,
753
+ toBuilderV2EditorInitialData,
754
+ validateBuilderV2Output
755
+ };