@orion-studios/payload-studio 0.6.0-beta.7 → 0.6.0-beta.71

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 (48) hide show
  1. package/dist/admin/client.js +2076 -618
  2. package/dist/admin/client.mjs +2037 -590
  3. package/dist/admin/index.d.mts +2 -2
  4. package/dist/admin/index.d.ts +2 -2
  5. package/dist/admin/index.js +140 -17
  6. package/dist/admin/index.mjs +2 -2
  7. package/dist/admin-app/client.js +11 -4
  8. package/dist/admin-app/client.mjs +1 -1
  9. package/dist/admin-app/index.d.mts +2 -2
  10. package/dist/admin-app/index.d.ts +2 -2
  11. package/dist/admin-app/styles.css +343 -41
  12. package/dist/admin.css +18 -2
  13. package/dist/builder-v2/client.d.mts +18 -0
  14. package/dist/builder-v2/client.d.ts +18 -0
  15. package/dist/builder-v2/client.js +1673 -0
  16. package/dist/builder-v2/client.mjs +1548 -0
  17. package/dist/builder-v2/index.d.mts +241 -0
  18. package/dist/builder-v2/index.d.ts +241 -0
  19. package/dist/builder-v2/index.js +760 -0
  20. package/dist/builder-v2/index.mjs +710 -0
  21. package/dist/builder-v2/styles.css +1524 -0
  22. package/dist/{chunk-XKUTZ7IU.mjs → chunk-276KAPGM.mjs} +56 -5
  23. package/dist/{chunk-KPIX7OSV.mjs → chunk-2XH7X34N.mjs} +11 -4
  24. package/dist/{chunk-PF3EBZXF.mjs → chunk-7ZMXZRBP.mjs} +39 -3
  25. package/dist/{chunk-5FNTVRCR.mjs → chunk-KHK6RTGC.mjs} +143 -20
  26. package/dist/{chunk-OTHERBGX.mjs → chunk-ZADL33R6.mjs} +1 -1
  27. package/dist/{index-QPDAedIX.d.ts → index-BV0vEGl6.d.ts} +4 -2
  28. package/dist/{index-Cv-6qnrw.d.mts → index-D5zrOdyv.d.mts} +3 -1
  29. package/dist/{index-52HdVLQq.d.ts → index-DAdN56fM.d.ts} +1 -1
  30. package/dist/{index-DyMmaRfI.d.mts → index-DLfPOqYA.d.mts} +4 -2
  31. package/dist/{index-Crx_MtPw.d.ts → index-Dv-Alx4h.d.ts} +3 -1
  32. package/dist/{index-DEQC3Dwj.d.mts → index-G_uTNffQ.d.mts} +1 -1
  33. package/dist/index.d.mts +4 -4
  34. package/dist/index.d.ts +4 -4
  35. package/dist/index.js +231 -21
  36. package/dist/index.mjs +10 -10
  37. package/dist/nextjs/index.js +39 -3
  38. package/dist/nextjs/index.mjs +2 -2
  39. package/dist/{sitePreviewTypes-BkHCWxNW.d.mts → sitePreviewTypes-BrJwGzJj.d.mts} +1 -1
  40. package/dist/{sitePreviewTypes-BkHCWxNW.d.ts → sitePreviewTypes-BrJwGzJj.d.ts} +1 -1
  41. package/dist/studio-pages/builder.css +24 -5
  42. package/dist/studio-pages/client.js +574 -64
  43. package/dist/studio-pages/client.mjs +574 -64
  44. package/dist/studio-pages/index.d.mts +1 -1
  45. package/dist/studio-pages/index.d.ts +1 -1
  46. package/dist/studio-pages/index.js +91 -4
  47. package/dist/studio-pages/index.mjs +3 -3
  48. package/package.json +22 -3
@@ -0,0 +1,710 @@
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>[^>]*)>(?<content>.*?)<\/\k<tag>>/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
+ return id || className ? { className, id } : void 0;
185
+ };
186
+ var parseBuilderV2DynamicComponents = (html) => {
187
+ const instances = [];
188
+ let match;
189
+ while ((match = placeholderPattern.exec(html)) !== null) {
190
+ const attrs = `${match.groups?.attrs ?? ""} ${match.groups?.rest ?? ""}`;
191
+ const component = match.groups?.component ?? "";
192
+ if (!component) {
193
+ continue;
194
+ }
195
+ instances.push({
196
+ component,
197
+ id: extractAttribute(attrs, "data-orion-id") || `component-${instances.length + 1}`,
198
+ props: parseAttributes(attrs),
199
+ wrapperAttributes: extractWrapperAttributes(attrs)
200
+ });
201
+ }
202
+ return instances;
203
+ };
204
+ var splitBuilderV2HtmlIntoChunks = (html) => {
205
+ const chunks = [];
206
+ let lastIndex = 0;
207
+ let componentIndex = 0;
208
+ let match;
209
+ while ((match = placeholderPattern.exec(html)) !== null) {
210
+ const before = html.slice(lastIndex, match.index);
211
+ if (before.length > 0) {
212
+ chunks.push({ html: before, kind: "html" });
213
+ }
214
+ const attrs = `${match.groups?.attrs ?? ""} ${match.groups?.rest ?? ""}`;
215
+ const component = match.groups?.component ?? "";
216
+ chunks.push({
217
+ instance: {
218
+ component,
219
+ id: extractAttribute(attrs, "data-orion-id") || `component-${componentIndex + 1}`,
220
+ props: parseAttributes(attrs),
221
+ wrapperAttributes: extractWrapperAttributes(attrs)
222
+ },
223
+ kind: "component"
224
+ });
225
+ componentIndex += 1;
226
+ lastIndex = match.index + match[0].length;
227
+ }
228
+ const after = html.slice(lastIndex);
229
+ if (after.length > 0) {
230
+ chunks.push({ html: after, kind: "html" });
231
+ }
232
+ return chunks;
233
+ };
234
+
235
+ // src/builder-v2/sanitize.ts
236
+ import sanitizeHtml from "sanitize-html";
237
+ var allowedTags = sanitizeHtml.defaults.allowedTags.concat([
238
+ "article",
239
+ "aside",
240
+ "button",
241
+ "figure",
242
+ "figcaption",
243
+ "footer",
244
+ "header",
245
+ "main",
246
+ "nav",
247
+ "section",
248
+ "source",
249
+ "video"
250
+ ]);
251
+ var allowedAttributes = {
252
+ ...sanitizeHtml.defaults.allowedAttributes,
253
+ "*": [
254
+ "aria-*",
255
+ "class",
256
+ "data-*",
257
+ "id",
258
+ "role",
259
+ "style",
260
+ "title"
261
+ ],
262
+ a: ["aria-*", "class", "data-*", "href", "id", "name", "rel", "style", "target", "title"],
263
+ button: ["aria-*", "class", "data-*", "disabled", "id", "style", "title", "type"],
264
+ iframe: ["allow", "allowfullscreen", "class", "data-*", "height", "loading", "src", "style", "title", "width"],
265
+ img: ["alt", "class", "data-*", "height", "id", "loading", "sizes", "src", "srcset", "style", "title", "width"],
266
+ source: ["media", "src", "srcset", "type"],
267
+ video: ["autoplay", "class", "controls", "height", "loop", "muted", "playsinline", "poster", "preload", "src", "style", "width"]
268
+ };
269
+ var allowedIframeHosts = [
270
+ "calendar.google.com",
271
+ "calendly.com",
272
+ "player.vimeo.com",
273
+ "www.google.com",
274
+ "www.youtube.com",
275
+ "youtube.com"
276
+ ];
277
+ var sanitizeBuilderHtml = (value) => {
278
+ if (typeof value !== "string" || value.trim().length === 0) {
279
+ return "";
280
+ }
281
+ return sanitizeHtml(value, {
282
+ allowedAttributes,
283
+ allowedIframeHostnames: allowedIframeHosts,
284
+ allowedSchemes: ["http", "https", "mailto", "tel"],
285
+ allowedSchemesByTag: {
286
+ img: ["http", "https", "data"]
287
+ },
288
+ allowedTags,
289
+ allowProtocolRelative: false,
290
+ parseStyleAttributes: false
291
+ });
292
+ };
293
+ var sanitizeBuilderCss = (value) => {
294
+ if (typeof value !== "string" || value.trim().length === 0) {
295
+ return "";
296
+ }
297
+ return value.replace(/@import\s+[^;]+;/gi, "").replace(/expression\s*\(/gi, "").replace(/javascript\s*:/gi, "");
298
+ };
299
+ var scopeSelector = (selector, scope) => selector.split(",").map((part) => {
300
+ const trimmed = part.trim();
301
+ if (!trimmed || trimmed.startsWith(scope) || trimmed.startsWith("@")) {
302
+ return trimmed;
303
+ }
304
+ if (/^(html|body|:root)\b/i.test(trimmed)) {
305
+ return trimmed.replace(/^(html|body|:root)\b/i, scope);
306
+ }
307
+ return `${scope} ${trimmed}`;
308
+ }).filter(Boolean).join(", ");
309
+ var scopeBuilderCss = (value, scope = ".orion-builder-v2-runtime") => {
310
+ const css = sanitizeBuilderCss(value);
311
+ if (!css) {
312
+ return "";
313
+ }
314
+ let output = "";
315
+ let cursor = 0;
316
+ const rulePattern = /([^{}]+)\{/g;
317
+ let match;
318
+ while ((match = rulePattern.exec(css)) !== null) {
319
+ const selectorStart = match.index;
320
+ const selector = match[1];
321
+ output += css.slice(cursor, selectorStart);
322
+ const trimmedSelector = selector.trim();
323
+ if (trimmedSelector.startsWith("@keyframes") || trimmedSelector.startsWith("@font-face") || trimmedSelector.startsWith("@page")) {
324
+ output += `${selector}{`;
325
+ } else if (trimmedSelector.startsWith("@media") || trimmedSelector.startsWith("@supports")) {
326
+ output += `${selector}{`;
327
+ } else {
328
+ output += `${scopeSelector(selector, scope)} {`;
329
+ }
330
+ cursor = rulePattern.lastIndex;
331
+ }
332
+ output += css.slice(cursor);
333
+ return output;
334
+ };
335
+
336
+ // src/builder-v2/validation.ts
337
+ var hasMatch = (value, pattern) => pattern.test(value);
338
+ var validateBuilderV2Output = (input) => {
339
+ const html = typeof input.html === "string" ? input.html : "";
340
+ const css = typeof input.css === "string" ? input.css : "";
341
+ const issues = [];
342
+ if (!html.trim()) {
343
+ issues.push({
344
+ code: "empty-page",
345
+ message: "This page has no rendered content.",
346
+ path: "compiledHtml",
347
+ severity: "error"
348
+ });
349
+ }
350
+ if (!hasMatch(html, /<h1\b/i)) {
351
+ issues.push({
352
+ code: "missing-h1",
353
+ message: "Add one H1 so the published page has a clear primary heading.",
354
+ path: "compiledHtml",
355
+ severity: "warning"
356
+ });
357
+ }
358
+ if (hasMatch(html, /\son[a-z]+\s*=/i)) {
359
+ issues.push({
360
+ code: "inline-event-handler",
361
+ message: "Inline event handlers are not allowed in published builder HTML.",
362
+ path: "compiledHtml",
363
+ severity: "error"
364
+ });
365
+ }
366
+ if (hasMatch(html, /<(script|object|embed)\b/i)) {
367
+ issues.push({
368
+ code: "unsafe-element",
369
+ message: "Script, object, and embed tags are not allowed in builder content.",
370
+ path: "compiledHtml",
371
+ severity: "error"
372
+ });
373
+ }
374
+ if (hasMatch(html, /\b(?:href|src)=["']\s*javascript:/i)) {
375
+ issues.push({
376
+ code: "unsafe-url",
377
+ message: "Links and media cannot use javascript URLs.",
378
+ path: "compiledHtml",
379
+ severity: "error"
380
+ });
381
+ }
382
+ if (hasMatch(css, /@import\s/i)) {
383
+ issues.push({
384
+ code: "css-import",
385
+ message: "CSS imports are removed at publish time. Use the site font and theme managers instead.",
386
+ path: "compiledCss",
387
+ severity: "warning"
388
+ });
389
+ }
390
+ if (hasMatch(css, /position\s*:\s*fixed/i)) {
391
+ issues.push({
392
+ code: "fixed-position",
393
+ message: "Fixed positioning can cover site navigation or dialogs. Review this before publishing.",
394
+ path: "compiledCss",
395
+ severity: "warning"
396
+ });
397
+ }
398
+ return issues;
399
+ };
400
+ var hasBlockingBuilderV2Issues = (issues) => issues.some((issue) => issue.severity === "error");
401
+
402
+ // src/builder-v2/payload/compile.ts
403
+ var compileBuilderV2Output = (input) => {
404
+ const html = sanitizeBuilderHtml(input.html);
405
+ const css = scopeBuilderCss(input.css);
406
+ const validationIssues = validateBuilderV2Output({ css: input.css, html: input.html });
407
+ return {
408
+ css,
409
+ dynamicComponents: parseBuilderV2DynamicComponents(html),
410
+ html,
411
+ validationIssues
412
+ };
413
+ };
414
+
415
+ // src/builder-v2/projectData.ts
416
+ var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
417
+ var createEmptyBuilderV2ProjectData = (title = "Untitled Page") => ({
418
+ assets: [],
419
+ pages: [
420
+ {
421
+ component: {
422
+ components: [
423
+ {
424
+ attributes: {
425
+ class: "orion-builder-v2-section"
426
+ },
427
+ components: [
428
+ {
429
+ content: title,
430
+ tagName: "h1",
431
+ type: "text"
432
+ },
433
+ {
434
+ content: "Start building this page by dragging blocks from the panel.",
435
+ tagName: "p",
436
+ type: "text"
437
+ }
438
+ ],
439
+ tagName: "section"
440
+ }
441
+ ],
442
+ type: "wrapper"
443
+ },
444
+ id: "page",
445
+ name: title
446
+ }
447
+ ],
448
+ styles: []
449
+ });
450
+ var normalizeBuilderV2ProjectData = (value, fallbackTitle = "Untitled Page") => {
451
+ if (!isRecord(value)) {
452
+ return createEmptyBuilderV2ProjectData(fallbackTitle);
453
+ }
454
+ return value;
455
+ };
456
+
457
+ // src/builder-v2/payload/pageService.ts
458
+ var pageTitle = (page) => typeof page.title === "string" && page.title.trim().length > 0 ? page.title : "Untitled Page";
459
+ var normalizeVersions = (value) => Array.isArray(value) ? value.filter((item) => Boolean(item && typeof item === "object")) : [];
460
+ var createVersionSnapshot = ({
461
+ compiled,
462
+ label,
463
+ projectData,
464
+ published = false
465
+ }) => {
466
+ const createdAt = (/* @__PURE__ */ new Date()).toISOString();
467
+ return {
468
+ compiledCss: compiled.css,
469
+ compiledHtml: compiled.html,
470
+ createdAt,
471
+ id: `builder-v2-${createdAt.replace(/[^0-9]/g, "")}`,
472
+ label,
473
+ projectData,
474
+ published
475
+ };
476
+ };
477
+ var appendVersionSnapshot = (current, snapshot) => [snapshot, ...normalizeVersions(current)].slice(0, 50);
478
+ var toBuilderV2EditorInitialData = (page) => ({
479
+ projectData: normalizeBuilderV2ProjectData(
480
+ page.builderProjectData || page.builderPublishedProjectData,
481
+ pageTitle(page)
482
+ ),
483
+ title: pageTitle(page)
484
+ });
485
+ var createBuilderV2PageService = ({
486
+ collectionSlug = "pages",
487
+ payload,
488
+ user
489
+ }) => ({
490
+ getPageForBuilder: async (pageID) => {
491
+ const page = await payload.findByID({
492
+ collection: collectionSlug,
493
+ depth: 2,
494
+ draft: true,
495
+ id: pageID,
496
+ overrideAccess: false,
497
+ user
498
+ });
499
+ return {
500
+ id: String(page.id),
501
+ initialData: toBuilderV2EditorInitialData(page),
502
+ page
503
+ };
504
+ },
505
+ saveDraft: async (pageID, input) => {
506
+ const compiled = compileBuilderV2Output(input.compiled);
507
+ const existing = await payload.findByID({
508
+ collection: collectionSlug,
509
+ depth: 0,
510
+ draft: true,
511
+ id: pageID,
512
+ overrideAccess: false,
513
+ user
514
+ });
515
+ const validationIssues = input.validationIssues || compiled.validationIssues || [];
516
+ await payload.update({
517
+ collection: collectionSlug,
518
+ data: {
519
+ _status: "draft",
520
+ builderAutosaveProjectData: null,
521
+ builderDynamicComponents: compiled.dynamicComponents,
522
+ builderLastSavedAt: (/* @__PURE__ */ new Date()).toISOString(),
523
+ builderMode: "grapes-v2",
524
+ builderProjectData: input.projectData,
525
+ builderValidationIssues: validationIssues,
526
+ builderVersions: appendVersionSnapshot(
527
+ existing.builderVersions,
528
+ createVersionSnapshot({
529
+ compiled,
530
+ label: "Draft saved",
531
+ projectData: input.projectData
532
+ })
533
+ ),
534
+ compiledCss: compiled.css,
535
+ compiledHtml: compiled.html,
536
+ ...input.title ? { title: input.title } : {}
537
+ },
538
+ id: pageID,
539
+ overrideAccess: false,
540
+ user
541
+ });
542
+ return {
543
+ compiled,
544
+ id: pageID,
545
+ status: "draft"
546
+ };
547
+ },
548
+ publish: async (pageID, input) => {
549
+ const compiled = compileBuilderV2Output(input.compiled);
550
+ const existing = await payload.findByID({
551
+ collection: collectionSlug,
552
+ depth: 0,
553
+ draft: true,
554
+ id: pageID,
555
+ overrideAccess: false,
556
+ user
557
+ });
558
+ const validationIssues = input.validationIssues || compiled.validationIssues || [];
559
+ const snapshot = createVersionSnapshot({
560
+ compiled,
561
+ label: "Published",
562
+ projectData: input.projectData,
563
+ published: true
564
+ });
565
+ await payload.update({
566
+ collection: collectionSlug,
567
+ data: {
568
+ _status: "published",
569
+ builderAutosaveProjectData: null,
570
+ builderDynamicComponents: compiled.dynamicComponents,
571
+ builderLastPublishedAt: snapshot.createdAt,
572
+ builderLastSavedAt: snapshot.createdAt,
573
+ builderMode: "grapes-v2",
574
+ builderProjectData: input.projectData,
575
+ builderPublishedProjectData: input.projectData,
576
+ builderPublishedSnapshot: snapshot,
577
+ builderValidationIssues: validationIssues,
578
+ builderVersions: appendVersionSnapshot(existing.builderVersions, snapshot),
579
+ compiledCss: compiled.css,
580
+ compiledHtml: compiled.html,
581
+ ...input.title ? { title: input.title } : {}
582
+ },
583
+ id: pageID,
584
+ overrideAccess: false,
585
+ user
586
+ });
587
+ return {
588
+ compiled,
589
+ id: pageID,
590
+ status: "published"
591
+ };
592
+ }
593
+ });
594
+
595
+ // src/builder-v2/pageTree.ts
596
+ var relationId = (value) => {
597
+ if (typeof value === "number" || typeof value === "string") {
598
+ return value;
599
+ }
600
+ if (value && typeof value === "object") {
601
+ const id = value.id;
602
+ return typeof id === "number" || typeof id === "string" ? id : null;
603
+ }
604
+ return null;
605
+ };
606
+ var buildBuilderV2PageTree = (pages) => {
607
+ const nodes = /* @__PURE__ */ new Map();
608
+ const roots = [];
609
+ pages.forEach((page) => {
610
+ nodes.set(page.id, {
611
+ children: [],
612
+ id: page.id,
613
+ parentId: page.parentId ?? relationId(page.parent),
614
+ path: page.path || (page.slug ? `/${page.slug}` : "/"),
615
+ slug: page.slug || "",
616
+ status: page._status,
617
+ title: page.title || "Untitled page"
618
+ });
619
+ });
620
+ nodes.forEach((node) => {
621
+ if (node.parentId && nodes.has(node.parentId)) {
622
+ nodes.get(node.parentId)?.children?.push(node);
623
+ } else {
624
+ roots.push(node);
625
+ }
626
+ });
627
+ const sortNodes = (items) => {
628
+ items.sort((a, b) => a.path.localeCompare(b.path));
629
+ items.forEach((item) => sortNodes(item.children || []));
630
+ };
631
+ sortNodes(roots);
632
+ return roots;
633
+ };
634
+
635
+ // src/builder-v2/runtime/BuilderPageRuntime.tsx
636
+ import { createElement, Fragment } from "react";
637
+ import { jsx, jsxs } from "react/jsx-runtime";
638
+ var resolveRuntimeComponent = (adapter, type) => {
639
+ const definition = adapter?.components?.[type];
640
+ if (!definition) {
641
+ return null;
642
+ }
643
+ if (typeof definition === "function") {
644
+ return definition;
645
+ }
646
+ return definition.render;
647
+ };
648
+ function BuilderPageRuntime({ adapter, className, page }) {
649
+ const html = sanitizeBuilderHtml(page.compiledHtml);
650
+ const css = scopeBuilderCss(page.compiledCss);
651
+ const chunks = splitBuilderV2HtmlIntoChunks(html);
652
+ return /* @__PURE__ */ jsxs("div", { className: ["orion-builder-v2-runtime", className].filter(Boolean).join(" "), children: [
653
+ css ? /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: css } }) : null,
654
+ chunks.map((chunk, index) => {
655
+ if (chunk.kind === "html") {
656
+ return /* @__PURE__ */ jsx(
657
+ "div",
658
+ {
659
+ className: "orion-builder-v2-html-chunk",
660
+ dangerouslySetInnerHTML: { __html: chunk.html }
661
+ },
662
+ `html-${index}`
663
+ );
664
+ }
665
+ const Component = resolveRuntimeComponent(adapter, chunk.instance.component);
666
+ if (!Component) {
667
+ return /* @__PURE__ */ jsx(
668
+ "div",
669
+ {
670
+ className: "orion-builder-v2-missing-component",
671
+ "data-orion-missing-component": chunk.instance.component
672
+ },
673
+ `component-${chunk.instance.id}-${index}`
674
+ );
675
+ }
676
+ const renderedComponent = /* @__PURE__ */ jsx(Component, { instance: chunk.instance, page });
677
+ const wrapperAttributes = chunk.instance.wrapperAttributes;
678
+ if (wrapperAttributes?.id || wrapperAttributes?.className) {
679
+ return createElement(
680
+ "div",
681
+ {
682
+ className: wrapperAttributes.className,
683
+ id: wrapperAttributes.id,
684
+ key: `component-${chunk.instance.id}-${index}`
685
+ },
686
+ renderedComponent
687
+ );
688
+ }
689
+ return createElement(Fragment, { key: `component-${chunk.instance.id}-${index}` }, renderedComponent);
690
+ })
691
+ ] });
692
+ }
693
+ export {
694
+ BuilderPageRuntime,
695
+ appendBuilderV2PageFields,
696
+ buildBuilderV2PageTree,
697
+ compileBuilderV2Output,
698
+ createBuilderV2PageFields,
699
+ createBuilderV2PageService,
700
+ createEmptyBuilderV2ProjectData,
701
+ hasBlockingBuilderV2Issues,
702
+ normalizeBuilderV2ProjectData,
703
+ parseBuilderV2DynamicComponents,
704
+ sanitizeBuilderCss,
705
+ sanitizeBuilderHtml,
706
+ scopeBuilderCss,
707
+ splitBuilderV2HtmlIntoChunks,
708
+ toBuilderV2EditorInitialData,
709
+ validateBuilderV2Output
710
+ };