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

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