@orion-studios/payload-studio 0.6.0-beta.5 → 0.6.0-beta.50
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/admin/client.d.mts +1 -0
- package/dist/admin/client.d.ts +1 -0
- package/dist/admin/client.js +3923 -1354
- package/dist/admin/client.mjs +4089 -1532
- package/dist/admin/index.d.mts +2 -3
- package/dist/admin/index.d.ts +2 -3
- package/dist/admin/index.js +141 -1522
- package/dist/admin/index.mjs +2 -4
- package/dist/admin-app/client.js +11 -4
- package/dist/admin-app/client.mjs +1 -1
- package/dist/admin-app/index.d.mts +2 -2
- package/dist/admin-app/index.d.ts +2 -2
- package/dist/admin-app/index.mjs +4 -4
- package/dist/admin-app/styles.css +343 -41
- package/dist/admin.css +18 -2
- package/dist/builder-v2/client.d.mts +18 -0
- package/dist/builder-v2/client.d.ts +18 -0
- package/dist/builder-v2/client.js +1158 -0
- package/dist/builder-v2/client.mjs +1033 -0
- package/dist/builder-v2/index.d.mts +236 -0
- package/dist/builder-v2/index.d.ts +236 -0
- package/dist/builder-v2/index.js +735 -0
- package/dist/builder-v2/index.mjs +685 -0
- package/dist/builder-v2/styles.css +1005 -0
- package/dist/{chunk-KPIX7OSV.mjs → chunk-2XH7X34N.mjs} +11 -4
- package/dist/{chunk-PF3EBZXF.mjs → chunk-7ZMXZRBP.mjs} +39 -3
- package/dist/chunk-JC3UV74N.mjs +1033 -0
- package/dist/{chunk-XKUTZ7IU.mjs → chunk-NGLIA2OE.mjs} +53 -2
- package/dist/{chunk-EHUE4LCT.mjs → chunk-RKTIFEUY.mjs} +33 -3
- package/dist/chunk-W2UOCJDX.mjs +32 -0
- package/dist/{chunk-OTHERBGX.mjs → chunk-ZADL33R6.mjs} +1 -1
- package/dist/{index-bbA3HSxa.d.ts → index-BV0vEGl6.d.ts} +6 -9
- package/dist/{index-Cv-6qnrw.d.mts → index-D5zrOdyv.d.mts} +3 -1
- package/dist/{index-52HdVLQq.d.ts → index-DAdN56fM.d.ts} +1 -1
- package/dist/{index-DEkV-sMs.d.mts → index-DLfPOqYA.d.mts} +6 -9
- package/dist/{index-Crx_MtPw.d.ts → index-Dv-Alx4h.d.ts} +3 -1
- package/dist/{index-DEQC3Dwj.d.mts → index-G_uTNffQ.d.mts} +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +294 -1542
- package/dist/index.mjs +6 -6
- package/dist/nextjs/index.js +39 -3
- package/dist/nextjs/index.mjs +2 -2
- package/dist/{sitePreviewTypes-BkHCWxNW.d.mts → sitePreviewTypes-BrJwGzJj.d.mts} +1 -1
- package/dist/{sitePreviewTypes-BkHCWxNW.d.ts → sitePreviewTypes-BrJwGzJj.d.ts} +1 -1
- package/dist/studio-pages/builder.css +24 -5
- package/dist/studio-pages/client.js +574 -64
- package/dist/studio-pages/client.mjs +574 -64
- package/dist/studio-pages/index.d.mts +1 -1
- package/dist/studio-pages/index.d.ts +1 -1
- package/dist/studio-pages/index.js +91 -4
- package/dist/studio-pages/index.mjs +2 -2
- package/package.json +22 -3
- package/dist/chunk-PKVTM6DY.mjs +0 -2372
- package/dist/chunk-Z6L5K5MH.mjs +0 -64
|
@@ -0,0 +1,1158 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
"use client";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// src/builder-v2/client.ts
|
|
33
|
+
var client_exports = {};
|
|
34
|
+
__export(client_exports, {
|
|
35
|
+
GrapesPageEditor: () => GrapesPageEditor
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(client_exports);
|
|
38
|
+
|
|
39
|
+
// src/builder-v2/editor/GrapesPageEditor.tsx
|
|
40
|
+
var import_react = require("react");
|
|
41
|
+
|
|
42
|
+
// src/shared/clientImageUploadOptimization.ts
|
|
43
|
+
var MAX_DIRECT_UPLOAD_BYTES = 4e6;
|
|
44
|
+
var extensionForMimeType = (mimeType) => {
|
|
45
|
+
switch (mimeType) {
|
|
46
|
+
case "image/webp":
|
|
47
|
+
return ".webp";
|
|
48
|
+
case "image/png":
|
|
49
|
+
return ".png";
|
|
50
|
+
default:
|
|
51
|
+
return ".jpg";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var detectCanvasTransparency = (context, width, height) => {
|
|
55
|
+
try {
|
|
56
|
+
const { data } = context.getImageData(0, 0, width, height);
|
|
57
|
+
for (let index = 3; index < data.length; index += 4) {
|
|
58
|
+
if (data[index] < 255) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
var resolveOutputMimeTypes = (sourceMime, hasTransparency) => {
|
|
67
|
+
const candidates = [];
|
|
68
|
+
if (hasTransparency) {
|
|
69
|
+
candidates.push("image/webp", "image/png");
|
|
70
|
+
} else if (sourceMime === "image/webp") {
|
|
71
|
+
candidates.push("image/webp", "image/jpeg");
|
|
72
|
+
} else if (sourceMime === "image/png") {
|
|
73
|
+
candidates.push("image/webp", "image/jpeg", "image/png");
|
|
74
|
+
} else {
|
|
75
|
+
candidates.push("image/jpeg", "image/webp");
|
|
76
|
+
}
|
|
77
|
+
return [...new Set(candidates)];
|
|
78
|
+
};
|
|
79
|
+
async function optimizeImageForUpload(file) {
|
|
80
|
+
if (!file.type.startsWith("image/")) {
|
|
81
|
+
return file;
|
|
82
|
+
}
|
|
83
|
+
const objectURL = URL.createObjectURL(file);
|
|
84
|
+
try {
|
|
85
|
+
const image = await new Promise((resolve, reject) => {
|
|
86
|
+
const nextImage = new Image();
|
|
87
|
+
nextImage.onload = () => resolve(nextImage);
|
|
88
|
+
nextImage.onerror = () => reject(new Error("Could not read image for upload optimization."));
|
|
89
|
+
nextImage.src = objectURL;
|
|
90
|
+
});
|
|
91
|
+
const canvas = document.createElement("canvas");
|
|
92
|
+
canvas.width = Math.max(1, image.width);
|
|
93
|
+
canvas.height = Math.max(1, image.height);
|
|
94
|
+
const context = canvas.getContext("2d");
|
|
95
|
+
if (!context) {
|
|
96
|
+
return file;
|
|
97
|
+
}
|
|
98
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
99
|
+
const sourceMime = file.type.toLowerCase();
|
|
100
|
+
const hasTransparency = detectCanvasTransparency(context, canvas.width, canvas.height);
|
|
101
|
+
const outputMimes = resolveOutputMimeTypes(sourceMime, hasTransparency);
|
|
102
|
+
const qualityPasses = [0.82, 0.74, 0.66, 0.58, 0.5, 0.42, 0.36, 0.3, 0.26];
|
|
103
|
+
let bestFile = null;
|
|
104
|
+
for (const outputMime of outputMimes) {
|
|
105
|
+
const passes = outputMime === "image/png" ? [void 0] : qualityPasses;
|
|
106
|
+
for (const quality of passes) {
|
|
107
|
+
const blob = await new Promise((resolve) => {
|
|
108
|
+
canvas.toBlob((value) => resolve(value), outputMime, quality);
|
|
109
|
+
});
|
|
110
|
+
if (!blob) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const optimizedName = file.name.replace(/\.[^/.]+$/, extensionForMimeType(outputMime));
|
|
114
|
+
const optimized = new File([blob], optimizedName, {
|
|
115
|
+
lastModified: Date.now(),
|
|
116
|
+
type: outputMime
|
|
117
|
+
});
|
|
118
|
+
if (!bestFile || optimized.size < bestFile.size) {
|
|
119
|
+
bestFile = optimized;
|
|
120
|
+
}
|
|
121
|
+
if (optimized.size <= MAX_DIRECT_UPLOAD_BYTES) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!bestFile) {
|
|
127
|
+
return file;
|
|
128
|
+
}
|
|
129
|
+
return bestFile.size < file.size ? bestFile : file;
|
|
130
|
+
} finally {
|
|
131
|
+
URL.revokeObjectURL(objectURL);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/builder-v2/projectData.ts
|
|
136
|
+
var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
137
|
+
var createEmptyBuilderV2ProjectData = (title = "Untitled Page") => ({
|
|
138
|
+
assets: [],
|
|
139
|
+
pages: [
|
|
140
|
+
{
|
|
141
|
+
component: {
|
|
142
|
+
components: [
|
|
143
|
+
{
|
|
144
|
+
attributes: {
|
|
145
|
+
class: "orion-builder-v2-section"
|
|
146
|
+
},
|
|
147
|
+
components: [
|
|
148
|
+
{
|
|
149
|
+
content: title,
|
|
150
|
+
tagName: "h1",
|
|
151
|
+
type: "text"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
content: "Start building this page by dragging blocks from the panel.",
|
|
155
|
+
tagName: "p",
|
|
156
|
+
type: "text"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
tagName: "section"
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
type: "wrapper"
|
|
163
|
+
},
|
|
164
|
+
id: "page",
|
|
165
|
+
name: title
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
styles: []
|
|
169
|
+
});
|
|
170
|
+
var normalizeBuilderV2ProjectData = (value, fallbackTitle = "Untitled Page") => {
|
|
171
|
+
if (!isRecord(value)) {
|
|
172
|
+
return createEmptyBuilderV2ProjectData(fallbackTitle);
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/builder-v2/runtime/placeholders.ts
|
|
178
|
+
var placeholderPattern = /<(?<tag>[a-zA-Z][a-zA-Z0-9-]*)\b(?<attrs>[^>]*)data-orion-component=["'](?<component>[^"']+)["'](?<rest>[^>]*)>(?<content>.*?)<\/\k<tag>>/gis;
|
|
179
|
+
var attrPattern = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)=(?:"([^"]*)"|'([^']*)')/g;
|
|
180
|
+
var decodeHtmlAttribute = (value) => value.replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
181
|
+
var parseAttributes = (value) => {
|
|
182
|
+
const props = {};
|
|
183
|
+
let match;
|
|
184
|
+
while ((match = attrPattern.exec(value)) !== null) {
|
|
185
|
+
const name = match[1];
|
|
186
|
+
const rawValue = match[2] ?? match[3] ?? "";
|
|
187
|
+
if (!name.startsWith("data-")) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (name === "data-orion-component" || name === "data-orion-id") {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (name === "data-orion-props") {
|
|
194
|
+
const decoded = decodeHtmlAttribute(rawValue);
|
|
195
|
+
try {
|
|
196
|
+
const parsed = JSON.parse(decoded);
|
|
197
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
198
|
+
Object.assign(props, parsed);
|
|
199
|
+
}
|
|
200
|
+
} catch {
|
|
201
|
+
props.propsJson = decoded;
|
|
202
|
+
}
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const propName = name.replace(/^data-orion-/, "").replace(/^data-/, "").replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
206
|
+
props[propName] = decodeHtmlAttribute(rawValue);
|
|
207
|
+
}
|
|
208
|
+
return props;
|
|
209
|
+
};
|
|
210
|
+
var extractAttribute = (attrs, name) => {
|
|
211
|
+
const pattern = new RegExp(`${name}=["']([^"']+)["']`, "i");
|
|
212
|
+
const match = attrs.match(pattern);
|
|
213
|
+
return match ? decodeHtmlAttribute(match[1]) : null;
|
|
214
|
+
};
|
|
215
|
+
var parseBuilderV2DynamicComponents = (html) => {
|
|
216
|
+
const instances = [];
|
|
217
|
+
let match;
|
|
218
|
+
while ((match = placeholderPattern.exec(html)) !== null) {
|
|
219
|
+
const attrs = `${match.groups?.attrs ?? ""} ${match.groups?.rest ?? ""}`;
|
|
220
|
+
const component = match.groups?.component ?? "";
|
|
221
|
+
if (!component) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
instances.push({
|
|
225
|
+
component,
|
|
226
|
+
id: extractAttribute(attrs, "data-orion-id") || `component-${instances.length + 1}`,
|
|
227
|
+
props: parseAttributes(attrs)
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return instances;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/builder-v2/sanitize.ts
|
|
234
|
+
var import_sanitize_html = __toESM(require("sanitize-html"));
|
|
235
|
+
var allowedTags = import_sanitize_html.default.defaults.allowedTags.concat([
|
|
236
|
+
"article",
|
|
237
|
+
"aside",
|
|
238
|
+
"button",
|
|
239
|
+
"figure",
|
|
240
|
+
"figcaption",
|
|
241
|
+
"footer",
|
|
242
|
+
"header",
|
|
243
|
+
"main",
|
|
244
|
+
"nav",
|
|
245
|
+
"section",
|
|
246
|
+
"source",
|
|
247
|
+
"video"
|
|
248
|
+
]);
|
|
249
|
+
var allowedAttributes = {
|
|
250
|
+
...import_sanitize_html.default.defaults.allowedAttributes,
|
|
251
|
+
"*": [
|
|
252
|
+
"aria-*",
|
|
253
|
+
"class",
|
|
254
|
+
"data-*",
|
|
255
|
+
"id",
|
|
256
|
+
"role",
|
|
257
|
+
"style",
|
|
258
|
+
"title"
|
|
259
|
+
],
|
|
260
|
+
a: ["aria-*", "class", "data-*", "href", "id", "name", "rel", "style", "target", "title"],
|
|
261
|
+
button: ["aria-*", "class", "data-*", "disabled", "id", "style", "title", "type"],
|
|
262
|
+
iframe: ["allow", "allowfullscreen", "class", "data-*", "height", "loading", "src", "style", "title", "width"],
|
|
263
|
+
img: ["alt", "class", "data-*", "height", "id", "loading", "sizes", "src", "srcset", "style", "title", "width"],
|
|
264
|
+
source: ["media", "src", "srcset", "type"],
|
|
265
|
+
video: ["autoplay", "class", "controls", "height", "loop", "muted", "playsinline", "poster", "preload", "src", "style", "width"]
|
|
266
|
+
};
|
|
267
|
+
var allowedIframeHosts = [
|
|
268
|
+
"calendar.google.com",
|
|
269
|
+
"calendly.com",
|
|
270
|
+
"player.vimeo.com",
|
|
271
|
+
"www.google.com",
|
|
272
|
+
"www.youtube.com",
|
|
273
|
+
"youtube.com"
|
|
274
|
+
];
|
|
275
|
+
var sanitizeBuilderHtml = (value) => {
|
|
276
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
277
|
+
return "";
|
|
278
|
+
}
|
|
279
|
+
return (0, import_sanitize_html.default)(value, {
|
|
280
|
+
allowedAttributes,
|
|
281
|
+
allowedIframeHostnames: allowedIframeHosts,
|
|
282
|
+
allowedSchemes: ["http", "https", "mailto", "tel"],
|
|
283
|
+
allowedSchemesByTag: {
|
|
284
|
+
img: ["http", "https", "data"]
|
|
285
|
+
},
|
|
286
|
+
allowedTags,
|
|
287
|
+
allowProtocolRelative: false,
|
|
288
|
+
parseStyleAttributes: false
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
var sanitizeBuilderCss = (value) => {
|
|
292
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
293
|
+
return "";
|
|
294
|
+
}
|
|
295
|
+
return value.replace(/@import\s+[^;]+;/gi, "").replace(/expression\s*\(/gi, "").replace(/javascript\s*:/gi, "");
|
|
296
|
+
};
|
|
297
|
+
var scopeSelector = (selector, scope) => selector.split(",").map((part) => {
|
|
298
|
+
const trimmed = part.trim();
|
|
299
|
+
if (!trimmed || trimmed.startsWith(scope) || trimmed.startsWith("@")) {
|
|
300
|
+
return trimmed;
|
|
301
|
+
}
|
|
302
|
+
if (/^(html|body|:root)\b/i.test(trimmed)) {
|
|
303
|
+
return trimmed.replace(/^(html|body|:root)\b/i, scope);
|
|
304
|
+
}
|
|
305
|
+
return `${scope} ${trimmed}`;
|
|
306
|
+
}).filter(Boolean).join(", ");
|
|
307
|
+
var scopeBuilderCss = (value, scope = ".orion-builder-v2-runtime") => {
|
|
308
|
+
const css = sanitizeBuilderCss(value);
|
|
309
|
+
if (!css) {
|
|
310
|
+
return "";
|
|
311
|
+
}
|
|
312
|
+
let output = "";
|
|
313
|
+
let cursor = 0;
|
|
314
|
+
const rulePattern = /([^{}]+)\{/g;
|
|
315
|
+
let match;
|
|
316
|
+
while ((match = rulePattern.exec(css)) !== null) {
|
|
317
|
+
const selectorStart = match.index;
|
|
318
|
+
const selector = match[1];
|
|
319
|
+
output += css.slice(cursor, selectorStart);
|
|
320
|
+
const trimmedSelector = selector.trim();
|
|
321
|
+
if (trimmedSelector.startsWith("@keyframes") || trimmedSelector.startsWith("@font-face") || trimmedSelector.startsWith("@page")) {
|
|
322
|
+
output += `${selector}{`;
|
|
323
|
+
} else if (trimmedSelector.startsWith("@media") || trimmedSelector.startsWith("@supports")) {
|
|
324
|
+
output += `${selector}{`;
|
|
325
|
+
} else {
|
|
326
|
+
output += `${scopeSelector(selector, scope)} {`;
|
|
327
|
+
}
|
|
328
|
+
cursor = rulePattern.lastIndex;
|
|
329
|
+
}
|
|
330
|
+
output += css.slice(cursor);
|
|
331
|
+
return output;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// src/builder-v2/validation.ts
|
|
335
|
+
var hasMatch = (value, pattern) => pattern.test(value);
|
|
336
|
+
var validateBuilderV2Output = (input) => {
|
|
337
|
+
const html = typeof input.html === "string" ? input.html : "";
|
|
338
|
+
const css = typeof input.css === "string" ? input.css : "";
|
|
339
|
+
const issues = [];
|
|
340
|
+
if (!html.trim()) {
|
|
341
|
+
issues.push({
|
|
342
|
+
code: "empty-page",
|
|
343
|
+
message: "This page has no rendered content.",
|
|
344
|
+
path: "compiledHtml",
|
|
345
|
+
severity: "error"
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
if (!hasMatch(html, /<h1\b/i)) {
|
|
349
|
+
issues.push({
|
|
350
|
+
code: "missing-h1",
|
|
351
|
+
message: "Add one H1 so the published page has a clear primary heading.",
|
|
352
|
+
path: "compiledHtml",
|
|
353
|
+
severity: "warning"
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
if (hasMatch(html, /\son[a-z]+\s*=/i)) {
|
|
357
|
+
issues.push({
|
|
358
|
+
code: "inline-event-handler",
|
|
359
|
+
message: "Inline event handlers are not allowed in published builder HTML.",
|
|
360
|
+
path: "compiledHtml",
|
|
361
|
+
severity: "error"
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
if (hasMatch(html, /<(script|object|embed)\b/i)) {
|
|
365
|
+
issues.push({
|
|
366
|
+
code: "unsafe-element",
|
|
367
|
+
message: "Script, object, and embed tags are not allowed in builder content.",
|
|
368
|
+
path: "compiledHtml",
|
|
369
|
+
severity: "error"
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
if (hasMatch(html, /\b(?:href|src)=["']\s*javascript:/i)) {
|
|
373
|
+
issues.push({
|
|
374
|
+
code: "unsafe-url",
|
|
375
|
+
message: "Links and media cannot use javascript URLs.",
|
|
376
|
+
path: "compiledHtml",
|
|
377
|
+
severity: "error"
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (hasMatch(css, /@import\s/i)) {
|
|
381
|
+
issues.push({
|
|
382
|
+
code: "css-import",
|
|
383
|
+
message: "CSS imports are removed at publish time. Use the site font and theme managers instead.",
|
|
384
|
+
path: "compiledCss",
|
|
385
|
+
severity: "warning"
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
if (hasMatch(css, /position\s*:\s*fixed/i)) {
|
|
389
|
+
issues.push({
|
|
390
|
+
code: "fixed-position",
|
|
391
|
+
message: "Fixed positioning can cover site navigation or dialogs. Review this before publishing.",
|
|
392
|
+
path: "compiledCss",
|
|
393
|
+
severity: "warning"
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return issues;
|
|
397
|
+
};
|
|
398
|
+
var hasBlockingBuilderV2Issues = (issues) => issues.some((issue) => issue.severity === "error");
|
|
399
|
+
|
|
400
|
+
// src/builder-v2/editor/defaultBlocks.ts
|
|
401
|
+
var registerOrionBuilderV2Blocks = (editor) => {
|
|
402
|
+
const blocks = editor.Blocks;
|
|
403
|
+
blocks.add("orion-nav", {
|
|
404
|
+
category: "Chrome",
|
|
405
|
+
content: `
|
|
406
|
+
<header class="orion-builder-v2-nav">
|
|
407
|
+
<a class="orion-builder-v2-logo" href="/">Brand</a>
|
|
408
|
+
<nav aria-label="Primary">
|
|
409
|
+
<a href="/">Home</a>
|
|
410
|
+
<a href="/about">About</a>
|
|
411
|
+
<a href="/contact">Contact</a>
|
|
412
|
+
</nav>
|
|
413
|
+
<a class="orion-builder-v2-button" href="/contact">Start</a>
|
|
414
|
+
</header>
|
|
415
|
+
`,
|
|
416
|
+
label: "Nav"
|
|
417
|
+
});
|
|
418
|
+
blocks.add("orion-section", {
|
|
419
|
+
category: "Layout",
|
|
420
|
+
content: `
|
|
421
|
+
<section class="orion-builder-v2-section">
|
|
422
|
+
<div class="orion-builder-v2-container">
|
|
423
|
+
<h2>Section Heading</h2>
|
|
424
|
+
<p>Add supporting content here.</p>
|
|
425
|
+
</div>
|
|
426
|
+
</section>
|
|
427
|
+
`,
|
|
428
|
+
label: "Section"
|
|
429
|
+
});
|
|
430
|
+
blocks.add("orion-hero", {
|
|
431
|
+
category: "Sections",
|
|
432
|
+
content: `
|
|
433
|
+
<section class="orion-builder-v2-hero">
|
|
434
|
+
<div class="orion-builder-v2-container">
|
|
435
|
+
<p class="orion-builder-v2-kicker">Optional kicker</p>
|
|
436
|
+
<h1>Build a stronger website</h1>
|
|
437
|
+
<p>Use this area for a clear value proposition and call to action.</p>
|
|
438
|
+
<a class="orion-builder-v2-button" href="/contact">Get started</a>
|
|
439
|
+
</div>
|
|
440
|
+
</section>
|
|
441
|
+
`,
|
|
442
|
+
label: "Hero"
|
|
443
|
+
});
|
|
444
|
+
blocks.add("orion-columns", {
|
|
445
|
+
category: "Layout",
|
|
446
|
+
content: `
|
|
447
|
+
<section class="orion-builder-v2-section">
|
|
448
|
+
<div class="orion-builder-v2-container orion-builder-v2-grid is-3">
|
|
449
|
+
<article class="orion-builder-v2-card"><h3>Column One</h3><p>Add content.</p></article>
|
|
450
|
+
<article class="orion-builder-v2-card"><h3>Column Two</h3><p>Add content.</p></article>
|
|
451
|
+
<article class="orion-builder-v2-card"><h3>Column Three</h3><p>Add content.</p></article>
|
|
452
|
+
</div>
|
|
453
|
+
</section>
|
|
454
|
+
`,
|
|
455
|
+
label: "Columns"
|
|
456
|
+
});
|
|
457
|
+
blocks.add("orion-card-grid", {
|
|
458
|
+
category: "Sections",
|
|
459
|
+
content: `
|
|
460
|
+
<section class="orion-builder-v2-section">
|
|
461
|
+
<div class="orion-builder-v2-container">
|
|
462
|
+
<p class="orion-builder-v2-kicker">Featured</p>
|
|
463
|
+
<h2>Cards that explain the offer</h2>
|
|
464
|
+
<div class="orion-builder-v2-grid is-3">
|
|
465
|
+
<article class="orion-builder-v2-card"><h3>Service One</h3><p>Describe the outcome clients care about.</p><a href="/contact">Learn more</a></article>
|
|
466
|
+
<article class="orion-builder-v2-card"><h3>Service Two</h3><p>Keep the card concise and scannable.</p><a href="/contact">Learn more</a></article>
|
|
467
|
+
<article class="orion-builder-v2-card"><h3>Service Three</h3><p>Use the same structure for visual rhythm.</p><a href="/contact">Learn more</a></article>
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
</section>
|
|
471
|
+
`,
|
|
472
|
+
label: "Card grid"
|
|
473
|
+
});
|
|
474
|
+
blocks.add("orion-gallery", {
|
|
475
|
+
category: "Media",
|
|
476
|
+
content: `
|
|
477
|
+
<section class="orion-builder-v2-section">
|
|
478
|
+
<div class="orion-builder-v2-container">
|
|
479
|
+
<h2>Gallery</h2>
|
|
480
|
+
<div class="orion-builder-v2-gallery">
|
|
481
|
+
<img alt="Gallery item" src="https://placehold.co/900x700" />
|
|
482
|
+
<img alt="Gallery item" src="https://placehold.co/900x700" />
|
|
483
|
+
<img alt="Gallery item" src="https://placehold.co/900x700" />
|
|
484
|
+
<img alt="Gallery item" src="https://placehold.co/900x700" />
|
|
485
|
+
</div>
|
|
486
|
+
</div>
|
|
487
|
+
</section>
|
|
488
|
+
`,
|
|
489
|
+
label: "Gallery"
|
|
490
|
+
});
|
|
491
|
+
blocks.add("orion-testimonials", {
|
|
492
|
+
category: "Sections",
|
|
493
|
+
content: `
|
|
494
|
+
<section class="orion-builder-v2-section is-muted">
|
|
495
|
+
<div class="orion-builder-v2-container">
|
|
496
|
+
<p class="orion-builder-v2-kicker">Testimonials</p>
|
|
497
|
+
<h2>What clients say</h2>
|
|
498
|
+
<div class="orion-builder-v2-grid is-3">
|
|
499
|
+
<blockquote class="orion-builder-v2-card"><p>"A clear, warm experience from start to finish."</p><cite>Client Name</cite></blockquote>
|
|
500
|
+
<blockquote class="orion-builder-v2-card"><p>"Exactly what we needed, without friction."</p><cite>Client Name</cite></blockquote>
|
|
501
|
+
<blockquote class="orion-builder-v2-card"><p>"The site made every next step obvious."</p><cite>Client Name</cite></blockquote>
|
|
502
|
+
</div>
|
|
503
|
+
</div>
|
|
504
|
+
</section>
|
|
505
|
+
`,
|
|
506
|
+
label: "Testimonials"
|
|
507
|
+
});
|
|
508
|
+
blocks.add("orion-faq", {
|
|
509
|
+
category: "Sections",
|
|
510
|
+
content: `
|
|
511
|
+
<section class="orion-builder-v2-section">
|
|
512
|
+
<div class="orion-builder-v2-container is-narrow">
|
|
513
|
+
<p class="orion-builder-v2-kicker">FAQ</p>
|
|
514
|
+
<h2>Questions answered</h2>
|
|
515
|
+
<details open><summary>What should visitors know first?</summary><p>Give a short, useful answer that removes hesitation.</p></details>
|
|
516
|
+
<details><summary>How does the process work?</summary><p>Explain the next step clearly.</p></details>
|
|
517
|
+
<details><summary>How do we get started?</summary><p>Point people to the strongest call to action.</p></details>
|
|
518
|
+
</div>
|
|
519
|
+
</section>
|
|
520
|
+
`,
|
|
521
|
+
label: "FAQ"
|
|
522
|
+
});
|
|
523
|
+
blocks.add("orion-pricing", {
|
|
524
|
+
category: "Commerce",
|
|
525
|
+
content: `
|
|
526
|
+
<section class="orion-builder-v2-section">
|
|
527
|
+
<div class="orion-builder-v2-container">
|
|
528
|
+
<p class="orion-builder-v2-kicker">Pricing</p>
|
|
529
|
+
<h2>Simple package options</h2>
|
|
530
|
+
<div class="orion-builder-v2-grid is-3">
|
|
531
|
+
<article class="orion-builder-v2-card"><h3>Starter</h3><p class="orion-builder-v2-price">$500</p><p>Best for focused launches.</p><a class="orion-builder-v2-button" href="/contact">Choose Starter</a></article>
|
|
532
|
+
<article class="orion-builder-v2-card is-featured"><h3>Growth</h3><p class="orion-builder-v2-price">$1,500</p><p>Best for expanding teams.</p><a class="orion-builder-v2-button" href="/contact">Choose Growth</a></article>
|
|
533
|
+
<article class="orion-builder-v2-card"><h3>Custom</h3><p class="orion-builder-v2-price">Quote</p><p>Best for complex builds.</p><a class="orion-builder-v2-button" href="/contact">Talk with us</a></article>
|
|
534
|
+
</div>
|
|
535
|
+
</div>
|
|
536
|
+
</section>
|
|
537
|
+
`,
|
|
538
|
+
label: "Pricing"
|
|
539
|
+
});
|
|
540
|
+
blocks.add("orion-button", {
|
|
541
|
+
category: "Basic",
|
|
542
|
+
content: '<a class="orion-builder-v2-button" href="/contact">Button</a>',
|
|
543
|
+
label: "Button"
|
|
544
|
+
});
|
|
545
|
+
blocks.add("orion-image", {
|
|
546
|
+
category: "Basic",
|
|
547
|
+
content: '<img alt="Image" class="orion-builder-v2-image" src="https://placehold.co/1200x700" />',
|
|
548
|
+
label: "Image"
|
|
549
|
+
});
|
|
550
|
+
blocks.add("orion-form-embed", {
|
|
551
|
+
category: "Dynamic",
|
|
552
|
+
content: `
|
|
553
|
+
<div
|
|
554
|
+
class="orion-builder-v2-dynamic-placeholder"
|
|
555
|
+
data-orion-component="formEmbed"
|
|
556
|
+
data-orion-form-slug="contact"
|
|
557
|
+
>
|
|
558
|
+
<strong>Form Embed</strong>
|
|
559
|
+
<span>contact</span>
|
|
560
|
+
</div>
|
|
561
|
+
`,
|
|
562
|
+
label: "Form"
|
|
563
|
+
});
|
|
564
|
+
blocks.add("orion-footer", {
|
|
565
|
+
category: "Chrome",
|
|
566
|
+
content: `
|
|
567
|
+
<footer class="orion-builder-v2-footer">
|
|
568
|
+
<div>
|
|
569
|
+
<strong>Brand</strong>
|
|
570
|
+
<p>Short positioning line for the site footer.</p>
|
|
571
|
+
</div>
|
|
572
|
+
<nav aria-label="Footer">
|
|
573
|
+
<a href="/privacy">Privacy</a>
|
|
574
|
+
<a href="/contact">Contact</a>
|
|
575
|
+
</nav>
|
|
576
|
+
</footer>
|
|
577
|
+
`,
|
|
578
|
+
label: "Footer"
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// src/builder-v2/editor/projectComponents.ts
|
|
583
|
+
var normalizeDefinition = (type, value) => {
|
|
584
|
+
if (!value || typeof value === "function") {
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
...value,
|
|
589
|
+
type: value.type || type
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
var decodeHtmlAttribute2 = (value) => typeof value === "string" ? value.replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") : "";
|
|
593
|
+
var attrToPropName = (name) => name.replace(/^data-orion-/, "").replace(/^data-/, "").replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
594
|
+
var propsFromAttributes = (attributes = {}) => {
|
|
595
|
+
const props = {};
|
|
596
|
+
Object.keys(attributes).forEach((name) => {
|
|
597
|
+
if (!name.startsWith("data-") || name === "data-orion-component" || name === "data-orion-id") {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
const value = decodeHtmlAttribute2(attributes[name]);
|
|
601
|
+
if (name === "data-orion-props") {
|
|
602
|
+
try {
|
|
603
|
+
const parsed = JSON.parse(value);
|
|
604
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
605
|
+
Object.assign(props, parsed);
|
|
606
|
+
}
|
|
607
|
+
} catch {
|
|
608
|
+
props.propsJson = value;
|
|
609
|
+
}
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
props[attrToPropName(name)] = value;
|
|
613
|
+
});
|
|
614
|
+
return props;
|
|
615
|
+
};
|
|
616
|
+
var previewForDefinition = (definition, props) => definition.editorPreview?.(props) || `<div class="orion-builder-v2-dynamic-placeholder"><strong>${definition.label}</strong></div>`;
|
|
617
|
+
var registerProjectDynamicComponents = (editor, adapter) => {
|
|
618
|
+
const components = adapter?.components || {};
|
|
619
|
+
Object.keys(components).forEach((type) => {
|
|
620
|
+
const definition = normalizeDefinition(type, components[type]);
|
|
621
|
+
if (!definition) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
editor.DomComponents.addType(`orion-${type}`, {
|
|
625
|
+
model: {
|
|
626
|
+
defaults: {
|
|
627
|
+
attributes: {
|
|
628
|
+
"data-orion-component": type,
|
|
629
|
+
"data-orion-id": `${type}-${Date.now()}`
|
|
630
|
+
},
|
|
631
|
+
components: "",
|
|
632
|
+
droppable: false,
|
|
633
|
+
tagName: "div",
|
|
634
|
+
traits: [
|
|
635
|
+
{
|
|
636
|
+
label: "Component",
|
|
637
|
+
name: "data-orion-component",
|
|
638
|
+
type: "text"
|
|
639
|
+
},
|
|
640
|
+
...(definition.traits || []).map((trait) => ({
|
|
641
|
+
label: trait.label,
|
|
642
|
+
name: `data-orion-${trait.name.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`)}`,
|
|
643
|
+
options: trait.options,
|
|
644
|
+
placeholder: trait.placeholder,
|
|
645
|
+
type: trait.type
|
|
646
|
+
}))
|
|
647
|
+
]
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
view: {
|
|
651
|
+
init() {
|
|
652
|
+
this.listenTo(this.model, "change:attributes", this.renderPreview);
|
|
653
|
+
this.renderPreview();
|
|
654
|
+
},
|
|
655
|
+
renderPreview() {
|
|
656
|
+
const attributes = this.model.getAttributes?.() || {};
|
|
657
|
+
const props = propsFromAttributes(attributes);
|
|
658
|
+
this.model.components(previewForDefinition(definition, props));
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
editor.Blocks.add(`orion-dynamic-${type}`, {
|
|
663
|
+
category: "Project",
|
|
664
|
+
content: {
|
|
665
|
+
type: `orion-${type}`
|
|
666
|
+
},
|
|
667
|
+
label: definition.label
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// src/builder-v2/editor/GrapesPageEditor.tsx
|
|
673
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
674
|
+
var postToParent = (payload) => {
|
|
675
|
+
window.parent?.postMessage(
|
|
676
|
+
{
|
|
677
|
+
source: "payload-visual-builder-child",
|
|
678
|
+
...payload
|
|
679
|
+
},
|
|
680
|
+
"*"
|
|
681
|
+
);
|
|
682
|
+
};
|
|
683
|
+
var buildSavePayload = (editor, status, projectData) => ({
|
|
684
|
+
builderMode: "grapes-v2",
|
|
685
|
+
compiledCss: scopeBuilderCss(editor.getCss()),
|
|
686
|
+
compiledHtml: sanitizeBuilderHtml(editor.getHtml()),
|
|
687
|
+
projectData,
|
|
688
|
+
status
|
|
689
|
+
});
|
|
690
|
+
var parsePayloadErrorMessage = async (response, fallback) => {
|
|
691
|
+
try {
|
|
692
|
+
const json = await response.json();
|
|
693
|
+
return json.errors?.[0]?.message || json.message || fallback;
|
|
694
|
+
} catch {
|
|
695
|
+
const raw = await response.text();
|
|
696
|
+
return raw.trim() || fallback;
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
var getRelationID = (value) => {
|
|
700
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
701
|
+
return value;
|
|
702
|
+
}
|
|
703
|
+
if (!value || typeof value !== "object") {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
const id = value.id;
|
|
707
|
+
return typeof id === "number" || typeof id === "string" ? id : null;
|
|
708
|
+
};
|
|
709
|
+
var mediaDocToAsset = (doc) => {
|
|
710
|
+
const id = getRelationID(doc);
|
|
711
|
+
const filename = typeof doc.filename === "string" ? doc.filename : "";
|
|
712
|
+
const src = typeof doc.url === "string" && doc.url.length > 0 ? doc.url : filename ? `/api/media/file/${encodeURIComponent(filename)}` : "";
|
|
713
|
+
if (id === null || !src) {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
return {
|
|
717
|
+
alt: typeof doc.alt === "string" ? doc.alt : "",
|
|
718
|
+
id,
|
|
719
|
+
name: filename || String(id),
|
|
720
|
+
src,
|
|
721
|
+
type: "image"
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
var extractUploadedMedia = (value) => {
|
|
725
|
+
const candidate = value && typeof value === "object" && "doc" in value ? value.doc : value;
|
|
726
|
+
if (!candidate || typeof candidate !== "object") {
|
|
727
|
+
return null;
|
|
728
|
+
}
|
|
729
|
+
const id = getRelationID(candidate);
|
|
730
|
+
if (id === null) {
|
|
731
|
+
return null;
|
|
732
|
+
}
|
|
733
|
+
const typed = candidate;
|
|
734
|
+
return {
|
|
735
|
+
alt: typeof typed.alt === "string" ? typed.alt : "",
|
|
736
|
+
filename: typeof typed.filename === "string" ? typed.filename : "",
|
|
737
|
+
id,
|
|
738
|
+
url: typeof typed.url === "string" ? typed.url : ""
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
var loadPayloadMediaAssets = async (editor) => {
|
|
742
|
+
const response = await fetch(`/api/media?depth=1&limit=100&sort=-updatedAt&_=${Date.now()}`, {
|
|
743
|
+
cache: "no-store",
|
|
744
|
+
credentials: "include"
|
|
745
|
+
});
|
|
746
|
+
if (!response.ok) {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
const json = await response.json();
|
|
750
|
+
const assets = (Array.isArray(json.docs) ? json.docs : []).map((doc) => mediaDocToAsset(doc)).filter((asset) => asset !== null);
|
|
751
|
+
editor.AssetManager.add(assets);
|
|
752
|
+
};
|
|
753
|
+
var uploadPayloadMediaAssets = async (editor, files) => {
|
|
754
|
+
const fileArray = Array.from(files);
|
|
755
|
+
const uploadedAssets = [];
|
|
756
|
+
for (const file of fileArray) {
|
|
757
|
+
const optimizedFile = await optimizeImageForUpload(file);
|
|
758
|
+
if (optimizedFile.size > MAX_DIRECT_UPLOAD_BYTES) {
|
|
759
|
+
throw new Error("Image is too large. Use an image under 4MB or lower-resolution export.");
|
|
760
|
+
}
|
|
761
|
+
const fallbackAlt = file.name.replace(/\.[^/.]+$/, "").trim();
|
|
762
|
+
const formData = new FormData();
|
|
763
|
+
formData.set("_payload", JSON.stringify({ alt: fallbackAlt || "Uploaded image" }));
|
|
764
|
+
formData.set("alt", fallbackAlt || "Uploaded image");
|
|
765
|
+
formData.set("file", optimizedFile);
|
|
766
|
+
const response = await fetch("/api/media", {
|
|
767
|
+
body: formData,
|
|
768
|
+
credentials: "include",
|
|
769
|
+
method: "POST"
|
|
770
|
+
});
|
|
771
|
+
if (!response.ok) {
|
|
772
|
+
throw new Error(await parsePayloadErrorMessage(response, "Could not upload image."));
|
|
773
|
+
}
|
|
774
|
+
const uploaded = extractUploadedMedia(await response.json());
|
|
775
|
+
const asset = uploaded ? mediaDocToAsset(uploaded) : null;
|
|
776
|
+
if (asset) {
|
|
777
|
+
uploadedAssets.push(asset);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
if (uploadedAssets.length > 0) {
|
|
781
|
+
editor.AssetManager.add(uploadedAssets);
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
function GrapesPageEditor({
|
|
785
|
+
adapter,
|
|
786
|
+
autosaveIntervalMs = 3e4,
|
|
787
|
+
initialData,
|
|
788
|
+
pageID
|
|
789
|
+
}) {
|
|
790
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
791
|
+
const editorRef = (0, import_react.useRef)(null);
|
|
792
|
+
const autosaveTimerRef = (0, import_react.useRef)(null);
|
|
793
|
+
const saveRef = (0, import_react.useRef)(async () => void 0);
|
|
794
|
+
const [error, setError] = (0, import_react.useState)("");
|
|
795
|
+
const [historyState, setHistoryState] = (0, import_react.useState)({ canRedo: false, canUndo: false });
|
|
796
|
+
const [lastSavedAt, setLastSavedAt] = (0, import_react.useState)("");
|
|
797
|
+
const [loading, setLoading] = (0, import_react.useState)(true);
|
|
798
|
+
const [selectedDevice, setSelectedDevice] = (0, import_react.useState)("desktop");
|
|
799
|
+
const [saving, setSaving] = (0, import_react.useState)(null);
|
|
800
|
+
const [saveMessage, setSaveMessage] = (0, import_react.useState)("");
|
|
801
|
+
const [validationIssues, setValidationIssues] = (0, import_react.useState)([]);
|
|
802
|
+
const pageTree = initialData?.meta?.pageTree || [];
|
|
803
|
+
const updateHistoryState = (editor) => {
|
|
804
|
+
const next = {
|
|
805
|
+
canRedo: editor.UndoManager.hasRedo(),
|
|
806
|
+
canUndo: editor.UndoManager.hasUndo()
|
|
807
|
+
};
|
|
808
|
+
setHistoryState(next);
|
|
809
|
+
postToParent({
|
|
810
|
+
...next,
|
|
811
|
+
type: "history-state"
|
|
812
|
+
});
|
|
813
|
+
};
|
|
814
|
+
const runValidation = (editor) => {
|
|
815
|
+
const issues = validateBuilderV2Output({
|
|
816
|
+
css: editor.getCss(),
|
|
817
|
+
html: editor.getHtml()
|
|
818
|
+
});
|
|
819
|
+
setValidationIssues(issues);
|
|
820
|
+
postToParent({ issues, type: "validation-state" });
|
|
821
|
+
return issues;
|
|
822
|
+
};
|
|
823
|
+
const setDevice = (device) => {
|
|
824
|
+
const editor = editorRef.current;
|
|
825
|
+
if (!editor) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
editor.setDevice(device);
|
|
829
|
+
setSelectedDevice(device);
|
|
830
|
+
};
|
|
831
|
+
(0, import_react.useEffect)(() => {
|
|
832
|
+
let active = true;
|
|
833
|
+
const init = async () => {
|
|
834
|
+
if (!containerRef.current || editorRef.current) {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
try {
|
|
838
|
+
const grapesjs = (await import("grapesjs")).default;
|
|
839
|
+
if (!active || !containerRef.current) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const projectData = normalizeBuilderV2ProjectData(initialData?.projectData, initialData?.title);
|
|
843
|
+
const editor = grapesjs.init({
|
|
844
|
+
assetManager: {
|
|
845
|
+
uploadFile: async (event) => {
|
|
846
|
+
const target = event.target;
|
|
847
|
+
const dataTransfer = "dataTransfer" in event ? event.dataTransfer : null;
|
|
848
|
+
const files = dataTransfer?.files || target?.files;
|
|
849
|
+
if (!files || files.length === 0) {
|
|
850
|
+
return void 0;
|
|
851
|
+
}
|
|
852
|
+
await uploadPayloadMediaAssets(editorRef.current || editor, files).catch((uploadError) => {
|
|
853
|
+
setError(uploadError instanceof Error ? uploadError.message : "Could not upload image.");
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
blockManager: {
|
|
858
|
+
appendTo: "#orion-builder-v2-blocks"
|
|
859
|
+
},
|
|
860
|
+
container: containerRef.current,
|
|
861
|
+
deviceManager: {
|
|
862
|
+
devices: [
|
|
863
|
+
{ id: "desktop", name: "Desktop", width: "" },
|
|
864
|
+
{ id: "tablet", name: "Tablet", width: "768px" },
|
|
865
|
+
{ id: "mobile", name: "Mobile", width: "390px" }
|
|
866
|
+
]
|
|
867
|
+
},
|
|
868
|
+
fromElement: false,
|
|
869
|
+
height: "100%",
|
|
870
|
+
panels: {
|
|
871
|
+
defaults: []
|
|
872
|
+
},
|
|
873
|
+
selectorManager: {
|
|
874
|
+
componentFirst: true
|
|
875
|
+
},
|
|
876
|
+
storageManager: false,
|
|
877
|
+
styleManager: {
|
|
878
|
+
sectors: [
|
|
879
|
+
{
|
|
880
|
+
name: "Layout",
|
|
881
|
+
open: true,
|
|
882
|
+
properties: ["display", "position", "top", "right", "bottom", "left", "width", "height", "min-height", "margin", "padding"]
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
name: "Typography",
|
|
886
|
+
open: true,
|
|
887
|
+
properties: ["font-family", "font-size", "font-weight", "line-height", "letter-spacing", "color", "text-align"]
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
name: "Decoration",
|
|
891
|
+
open: true,
|
|
892
|
+
properties: ["background-color", "background", "border", "border-radius", "box-shadow", "opacity"]
|
|
893
|
+
},
|
|
894
|
+
{
|
|
895
|
+
name: "Flex",
|
|
896
|
+
open: false,
|
|
897
|
+
properties: ["flex-direction", "justify-content", "align-items", "gap", "flex-wrap"]
|
|
898
|
+
}
|
|
899
|
+
]
|
|
900
|
+
},
|
|
901
|
+
traitManager: {
|
|
902
|
+
appendTo: "#orion-builder-v2-traits"
|
|
903
|
+
},
|
|
904
|
+
width: "auto"
|
|
905
|
+
});
|
|
906
|
+
editorRef.current = editor;
|
|
907
|
+
registerOrionBuilderV2Blocks(editor);
|
|
908
|
+
registerProjectDynamicComponents(editor, adapter);
|
|
909
|
+
editor.loadProjectData(projectData);
|
|
910
|
+
void loadPayloadMediaAssets(editor);
|
|
911
|
+
editor.on("update", () => {
|
|
912
|
+
postToParent({ dirty: editor.getDirtyCount() > 0, type: "dirty-state" });
|
|
913
|
+
updateHistoryState(editor);
|
|
914
|
+
runValidation(editor);
|
|
915
|
+
setSaveMessage("Unsaved changes");
|
|
916
|
+
if (autosaveTimerRef.current) {
|
|
917
|
+
window.clearTimeout(autosaveTimerRef.current);
|
|
918
|
+
}
|
|
919
|
+
autosaveTimerRef.current = window.setTimeout(() => {
|
|
920
|
+
if (editor.getDirtyCount() > 0) {
|
|
921
|
+
void saveRef.current("draft", { autosave: true });
|
|
922
|
+
}
|
|
923
|
+
}, autosaveIntervalMs);
|
|
924
|
+
});
|
|
925
|
+
editor.on("component:selected", () => {
|
|
926
|
+
setSaveMessage("Selection ready");
|
|
927
|
+
});
|
|
928
|
+
setSelectedDevice(editor.getDevice() || "desktop");
|
|
929
|
+
runValidation(editor);
|
|
930
|
+
updateHistoryState(editor);
|
|
931
|
+
setLoading(false);
|
|
932
|
+
} catch (initError) {
|
|
933
|
+
setError(initError instanceof Error ? initError.message : "Could not load the website builder.");
|
|
934
|
+
setLoading(false);
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
void init();
|
|
938
|
+
return () => {
|
|
939
|
+
active = false;
|
|
940
|
+
if (autosaveTimerRef.current) {
|
|
941
|
+
window.clearTimeout(autosaveTimerRef.current);
|
|
942
|
+
}
|
|
943
|
+
editorRef.current?.destroy();
|
|
944
|
+
editorRef.current = null;
|
|
945
|
+
};
|
|
946
|
+
}, [adapter, autosaveIntervalMs, initialData?.projectData, initialData?.title]);
|
|
947
|
+
const save = async (status, options = {}) => {
|
|
948
|
+
const editor = editorRef.current;
|
|
949
|
+
if (!editor || saving) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const issues = runValidation(editor);
|
|
953
|
+
if (status === "published" && hasBlockingBuilderV2Issues(issues)) {
|
|
954
|
+
const message = "Resolve blocking validation errors before publishing.";
|
|
955
|
+
setSaveMessage(message);
|
|
956
|
+
postToParent({
|
|
957
|
+
message,
|
|
958
|
+
ok: false,
|
|
959
|
+
status,
|
|
960
|
+
type: "save-result"
|
|
961
|
+
});
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
setSaving(status);
|
|
965
|
+
try {
|
|
966
|
+
const projectData = editor.getProjectData();
|
|
967
|
+
const payload = buildSavePayload(editor, status, projectData);
|
|
968
|
+
const dynamicComponents = parseBuilderV2DynamicComponents(String(payload.compiledHtml || ""));
|
|
969
|
+
const endpoint = status === "draft" ? `/api/pages/${pageID}?draft=true` : `/api/pages/${pageID}`;
|
|
970
|
+
const response = await fetch(endpoint, {
|
|
971
|
+
body: JSON.stringify(
|
|
972
|
+
status === "published" ? {
|
|
973
|
+
_status: "published",
|
|
974
|
+
builderDynamicComponents: dynamicComponents,
|
|
975
|
+
builderMode: "grapes-v2",
|
|
976
|
+
builderProjectData: projectData,
|
|
977
|
+
builderPublishedProjectData: projectData,
|
|
978
|
+
builderLastPublishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
979
|
+
builderLastSavedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
980
|
+
builderValidationIssues: issues,
|
|
981
|
+
compiledCss: payload.compiledCss,
|
|
982
|
+
compiledHtml: payload.compiledHtml
|
|
983
|
+
} : {
|
|
984
|
+
_status: "draft",
|
|
985
|
+
builderAutosaveProjectData: options.autosave ? projectData : null,
|
|
986
|
+
builderDynamicComponents: dynamicComponents,
|
|
987
|
+
builderMode: "grapes-v2",
|
|
988
|
+
builderProjectData: projectData,
|
|
989
|
+
builderLastSavedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
990
|
+
builderValidationIssues: issues,
|
|
991
|
+
compiledCss: payload.compiledCss,
|
|
992
|
+
compiledHtml: payload.compiledHtml
|
|
993
|
+
}
|
|
994
|
+
),
|
|
995
|
+
credentials: "include",
|
|
996
|
+
headers: {
|
|
997
|
+
"Content-Type": "application/json"
|
|
998
|
+
},
|
|
999
|
+
method: "PATCH"
|
|
1000
|
+
});
|
|
1001
|
+
if (!response.ok) {
|
|
1002
|
+
if (response.status === 401 || response.status === 403) {
|
|
1003
|
+
postToParent({ type: "session-expired" });
|
|
1004
|
+
}
|
|
1005
|
+
throw new Error(await parsePayloadErrorMessage(response, "Could not save this page."));
|
|
1006
|
+
}
|
|
1007
|
+
editor.clearDirtyCount();
|
|
1008
|
+
postToParent({
|
|
1009
|
+
dirty: false,
|
|
1010
|
+
type: "dirty-state"
|
|
1011
|
+
});
|
|
1012
|
+
postToParent({
|
|
1013
|
+
message: status === "published" ? "Published." : options.autosave ? "Autosaved." : "Draft saved.",
|
|
1014
|
+
ok: true,
|
|
1015
|
+
status,
|
|
1016
|
+
type: "save-result"
|
|
1017
|
+
});
|
|
1018
|
+
setLastSavedAt((/* @__PURE__ */ new Date()).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }));
|
|
1019
|
+
setSaveMessage(status === "published" ? "Published" : options.autosave ? "Autosaved" : "Draft saved");
|
|
1020
|
+
} catch (saveError) {
|
|
1021
|
+
const message = saveError instanceof Error ? saveError.message : "Could not save.";
|
|
1022
|
+
setSaveMessage(message);
|
|
1023
|
+
postToParent({
|
|
1024
|
+
message,
|
|
1025
|
+
ok: false,
|
|
1026
|
+
status,
|
|
1027
|
+
type: "save-result"
|
|
1028
|
+
});
|
|
1029
|
+
} finally {
|
|
1030
|
+
setSaving(null);
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
(0, import_react.useEffect)(() => {
|
|
1034
|
+
saveRef.current = save;
|
|
1035
|
+
}, [saving]);
|
|
1036
|
+
(0, import_react.useEffect)(() => {
|
|
1037
|
+
const onMessage = (event) => {
|
|
1038
|
+
const data = event.data;
|
|
1039
|
+
const editor = editorRef.current;
|
|
1040
|
+
if (!data || data.source !== "payload-visual-builder-parent" || !editor) {
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
if (data.type === "dirty-check-request") {
|
|
1044
|
+
postToParent({ dirty: editor.getDirtyCount() > 0, type: "dirty-state" });
|
|
1045
|
+
updateHistoryState(editor);
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
if (data.type === "history-check-request") {
|
|
1049
|
+
updateHistoryState(editor);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (data.type === "undo") {
|
|
1053
|
+
editor.UndoManager.undo();
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (data.type === "redo") {
|
|
1057
|
+
editor.UndoManager.redo();
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
if (data.type === "save" && (data.status === "draft" || data.status === "published")) {
|
|
1061
|
+
void save(data.status);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
window.addEventListener("message", onMessage);
|
|
1065
|
+
return () => window.removeEventListener("message", onMessage);
|
|
1066
|
+
}, [saving]);
|
|
1067
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "orion-builder-v2-editor", children: [
|
|
1068
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", { className: "orion-builder-v2-topbar", children: [
|
|
1069
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
1070
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "orion-builder-v2-eyebrow", children: "Website Builder V2" }),
|
|
1071
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: initialData?.title || "Untitled page" })
|
|
1072
|
+
] }),
|
|
1073
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "orion-builder-v2-toolbar", "aria-label": "Builder controls", children: [
|
|
1074
|
+
["desktop", "tablet", "mobile"].map((device) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1075
|
+
"button",
|
|
1076
|
+
{
|
|
1077
|
+
"aria-pressed": selectedDevice === device,
|
|
1078
|
+
className: "orion-builder-v2-tool",
|
|
1079
|
+
onClick: () => setDevice(device),
|
|
1080
|
+
type: "button",
|
|
1081
|
+
children: device
|
|
1082
|
+
},
|
|
1083
|
+
device
|
|
1084
|
+
)),
|
|
1085
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1086
|
+
"button",
|
|
1087
|
+
{
|
|
1088
|
+
className: "orion-builder-v2-tool",
|
|
1089
|
+
disabled: !historyState.canUndo,
|
|
1090
|
+
onClick: () => {
|
|
1091
|
+
editorRef.current?.UndoManager.undo();
|
|
1092
|
+
editorRef.current && updateHistoryState(editorRef.current);
|
|
1093
|
+
},
|
|
1094
|
+
type: "button",
|
|
1095
|
+
children: "Undo"
|
|
1096
|
+
}
|
|
1097
|
+
),
|
|
1098
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1099
|
+
"button",
|
|
1100
|
+
{
|
|
1101
|
+
className: "orion-builder-v2-tool",
|
|
1102
|
+
disabled: !historyState.canRedo,
|
|
1103
|
+
onClick: () => {
|
|
1104
|
+
editorRef.current?.UndoManager.redo();
|
|
1105
|
+
editorRef.current && updateHistoryState(editorRef.current);
|
|
1106
|
+
},
|
|
1107
|
+
type: "button",
|
|
1108
|
+
children: "Redo"
|
|
1109
|
+
}
|
|
1110
|
+
),
|
|
1111
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "orion-builder-v2-tool is-primary", disabled: Boolean(saving), onClick: () => void save("draft"), type: "button", children: saving === "draft" ? "Saving..." : "Save draft" }),
|
|
1112
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "orion-builder-v2-tool is-publish", disabled: Boolean(saving), onClick: () => void save("published"), type: "button", children: saving === "published" ? "Publishing..." : "Publish" })
|
|
1113
|
+
] })
|
|
1114
|
+
] }),
|
|
1115
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("aside", { className: "orion-builder-v2-sidebar", children: [
|
|
1116
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "orion-builder-v2-panel", children: [
|
|
1117
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: "Pages" }),
|
|
1118
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "orion-builder-v2-page-tree", children: pageTree.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "No pages loaded." }) : pageTree.map((page) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("a", { className: "orion-builder-v2-page-link", href: `#page-${page.id}`, children: [
|
|
1119
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: page.title }),
|
|
1120
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: page.path })
|
|
1121
|
+
] }, page.id)) })
|
|
1122
|
+
] }),
|
|
1123
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "orion-builder-v2-panel", children: [
|
|
1124
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: "Blocks" }),
|
|
1125
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Drag sections into the page. Dynamic blocks render through the project adapter." }),
|
|
1126
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: "orion-builder-v2-blocks" })
|
|
1127
|
+
] }),
|
|
1128
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "orion-builder-v2-panel", children: [
|
|
1129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: "Inspector" }),
|
|
1130
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Selection settings, dynamic bindings, links, and labels." }),
|
|
1131
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: "orion-builder-v2-traits" })
|
|
1132
|
+
] }),
|
|
1133
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "orion-builder-v2-panel", children: [
|
|
1134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: "Validation" }),
|
|
1135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "orion-builder-v2-validation-list", children: validationIssues.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "No issues found." }) : validationIssues.map((issue) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `orion-builder-v2-validation is-${issue.severity}`, children: [
|
|
1136
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: issue.message }),
|
|
1137
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: issue.severity })
|
|
1138
|
+
] }, `${issue.code}-${issue.path}`)) })
|
|
1139
|
+
] })
|
|
1140
|
+
] }),
|
|
1141
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("main", { className: "orion-builder-v2-main", children: [
|
|
1142
|
+
loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "orion-builder-v2-status", children: "Loading builder..." }) : null,
|
|
1143
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "orion-builder-v2-error", children: error }) : null,
|
|
1144
|
+
saveMessage || lastSavedAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "orion-builder-v2-save-status", children: [
|
|
1145
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: saveMessage || "Ready" }),
|
|
1146
|
+
lastSavedAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
|
|
1147
|
+
"Last saved ",
|
|
1148
|
+
lastSavedAt
|
|
1149
|
+
] }) : null
|
|
1150
|
+
] }) : null,
|
|
1151
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "orion-builder-v2-canvas", ref: containerRef })
|
|
1152
|
+
] })
|
|
1153
|
+
] });
|
|
1154
|
+
}
|
|
1155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1156
|
+
0 && (module.exports = {
|
|
1157
|
+
GrapesPageEditor
|
|
1158
|
+
});
|