@orion-studios/payload-studio 0.5.0-beta.7 → 0.5.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.
- package/README.md +20 -0
- package/dist/admin/client.d.mts +2 -0
- package/dist/admin/client.d.ts +2 -0
- package/dist/admin/client.js +779 -137
- package/dist/admin/client.mjs +769 -129
- package/dist/admin/index.d.mts +1 -1
- package/dist/admin/index.d.ts +1 -1
- package/dist/admin/index.js +100 -8
- package/dist/admin/index.mjs +3 -1
- package/dist/admin-app/client.d.mts +7 -0
- package/dist/admin-app/client.d.ts +7 -0
- package/dist/admin-app/client.js +1262 -3
- package/dist/admin-app/client.mjs +1164 -2
- package/dist/admin-app/index.d.mts +1 -1
- package/dist/admin-app/index.d.ts +1 -1
- package/dist/admin-app/index.js +167 -0
- package/dist/admin-app/index.mjs +13 -1
- package/dist/admin-app/styles.css +229 -0
- package/dist/blocks/index.js +633 -8
- package/dist/blocks/index.mjs +2 -2
- package/dist/{chunk-ZLLNO5FM.mjs → chunk-CKX5Y2HU.mjs} +44 -13
- package/dist/{chunk-J7W5EE3B.mjs → chunk-HCEPGEAI.mjs} +100 -8
- package/dist/chunk-HXGAG6I7.mjs +325 -0
- package/dist/chunk-ROTPP5CU.mjs +99 -0
- package/dist/{chunk-ETRRXURT.mjs → chunk-SIL2J5MF.mjs} +14 -0
- package/dist/chunk-VDGSMD6H.mjs +1072 -0
- package/dist/{chunk-PC5622T7.mjs → chunk-XK3K5GRP.mjs} +620 -9
- package/dist/chunk-XVH5SCBD.mjs +234 -0
- package/dist/{index-CmR6NInu.d.ts → index-BIwu3qIH.d.mts} +29 -3
- package/dist/{index-CmR6NInu.d.mts → index-BIwu3qIH.d.ts} +29 -3
- package/dist/index-CdnUNrvX.d.mts +134 -0
- package/dist/{index-DbH0Ljwp.d.ts → index-CpG3UHcS.d.mts} +1 -0
- package/dist/{index-DbH0Ljwp.d.mts → index-CpG3UHcS.d.ts} +1 -0
- package/dist/index-DyHbWliW.d.ts +134 -0
- package/dist/index-ZbOx4OCF.d.mts +128 -0
- package/dist/index-ZbOx4OCF.d.ts +128 -0
- package/dist/{index-DJFhANvJ.d.mts → index-cDYkEj29.d.mts} +20 -2
- package/dist/{index-DJFhANvJ.d.ts → index-cDYkEj29.d.ts} +20 -2
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2145 -305
- package/dist/index.mjs +9 -9
- package/dist/nextjs/index.d.mts +1 -1
- package/dist/nextjs/index.d.ts +1 -1
- package/dist/nextjs/index.js +996 -13
- package/dist/nextjs/index.mjs +4 -1
- package/dist/studio/index.d.mts +2 -1
- package/dist/studio/index.d.ts +2 -1
- package/dist/studio/index.js +171 -2
- package/dist/studio/index.mjs +7 -3
- package/dist/studio-pages/builder.css +358 -8
- package/dist/studio-pages/client.d.mts +17 -0
- package/dist/studio-pages/client.d.ts +17 -0
- package/dist/studio-pages/client.js +5657 -1478
- package/dist/studio-pages/client.mjs +5549 -1461
- package/dist/studio-pages/index.d.mts +3 -2
- package/dist/studio-pages/index.d.ts +3 -2
- package/dist/studio-pages/index.js +799 -29
- package/dist/studio-pages/index.mjs +6 -2
- package/package.json +26 -12
- package/dist/chunk-AAOHJDNS.mjs +0 -67
- package/dist/chunk-N67KVM2S.mjs +0 -156
- package/dist/chunk-UJFU323N.mjs +0 -301
- package/dist/index-B9N5MyjF.d.mts +0 -39
- package/dist/index-BallJs-K.d.mts +0 -43
- package/dist/index-BallJs-K.d.ts +0 -43
- package/dist/index-g8tBHLKD.d.ts +0 -39
package/dist/admin-app/client.js
CHANGED
|
@@ -21,7 +21,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/admin-app/client.ts
|
|
22
22
|
var client_exports = {};
|
|
23
23
|
__export(client_exports, {
|
|
24
|
-
AdminShellClient: () => AdminShellClient
|
|
24
|
+
AdminShellClient: () => AdminShellClient,
|
|
25
|
+
HeaderNavEditorWithPreview: () => HeaderNavEditorWithPreview,
|
|
26
|
+
HeaderNavItemsEditor: () => HeaderNavItemsEditor,
|
|
27
|
+
MediaDetailPanel: () => MediaDetailPanel,
|
|
28
|
+
MediaListItem: () => MediaListItem,
|
|
29
|
+
MediaUploadForm: () => MediaUploadForm,
|
|
30
|
+
PageEditorFrame: () => PageEditorFrame
|
|
25
31
|
});
|
|
26
32
|
module.exports = __toCommonJS(client_exports);
|
|
27
33
|
|
|
@@ -47,6 +53,47 @@ var navItemIsActive = (pathname, item) => {
|
|
|
47
53
|
|
|
48
54
|
// src/admin-app/components/AdminShellClient.tsx
|
|
49
55
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
56
|
+
var iconSize = 20;
|
|
57
|
+
var iconStyle = { display: "block", flexShrink: 0 };
|
|
58
|
+
function NavIcon({ name }) {
|
|
59
|
+
const props = { width: iconSize, height: iconSize, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", style: iconStyle };
|
|
60
|
+
switch (name) {
|
|
61
|
+
case "dashboard":
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { ...props, children: [
|
|
63
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "7", height: "9", rx: "1" }),
|
|
64
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "14", y: "3", width: "7", height: "5", rx: "1" }),
|
|
65
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "14", y: "12", width: "7", height: "9", rx: "1" }),
|
|
66
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "16", width: "7", height: "5", rx: "1" })
|
|
67
|
+
] });
|
|
68
|
+
case "pages":
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { ...props, children: [
|
|
70
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z" }),
|
|
71
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "14 2 14 8 20 8" }),
|
|
72
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "8", y1: "13", x2: "16", y2: "13" }),
|
|
73
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "8", y1: "17", x2: "12", y2: "17" })
|
|
74
|
+
] });
|
|
75
|
+
case "globals":
|
|
76
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { ...props, children: [
|
|
77
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "3" }),
|
|
78
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1Z" })
|
|
79
|
+
] });
|
|
80
|
+
case "media":
|
|
81
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { ...props, children: [
|
|
82
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }),
|
|
83
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8.5", cy: "8.5", r: "1.5" }),
|
|
84
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "21 15 16 10 5 21" })
|
|
85
|
+
] });
|
|
86
|
+
case "tools":
|
|
87
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76Z" }) });
|
|
88
|
+
case "account":
|
|
89
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { ...props, children: [
|
|
90
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" }),
|
|
91
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "7", r: "4" })
|
|
92
|
+
] });
|
|
93
|
+
default:
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
50
97
|
function AdminShellClient({
|
|
51
98
|
children,
|
|
52
99
|
brandName,
|
|
@@ -114,7 +161,10 @@ function AdminShellClient({
|
|
|
114
161
|
className: `orion-admin-nav-link ${active ? "is-active" : ""}`,
|
|
115
162
|
href: item.href,
|
|
116
163
|
title: item.label,
|
|
117
|
-
children: collapsed ? item.
|
|
164
|
+
children: item.icon ? collapsed ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NavIcon, { name: item.icon }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { alignItems: "center", display: "flex", gap: "0.6rem" }, children: [
|
|
165
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(NavIcon, { name: item.icon }),
|
|
166
|
+
item.label
|
|
167
|
+
] }) : collapsed ? item.label.slice(0, 1) : item.label
|
|
118
168
|
},
|
|
119
169
|
item.href
|
|
120
170
|
);
|
|
@@ -130,7 +180,1216 @@ function AdminShellClient({
|
|
|
130
180
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("main", { className: "orion-admin-main", children })
|
|
131
181
|
] });
|
|
132
182
|
}
|
|
183
|
+
|
|
184
|
+
// src/admin-app/components/HeaderNavItemsEditor.tsx
|
|
185
|
+
var import_react2 = require("react");
|
|
186
|
+
|
|
187
|
+
// src/admin-app/navigationLinks.ts
|
|
188
|
+
var normalizeAdminNavInputs = (rows, pageOptions) => {
|
|
189
|
+
const allowedLinks = new Map(pageOptions.map((option) => [option.href, option.title]));
|
|
190
|
+
const deduped = [];
|
|
191
|
+
const seen = /* @__PURE__ */ new Set();
|
|
192
|
+
for (const row of rows) {
|
|
193
|
+
const href = typeof row.href === "string" ? row.href.trim() : "";
|
|
194
|
+
const defaultLabel = allowedLinks.get(href);
|
|
195
|
+
const explicitLabel = typeof row.label === "string" ? row.label.trim() : "";
|
|
196
|
+
const parentHref = typeof row.parentHref === "string" ? row.parentHref.trim() : "";
|
|
197
|
+
if (!href || !defaultLabel || seen.has(href)) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
seen.add(href);
|
|
201
|
+
deduped.push({
|
|
202
|
+
href,
|
|
203
|
+
label: explicitLabel.length > 0 ? explicitLabel : defaultLabel,
|
|
204
|
+
...parentHref.length > 0 ? { parentHref } : {}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const hrefs = new Set(deduped.map((item) => item.href));
|
|
208
|
+
const parentByHref = new Map(deduped.map((item) => [item.href, item.parentHref || ""]));
|
|
209
|
+
const createsCycle = (href, parentHref) => {
|
|
210
|
+
const visited = /* @__PURE__ */ new Set([href]);
|
|
211
|
+
let current = parentHref;
|
|
212
|
+
while (current) {
|
|
213
|
+
if (visited.has(current)) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
visited.add(current);
|
|
217
|
+
current = parentByHref.get(current) || "";
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
};
|
|
221
|
+
return deduped.map((item) => {
|
|
222
|
+
const parentHref = item.parentHref;
|
|
223
|
+
if (!parentHref || parentHref === item.href || !hrefs.has(parentHref) || createsCycle(item.href, parentHref)) {
|
|
224
|
+
return {
|
|
225
|
+
href: item.href,
|
|
226
|
+
label: item.label
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return item;
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/admin-app/components/HeaderNavItemsEditor.tsx
|
|
234
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
235
|
+
var toRow = (item, index) => ({
|
|
236
|
+
id: `row-${index}-${item.href || "empty"}`,
|
|
237
|
+
href: item.href || "",
|
|
238
|
+
label: item.label || "",
|
|
239
|
+
parentHref: item.parentHref || ""
|
|
240
|
+
});
|
|
241
|
+
var moveRow = (rows, fromIndex, toIndex) => {
|
|
242
|
+
if (fromIndex === toIndex || fromIndex < 0 || toIndex < 0 || fromIndex >= rows.length || toIndex >= rows.length) {
|
|
243
|
+
return rows;
|
|
244
|
+
}
|
|
245
|
+
const next = [...rows];
|
|
246
|
+
const [moved] = next.splice(fromIndex, 1);
|
|
247
|
+
if (!moved) {
|
|
248
|
+
return rows;
|
|
249
|
+
}
|
|
250
|
+
next.splice(toIndex, 0, moved);
|
|
251
|
+
return next;
|
|
252
|
+
};
|
|
253
|
+
function HeaderNavItemsEditor({ initialItems, pageOptions, onItemsChange }) {
|
|
254
|
+
const [rows, setRows] = (0, import_react2.useState)(() => initialItems.map(toRow));
|
|
255
|
+
const [nextRowID, setNextRowID] = (0, import_react2.useState)(initialItems.length);
|
|
256
|
+
const [draggingRowID, setDraggingRowID] = (0, import_react2.useState)(null);
|
|
257
|
+
const [dragOverRowID, setDragOverRowID] = (0, import_react2.useState)(null);
|
|
258
|
+
const pageOptionByHref = (0, import_react2.useMemo)(() => new Map(pageOptions.map((option) => [option.href, option])), [pageOptions]);
|
|
259
|
+
const serializedState = (0, import_react2.useMemo)(
|
|
260
|
+
() => JSON.stringify(
|
|
261
|
+
rows.map((row) => ({
|
|
262
|
+
href: row.href.trim(),
|
|
263
|
+
label: row.label.trim(),
|
|
264
|
+
parentHref: row.parentHref.trim() || void 0
|
|
265
|
+
}))
|
|
266
|
+
),
|
|
267
|
+
[rows]
|
|
268
|
+
);
|
|
269
|
+
const normalizedItems = (0, import_react2.useMemo)(() => {
|
|
270
|
+
const inputs = rows.map((row) => ({
|
|
271
|
+
href: row.href,
|
|
272
|
+
label: row.label,
|
|
273
|
+
parentHref: row.parentHref
|
|
274
|
+
}));
|
|
275
|
+
return normalizeAdminNavInputs(inputs, pageOptions);
|
|
276
|
+
}, [rows, pageOptions]);
|
|
277
|
+
(0, import_react2.useEffect)(() => {
|
|
278
|
+
onItemsChange?.(normalizedItems);
|
|
279
|
+
}, [normalizedItems, onItemsChange]);
|
|
280
|
+
const setRowValue = (rowID, changes) => {
|
|
281
|
+
setRows(
|
|
282
|
+
(currentRows) => currentRows.map((row) => {
|
|
283
|
+
if (row.id !== rowID) {
|
|
284
|
+
return row;
|
|
285
|
+
}
|
|
286
|
+
const nextRow = { ...row, ...changes };
|
|
287
|
+
if (nextRow.parentHref === nextRow.href) {
|
|
288
|
+
nextRow.parentHref = "";
|
|
289
|
+
}
|
|
290
|
+
return nextRow;
|
|
291
|
+
})
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
const removeRow = (rowID) => {
|
|
295
|
+
setRows((currentRows) => {
|
|
296
|
+
const removedRow = currentRows.find((candidate) => candidate.id === rowID);
|
|
297
|
+
const removedHref = removedRow?.href || "";
|
|
298
|
+
return currentRows.filter((row) => row.id !== rowID).map((row) => removedHref && row.parentHref === removedHref ? { ...row, parentHref: "" } : row);
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
const addRow = () => {
|
|
302
|
+
setRows((currentRows) => [
|
|
303
|
+
...currentRows,
|
|
304
|
+
{
|
|
305
|
+
id: `row-new-${nextRowID}`,
|
|
306
|
+
href: "",
|
|
307
|
+
label: "",
|
|
308
|
+
parentHref: ""
|
|
309
|
+
}
|
|
310
|
+
]);
|
|
311
|
+
setNextRowID((current) => current + 1);
|
|
312
|
+
};
|
|
313
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "orion-admin-nav-editor", children: [
|
|
314
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { name: "navItemsState", readOnly: true, type: "hidden", value: serializedState }),
|
|
315
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "orion-admin-nav-editor-head", children: [
|
|
316
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "orion-admin-nav-editor-title", children: "Navigation Items" }),
|
|
317
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "orion-admin-nav-editor-add", onClick: addRow, type: "button", children: "Add Item" })
|
|
318
|
+
] }),
|
|
319
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "orion-admin-nav-editor-help", children: "Add only links you want in the menu. Drag rows to reorder. Set a parent to create dropdown items." }),
|
|
320
|
+
rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "orion-admin-nav-editor-empty", children: 'No navigation items yet. Click "Add Item" to start.' }) : null,
|
|
321
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "orion-admin-nav-editor-list", children: rows.map((row, rowIndex) => {
|
|
322
|
+
const parentCandidates = rows.filter((candidate) => candidate.id !== row.id && candidate.href.trim().length > 0).map((candidate) => {
|
|
323
|
+
const resolved = pageOptionByHref.get(candidate.href);
|
|
324
|
+
return {
|
|
325
|
+
href: candidate.href,
|
|
326
|
+
label: candidate.label.trim() || resolved?.title || candidate.href
|
|
327
|
+
};
|
|
328
|
+
});
|
|
329
|
+
const selectedPage = pageOptionByHref.get(row.href);
|
|
330
|
+
const labelPlaceholder = selectedPage?.title || "Navigation Label";
|
|
331
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
332
|
+
"div",
|
|
333
|
+
{
|
|
334
|
+
className: `orion-admin-nav-editor-row${draggingRowID === row.id ? " is-dragging" : ""}${dragOverRowID === row.id && draggingRowID !== row.id ? " is-drop-target" : ""}`,
|
|
335
|
+
draggable: true,
|
|
336
|
+
onDragEnd: () => {
|
|
337
|
+
setDraggingRowID(null);
|
|
338
|
+
setDragOverRowID(null);
|
|
339
|
+
},
|
|
340
|
+
onDragEnter: () => {
|
|
341
|
+
if (draggingRowID && draggingRowID !== row.id) {
|
|
342
|
+
setDragOverRowID(row.id);
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
onDragLeave: () => {
|
|
346
|
+
if (dragOverRowID === row.id) {
|
|
347
|
+
setDragOverRowID(null);
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
onDragOver: (event) => {
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
if (draggingRowID && draggingRowID !== row.id && dragOverRowID !== row.id) {
|
|
353
|
+
setDragOverRowID(row.id);
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
onDragStart: (event) => {
|
|
357
|
+
setDraggingRowID(row.id);
|
|
358
|
+
event.dataTransfer.effectAllowed = "move";
|
|
359
|
+
},
|
|
360
|
+
onDrop: (event) => {
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
if (!draggingRowID || draggingRowID === row.id) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
setRows((currentRows) => {
|
|
366
|
+
const fromIndex = currentRows.findIndex((entry) => entry.id === draggingRowID);
|
|
367
|
+
const toIndex = currentRows.findIndex((entry) => entry.id === row.id);
|
|
368
|
+
return moveRow(currentRows, fromIndex, toIndex);
|
|
369
|
+
});
|
|
370
|
+
setDraggingRowID(null);
|
|
371
|
+
setDragOverRowID(null);
|
|
372
|
+
},
|
|
373
|
+
children: [
|
|
374
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "orion-admin-nav-editor-row-head", children: [
|
|
375
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "orion-admin-nav-editor-drag", children: "Drag" }),
|
|
376
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "orion-admin-nav-editor-row-index", children: [
|
|
377
|
+
"#",
|
|
378
|
+
rowIndex + 1
|
|
379
|
+
] }),
|
|
380
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "orion-admin-nav-editor-remove", onClick: () => removeRow(row.id), type: "button", children: "Remove" })
|
|
381
|
+
] }),
|
|
382
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "orion-admin-nav-editor-row-grid", children: [
|
|
383
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
384
|
+
"Label",
|
|
385
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
386
|
+
"input",
|
|
387
|
+
{
|
|
388
|
+
name: `navLabel_${rowIndex}`,
|
|
389
|
+
onChange: (event) => setRowValue(row.id, { label: event.target.value }),
|
|
390
|
+
placeholder: labelPlaceholder,
|
|
391
|
+
type: "text",
|
|
392
|
+
value: row.label
|
|
393
|
+
}
|
|
394
|
+
)
|
|
395
|
+
] }),
|
|
396
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
397
|
+
"Page",
|
|
398
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
399
|
+
"select",
|
|
400
|
+
{
|
|
401
|
+
name: `navPage_${rowIndex}`,
|
|
402
|
+
onChange: (event) => {
|
|
403
|
+
const nextHref = event.target.value;
|
|
404
|
+
const nextParent = row.parentHref && row.parentHref === nextHref ? "" : row.parentHref;
|
|
405
|
+
setRowValue(row.id, { href: nextHref, parentHref: nextParent });
|
|
406
|
+
},
|
|
407
|
+
value: row.href,
|
|
408
|
+
children: [
|
|
409
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", children: "Select page..." }),
|
|
410
|
+
pageOptions.map((pageOption) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: pageOption.href, children: pageOption.label }, `${pageOption.href}-${pageOption.title}`))
|
|
411
|
+
]
|
|
412
|
+
}
|
|
413
|
+
)
|
|
414
|
+
] }),
|
|
415
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
416
|
+
"Parent (dropdown under)",
|
|
417
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
418
|
+
"select",
|
|
419
|
+
{
|
|
420
|
+
name: `navParentHref_${rowIndex}`,
|
|
421
|
+
onChange: (event) => setRowValue(row.id, { parentHref: event.target.value }),
|
|
422
|
+
value: row.parentHref,
|
|
423
|
+
children: [
|
|
424
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", children: "Top-level item" }),
|
|
425
|
+
parentCandidates.map((candidate) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: candidate.href, children: candidate.label }, `${row.id}-parent-${candidate.href}`))
|
|
426
|
+
]
|
|
427
|
+
}
|
|
428
|
+
)
|
|
429
|
+
] })
|
|
430
|
+
] })
|
|
431
|
+
]
|
|
432
|
+
},
|
|
433
|
+
row.id
|
|
434
|
+
);
|
|
435
|
+
}) })
|
|
436
|
+
] });
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/admin-app/components/HeaderNavEditorWithPreview.tsx
|
|
440
|
+
var import_react3 = require("react");
|
|
441
|
+
|
|
442
|
+
// src/admin-app/nestedNavigation.ts
|
|
443
|
+
var normalizeNestedNavItems = (items) => {
|
|
444
|
+
const deduped = [];
|
|
445
|
+
const seen = /* @__PURE__ */ new Set();
|
|
446
|
+
for (const item of items) {
|
|
447
|
+
const href = typeof item.href === "string" ? item.href.trim() : "";
|
|
448
|
+
const label = typeof item.label === "string" ? item.label.trim() : "";
|
|
449
|
+
const parentHref = typeof item.parentHref === "string" ? item.parentHref.trim() : "";
|
|
450
|
+
if (!href || !label || seen.has(href)) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
seen.add(href);
|
|
454
|
+
deduped.push({
|
|
455
|
+
href,
|
|
456
|
+
label,
|
|
457
|
+
...parentHref ? { parentHref } : {}
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
const hrefs = new Set(deduped.map((item) => item.href));
|
|
461
|
+
return deduped.map((item) => ({
|
|
462
|
+
href: item.href,
|
|
463
|
+
label: item.label,
|
|
464
|
+
...item.parentHref && item.parentHref !== item.href && hrefs.has(item.parentHref) ? { parentHref: item.parentHref } : {}
|
|
465
|
+
}));
|
|
466
|
+
};
|
|
467
|
+
var buildNestedNavTree = (items) => {
|
|
468
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
469
|
+
const topLevel = [];
|
|
470
|
+
for (const item of items) {
|
|
471
|
+
if (!item.parentHref) {
|
|
472
|
+
topLevel.push(item);
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const children = childrenByParent.get(item.parentHref) || [];
|
|
476
|
+
children.push(item);
|
|
477
|
+
childrenByParent.set(item.parentHref, children);
|
|
478
|
+
}
|
|
479
|
+
if (topLevel.length === 0 && items.length > 0) {
|
|
480
|
+
return {
|
|
481
|
+
topLevel: items.map((item) => ({ href: item.href, label: item.label })),
|
|
482
|
+
childrenByParent: /* @__PURE__ */ new Map()
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return { childrenByParent, topLevel };
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
// src/admin-app/components/HeaderNavEditorWithPreview.tsx
|
|
489
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
490
|
+
var fallbackNav = [{ href: "/", label: "Home" }];
|
|
491
|
+
function HeaderNavEditorWithPreview({
|
|
492
|
+
brandName,
|
|
493
|
+
initialItems,
|
|
494
|
+
logoUrl,
|
|
495
|
+
pageOptions,
|
|
496
|
+
tagline = ""
|
|
497
|
+
}) {
|
|
498
|
+
const [liveItems, setLiveItems] = (0, import_react3.useState)(initialItems);
|
|
499
|
+
const previewItems = (0, import_react3.useMemo)(() => {
|
|
500
|
+
const normalized = normalizeNestedNavItems(liveItems);
|
|
501
|
+
const tree = buildNestedNavTree(normalized);
|
|
502
|
+
return tree.topLevel.length > 0 ? tree : buildNestedNavTree(fallbackNav);
|
|
503
|
+
}, [liveItems]);
|
|
504
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
505
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HeaderNavItemsEditor, { initialItems, onItemsChange: setLiveItems, pageOptions }),
|
|
506
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { color: "#5d6664", fontSize: "0.88rem", fontWeight: 700 }, children: "Header Preview" }),
|
|
507
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
508
|
+
"div",
|
|
509
|
+
{
|
|
510
|
+
style: {
|
|
511
|
+
border: "1px solid #dce2e0",
|
|
512
|
+
borderRadius: 14,
|
|
513
|
+
overflow: "hidden"
|
|
514
|
+
},
|
|
515
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("header", { className: "site-header", style: { position: "relative", top: "auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "container container-content header-wrap", children: [
|
|
516
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("a", { className: "brand", href: "#", children: [
|
|
517
|
+
logoUrl ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { alt: `${brandName} logo`, src: logoUrl }) : null,
|
|
518
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
|
|
519
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "brand-title", children: brandName }),
|
|
520
|
+
tagline ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "brand-subtitle", children: tagline }) : null
|
|
521
|
+
] })
|
|
522
|
+
] }),
|
|
523
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("nav", { className: "site-nav open", children: previewItems.topLevel.map((item, index) => {
|
|
524
|
+
const children = previewItems.childrenByParent.get(item.href) || [];
|
|
525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
526
|
+
"div",
|
|
527
|
+
{
|
|
528
|
+
className: children.length > 0 ? "site-nav-item has-children" : "site-nav-item",
|
|
529
|
+
children: [
|
|
530
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { className: index === 0 ? "active" : "", href: item.href, children: item.label }),
|
|
531
|
+
children.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "site-subnav", children: children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: child.href, children: child.label }, `${item.href}-${child.href}`)) }) : null
|
|
532
|
+
]
|
|
533
|
+
},
|
|
534
|
+
`${item.href}-${index}`
|
|
535
|
+
);
|
|
536
|
+
}) })
|
|
537
|
+
] }) })
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
] });
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/admin-app/components/MediaDetailPanel.tsx
|
|
544
|
+
var import_react4 = require("react");
|
|
545
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
546
|
+
function formatFileSize(bytes) {
|
|
547
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
548
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
549
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
550
|
+
}
|
|
551
|
+
function MediaDetailPanel({
|
|
552
|
+
id,
|
|
553
|
+
filename,
|
|
554
|
+
alt,
|
|
555
|
+
url,
|
|
556
|
+
filesize,
|
|
557
|
+
width,
|
|
558
|
+
height,
|
|
559
|
+
mimeType,
|
|
560
|
+
createdAt,
|
|
561
|
+
updateAction,
|
|
562
|
+
deleteAction
|
|
563
|
+
}) {
|
|
564
|
+
const [copied, setCopied] = (0, import_react4.useState)(false);
|
|
565
|
+
const [confirmDelete, setConfirmDelete] = (0, import_react4.useState)(false);
|
|
566
|
+
const copyUrl = async () => {
|
|
567
|
+
if (!url) return;
|
|
568
|
+
try {
|
|
569
|
+
await navigator.clipboard.writeText(url);
|
|
570
|
+
setCopied(true);
|
|
571
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
572
|
+
} catch {
|
|
573
|
+
const input = document.createElement("input");
|
|
574
|
+
input.value = url;
|
|
575
|
+
document.body.appendChild(input);
|
|
576
|
+
input.select();
|
|
577
|
+
document.execCommand("copy");
|
|
578
|
+
document.body.removeChild(input);
|
|
579
|
+
setCopied(true);
|
|
580
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
const metaRows = [];
|
|
584
|
+
if (filename) metaRows.push({ label: "Filename", value: filename });
|
|
585
|
+
if (typeof filesize === "number") metaRows.push({ label: "File size", value: formatFileSize(filesize) });
|
|
586
|
+
if (typeof width === "number" && typeof height === "number") metaRows.push({ label: "Dimensions", value: `${width} \xD7 ${height} px` });
|
|
587
|
+
if (mimeType) metaRows.push({ label: "Type", value: mimeType });
|
|
588
|
+
if (createdAt) {
|
|
589
|
+
try {
|
|
590
|
+
metaRows.push({ label: "Uploaded", value: new Date(createdAt).toLocaleDateString() });
|
|
591
|
+
} catch {
|
|
592
|
+
metaRows.push({ label: "Uploaded", value: createdAt });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "orion-admin-grid", style: { alignItems: "start" }, children: [
|
|
596
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
597
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "orion-admin-card", children: url ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { alt: alt || filename || "Media", src: url, style: { borderRadius: 12, width: "100%" } }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "No preview available." }) }),
|
|
598
|
+
url ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
599
|
+
"button",
|
|
600
|
+
{
|
|
601
|
+
className: "orion-admin-action-button",
|
|
602
|
+
onClick: copyUrl,
|
|
603
|
+
style: { marginTop: "0.6rem", width: "100%" },
|
|
604
|
+
type: "button",
|
|
605
|
+
children: copied ? "Copied!" : "Copy URL"
|
|
606
|
+
}
|
|
607
|
+
) : null
|
|
608
|
+
] }),
|
|
609
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "grid", gap: "0.8rem" }, children: [
|
|
610
|
+
metaRows.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "orion-admin-card orion-admin-meta-table", children: metaRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "orion-admin-meta-row", children: [
|
|
611
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "orion-admin-meta-label", children: row.label }),
|
|
612
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "orion-admin-meta-value", children: row.value })
|
|
613
|
+
] }, row.label)) }) : null,
|
|
614
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { action: updateAction, className: "orion-admin-form", children: [
|
|
615
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { name: "id", type: "hidden", value: id }),
|
|
616
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { children: [
|
|
617
|
+
"Alt text",
|
|
618
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { defaultValue: alt || "", name: "alt", required: true, type: "text" })
|
|
619
|
+
] }),
|
|
620
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "submit", children: "Save" })
|
|
621
|
+
] }),
|
|
622
|
+
confirmDelete ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "orion-admin-form", style: { borderColor: "#b42318" }, children: [
|
|
623
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { fontWeight: 700, margin: 0 }, children: "Are you sure you want to delete this asset?" }),
|
|
624
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { color: "var(--orion-admin-muted)", fontSize: "0.9rem", margin: 0 }, children: "This action cannot be undone." }),
|
|
625
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", gap: "0.5rem" }, children: [
|
|
626
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { action: deleteAction, style: { flex: 1 }, children: [
|
|
627
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("input", { name: "id", type: "hidden", value: id }),
|
|
628
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { style: { background: "#b42318", border: 0, borderRadius: 10, color: "#fff", cursor: "pointer", fontWeight: 800, padding: "0.55rem 0.8rem", width: "100%" }, type: "submit", children: "Yes, Delete" })
|
|
629
|
+
] }),
|
|
630
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
631
|
+
"button",
|
|
632
|
+
{
|
|
633
|
+
onClick: () => setConfirmDelete(false),
|
|
634
|
+
style: { background: "transparent", border: "1px solid var(--orion-admin-border)", borderRadius: 10, cursor: "pointer", flex: 1, fontWeight: 700, padding: "0.55rem 0.8rem" },
|
|
635
|
+
type: "button",
|
|
636
|
+
children: "Cancel"
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
] })
|
|
640
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
641
|
+
"button",
|
|
642
|
+
{
|
|
643
|
+
className: "orion-admin-action-button",
|
|
644
|
+
onClick: () => setConfirmDelete(true),
|
|
645
|
+
style: { background: "#b42318" },
|
|
646
|
+
type: "button",
|
|
647
|
+
children: "Delete Asset"
|
|
648
|
+
}
|
|
649
|
+
)
|
|
650
|
+
] })
|
|
651
|
+
] });
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// src/admin-app/components/MediaListItem.tsx
|
|
655
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
656
|
+
function formatFileSize2(bytes) {
|
|
657
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
658
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
659
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
660
|
+
}
|
|
661
|
+
function MediaListItem({
|
|
662
|
+
id,
|
|
663
|
+
filename,
|
|
664
|
+
alt,
|
|
665
|
+
url,
|
|
666
|
+
filesize,
|
|
667
|
+
width,
|
|
668
|
+
height,
|
|
669
|
+
mimeType,
|
|
670
|
+
href
|
|
671
|
+
}) {
|
|
672
|
+
const label = filename || `Media ${id}`;
|
|
673
|
+
const altText = alt || "";
|
|
674
|
+
const metaParts = [];
|
|
675
|
+
if (typeof filesize === "number") metaParts.push(formatFileSize2(filesize));
|
|
676
|
+
if (typeof width === "number" && typeof height === "number") metaParts.push(`${width}\xD7${height}`);
|
|
677
|
+
if (typeof mimeType === "string") metaParts.push(mimeType);
|
|
678
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("a", { className: "orion-admin-list-item", href, children: [
|
|
679
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { alignItems: "center", display: "flex", gap: "0.8rem" }, children: [
|
|
680
|
+
url ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { alt: altText || label, className: "orion-admin-media-preview", src: url }) : null,
|
|
681
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
682
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: label }),
|
|
683
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "orion-admin-list-meta", children: altText || "No alt text" }),
|
|
684
|
+
metaParts.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "orion-admin-list-meta", style: { marginTop: "0.15rem" }, children: metaParts.join(" \xB7 ") }) : null
|
|
685
|
+
] })
|
|
686
|
+
] }),
|
|
687
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "orion-admin-list-meta", children: "Edit" })
|
|
688
|
+
] });
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// src/admin-app/components/MediaUploadForm.tsx
|
|
692
|
+
var import_react5 = require("react");
|
|
693
|
+
var import_navigation = require("next/navigation");
|
|
694
|
+
|
|
695
|
+
// src/shared/clientImageUploadOptimization.ts
|
|
696
|
+
var MAX_DIRECT_UPLOAD_BYTES = 4e6;
|
|
697
|
+
var extensionForMimeType = (mimeType) => {
|
|
698
|
+
switch (mimeType) {
|
|
699
|
+
case "image/webp":
|
|
700
|
+
return ".webp";
|
|
701
|
+
case "image/png":
|
|
702
|
+
return ".png";
|
|
703
|
+
default:
|
|
704
|
+
return ".jpg";
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
var detectCanvasTransparency = (context, width, height) => {
|
|
708
|
+
try {
|
|
709
|
+
const { data } = context.getImageData(0, 0, width, height);
|
|
710
|
+
for (let index = 3; index < data.length; index += 4) {
|
|
711
|
+
if (data[index] < 255) {
|
|
712
|
+
return true;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
} catch {
|
|
716
|
+
}
|
|
717
|
+
return false;
|
|
718
|
+
};
|
|
719
|
+
var resolveOutputMimeTypes = (sourceMime, hasTransparency) => {
|
|
720
|
+
const candidates = [];
|
|
721
|
+
if (hasTransparency) {
|
|
722
|
+
candidates.push("image/webp", "image/png");
|
|
723
|
+
} else if (sourceMime === "image/webp") {
|
|
724
|
+
candidates.push("image/webp", "image/jpeg");
|
|
725
|
+
} else if (sourceMime === "image/png") {
|
|
726
|
+
candidates.push("image/webp", "image/jpeg", "image/png");
|
|
727
|
+
} else {
|
|
728
|
+
candidates.push("image/jpeg", "image/webp");
|
|
729
|
+
}
|
|
730
|
+
return [...new Set(candidates)];
|
|
731
|
+
};
|
|
732
|
+
async function optimizeImageForUpload(file) {
|
|
733
|
+
if (!file.type.startsWith("image/")) {
|
|
734
|
+
return file;
|
|
735
|
+
}
|
|
736
|
+
const objectURL = URL.createObjectURL(file);
|
|
737
|
+
try {
|
|
738
|
+
const image = await new Promise((resolve, reject) => {
|
|
739
|
+
const nextImage = new Image();
|
|
740
|
+
nextImage.onload = () => resolve(nextImage);
|
|
741
|
+
nextImage.onerror = () => reject(new Error("Could not read image for upload optimization."));
|
|
742
|
+
nextImage.src = objectURL;
|
|
743
|
+
});
|
|
744
|
+
const canvas = document.createElement("canvas");
|
|
745
|
+
canvas.width = Math.max(1, image.width);
|
|
746
|
+
canvas.height = Math.max(1, image.height);
|
|
747
|
+
const context = canvas.getContext("2d");
|
|
748
|
+
if (!context) {
|
|
749
|
+
return file;
|
|
750
|
+
}
|
|
751
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
752
|
+
const sourceMime = file.type.toLowerCase();
|
|
753
|
+
const hasTransparency = detectCanvasTransparency(context, canvas.width, canvas.height);
|
|
754
|
+
const outputMimes = resolveOutputMimeTypes(sourceMime, hasTransparency);
|
|
755
|
+
const qualityPasses = [0.82, 0.74, 0.66, 0.58, 0.5, 0.42, 0.36, 0.3, 0.26];
|
|
756
|
+
let bestFile = null;
|
|
757
|
+
for (const outputMime of outputMimes) {
|
|
758
|
+
const passes = outputMime === "image/png" ? [void 0] : qualityPasses;
|
|
759
|
+
for (const quality of passes) {
|
|
760
|
+
const blob = await new Promise((resolve) => {
|
|
761
|
+
canvas.toBlob((value) => resolve(value), outputMime, quality);
|
|
762
|
+
});
|
|
763
|
+
if (!blob) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
const optimizedName = file.name.replace(/\.[^/.]+$/, extensionForMimeType(outputMime));
|
|
767
|
+
const optimized = new File([blob], optimizedName, {
|
|
768
|
+
lastModified: Date.now(),
|
|
769
|
+
type: outputMime
|
|
770
|
+
});
|
|
771
|
+
if (!bestFile || optimized.size < bestFile.size) {
|
|
772
|
+
bestFile = optimized;
|
|
773
|
+
}
|
|
774
|
+
if (optimized.size <= MAX_DIRECT_UPLOAD_BYTES) {
|
|
775
|
+
break;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (!bestFile) {
|
|
780
|
+
return file;
|
|
781
|
+
}
|
|
782
|
+
return bestFile.size < file.size ? bestFile : file;
|
|
783
|
+
} finally {
|
|
784
|
+
URL.revokeObjectURL(objectURL);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/admin-app/components/MediaUploadForm.tsx
|
|
789
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
790
|
+
var MEDIA_LIBRARY_SYNC_EVENT = "orion-media-library-updated";
|
|
791
|
+
var notifyMediaLibraryUpdated = () => {
|
|
792
|
+
if (typeof window === "undefined") {
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
const updatedAt = Date.now().toString();
|
|
796
|
+
window.dispatchEvent(
|
|
797
|
+
new CustomEvent(MEDIA_LIBRARY_SYNC_EVENT, {
|
|
798
|
+
detail: {
|
|
799
|
+
updatedAt
|
|
800
|
+
}
|
|
801
|
+
})
|
|
802
|
+
);
|
|
803
|
+
try {
|
|
804
|
+
window.localStorage.setItem(MEDIA_LIBRARY_SYNC_EVENT, updatedAt);
|
|
805
|
+
} catch {
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
var parseUploadError = async (response) => {
|
|
809
|
+
const fallback = "Upload failed. Please check the image and required fields, then try again.";
|
|
810
|
+
try {
|
|
811
|
+
const body = await response.json();
|
|
812
|
+
const nestedMessage = body.errors?.[0]?.data?.errors?.[0]?.message;
|
|
813
|
+
if (typeof nestedMessage === "string" && nestedMessage.trim().length > 0) {
|
|
814
|
+
return nestedMessage;
|
|
815
|
+
}
|
|
816
|
+
const topMessage = body.errors?.[0]?.message;
|
|
817
|
+
if (typeof topMessage === "string" && topMessage.trim().length > 0) {
|
|
818
|
+
return topMessage;
|
|
819
|
+
}
|
|
820
|
+
if (typeof body.message === "string" && body.message.trim().length > 0) {
|
|
821
|
+
return body.message;
|
|
822
|
+
}
|
|
823
|
+
} catch {
|
|
824
|
+
}
|
|
825
|
+
return fallback;
|
|
826
|
+
};
|
|
827
|
+
function MediaUploadForm() {
|
|
828
|
+
const router = (0, import_navigation.useRouter)();
|
|
829
|
+
const fileInputRef = (0, import_react5.useRef)(null);
|
|
830
|
+
const [alt, setAlt] = (0, import_react5.useState)("");
|
|
831
|
+
const [file, setFile] = (0, import_react5.useState)(null);
|
|
832
|
+
const [preview, setPreview] = (0, import_react5.useState)(null);
|
|
833
|
+
const [dragging, setDragging] = (0, import_react5.useState)(false);
|
|
834
|
+
const [submitting, setSubmitting] = (0, import_react5.useState)(false);
|
|
835
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
836
|
+
const handleFile = (0, import_react5.useCallback)((selectedFile) => {
|
|
837
|
+
setFile(selectedFile);
|
|
838
|
+
if (preview) {
|
|
839
|
+
URL.revokeObjectURL(preview);
|
|
840
|
+
setPreview(null);
|
|
841
|
+
}
|
|
842
|
+
if (selectedFile && selectedFile.type.startsWith("image/")) {
|
|
843
|
+
setPreview(URL.createObjectURL(selectedFile));
|
|
844
|
+
}
|
|
845
|
+
}, [preview]);
|
|
846
|
+
const onDragOver = (0, import_react5.useCallback)((e) => {
|
|
847
|
+
e.preventDefault();
|
|
848
|
+
setDragging(true);
|
|
849
|
+
}, []);
|
|
850
|
+
const onDragLeave = (0, import_react5.useCallback)((e) => {
|
|
851
|
+
e.preventDefault();
|
|
852
|
+
setDragging(false);
|
|
853
|
+
}, []);
|
|
854
|
+
const onDrop = (0, import_react5.useCallback)((e) => {
|
|
855
|
+
e.preventDefault();
|
|
856
|
+
setDragging(false);
|
|
857
|
+
const droppedFile = e.dataTransfer.files?.[0] || null;
|
|
858
|
+
if (droppedFile) {
|
|
859
|
+
handleFile(droppedFile);
|
|
860
|
+
}
|
|
861
|
+
}, [handleFile]);
|
|
862
|
+
const upload = async (event) => {
|
|
863
|
+
event.preventDefault();
|
|
864
|
+
if (!file) {
|
|
865
|
+
setError("Select an image to upload.");
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
setSubmitting(true);
|
|
869
|
+
setError(null);
|
|
870
|
+
try {
|
|
871
|
+
const optimizedFile = await optimizeImageForUpload(file);
|
|
872
|
+
if (optimizedFile.size > MAX_DIRECT_UPLOAD_BYTES) {
|
|
873
|
+
throw new Error("Image is too large. Use an image under 4MB or lower-resolution export.");
|
|
874
|
+
}
|
|
875
|
+
const formData = new FormData();
|
|
876
|
+
const fallbackAlt = file.name.replace(/\.[^/.]+$/, "").trim();
|
|
877
|
+
const resolvedAlt = alt.trim() || fallbackAlt || "Uploaded image";
|
|
878
|
+
formData.set("_payload", JSON.stringify({ alt: resolvedAlt }));
|
|
879
|
+
formData.set("alt", resolvedAlt);
|
|
880
|
+
formData.set("file", optimizedFile);
|
|
881
|
+
const response = await fetch("/api/media", {
|
|
882
|
+
method: "POST",
|
|
883
|
+
credentials: "include",
|
|
884
|
+
body: formData
|
|
885
|
+
});
|
|
886
|
+
if (!response.ok) {
|
|
887
|
+
throw new Error(await parseUploadError(response));
|
|
888
|
+
}
|
|
889
|
+
setAlt("");
|
|
890
|
+
setFile(null);
|
|
891
|
+
if (preview) {
|
|
892
|
+
URL.revokeObjectURL(preview);
|
|
893
|
+
setPreview(null);
|
|
894
|
+
}
|
|
895
|
+
notifyMediaLibraryUpdated();
|
|
896
|
+
router.refresh();
|
|
897
|
+
} catch (err) {
|
|
898
|
+
setError(err instanceof Error ? err.message : "Upload failed");
|
|
899
|
+
} finally {
|
|
900
|
+
setSubmitting(false);
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { className: "orion-admin-upload-form", onSubmit: upload, children: [
|
|
904
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { children: [
|
|
905
|
+
"Alt text",
|
|
906
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
907
|
+
"input",
|
|
908
|
+
{
|
|
909
|
+
onChange: (event) => setAlt(event.target.value),
|
|
910
|
+
placeholder: "Describe the image",
|
|
911
|
+
type: "text",
|
|
912
|
+
value: alt
|
|
913
|
+
}
|
|
914
|
+
)
|
|
915
|
+
] }),
|
|
916
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
917
|
+
"div",
|
|
918
|
+
{
|
|
919
|
+
className: `orion-admin-dropzone${dragging ? " is-dragging" : ""}${file ? " has-file" : ""}`,
|
|
920
|
+
onClick: () => fileInputRef.current?.click(),
|
|
921
|
+
onDragLeave,
|
|
922
|
+
onDragOver,
|
|
923
|
+
onDrop,
|
|
924
|
+
children: [
|
|
925
|
+
preview ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "orion-admin-dropzone-preview", children: [
|
|
926
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("img", { alt: "Upload preview", src: preview }),
|
|
927
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: file?.name })
|
|
928
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "orion-admin-dropzone-label", children: [
|
|
929
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("strong", { children: "Drop an image here" }),
|
|
930
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "or click to browse" })
|
|
931
|
+
] }),
|
|
932
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
933
|
+
"input",
|
|
934
|
+
{
|
|
935
|
+
accept: "image/*",
|
|
936
|
+
onChange: (event) => handleFile(event.target.files?.[0] || null),
|
|
937
|
+
ref: fileInputRef,
|
|
938
|
+
style: { display: "none" },
|
|
939
|
+
type: "file"
|
|
940
|
+
}
|
|
941
|
+
)
|
|
942
|
+
]
|
|
943
|
+
}
|
|
944
|
+
),
|
|
945
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "orion-admin-upload-error", children: error }) : null,
|
|
946
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { disabled: submitting, type: "submit", children: submitting ? "Uploading..." : "Upload" })
|
|
947
|
+
] });
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/admin-app/components/PageEditorFrame.tsx
|
|
951
|
+
var import_react6 = require("react");
|
|
952
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
953
|
+
var extractPageIDFromBuilderSrc = (value) => {
|
|
954
|
+
if (!value || typeof value !== "string") {
|
|
955
|
+
return null;
|
|
956
|
+
}
|
|
957
|
+
try {
|
|
958
|
+
const url = new URL(value, "http://localhost");
|
|
959
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
960
|
+
return segments.length > 0 ? segments[segments.length - 1] || null : null;
|
|
961
|
+
} catch {
|
|
962
|
+
return null;
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
function PageEditorFrame({ src }) {
|
|
966
|
+
const iframeRef = (0, import_react6.useRef)(null);
|
|
967
|
+
const dirtyCheckTimerRef = (0, import_react6.useRef)(null);
|
|
968
|
+
const [saving, setSaving] = (0, import_react6.useState)(null);
|
|
969
|
+
const [message, setMessage] = (0, import_react6.useState)("");
|
|
970
|
+
const [error, setError] = (0, import_react6.useState)("");
|
|
971
|
+
const [hasUnsavedChanges, setHasUnsavedChanges] = (0, import_react6.useState)(false);
|
|
972
|
+
const [awaitingDirtyCheck, setAwaitingDirtyCheck] = (0, import_react6.useState)(false);
|
|
973
|
+
const [pendingNavigationURL, setPendingNavigationURL] = (0, import_react6.useState)(null);
|
|
974
|
+
const [showUnsavedDialog, setShowUnsavedDialog] = (0, import_react6.useState)(false);
|
|
975
|
+
const [canUndo, setCanUndo] = (0, import_react6.useState)(false);
|
|
976
|
+
const [canRedo, setCanRedo] = (0, import_react6.useState)(false);
|
|
977
|
+
const [sessionExpired, setSessionExpired] = (0, import_react6.useState)(false);
|
|
978
|
+
const [hasUnpublishedChanges, setHasUnpublishedChanges] = (0, import_react6.useState)(false);
|
|
979
|
+
const pageID = extractPageIDFromBuilderSrc(src);
|
|
980
|
+
const refreshUnpublishedChanges = async () => {
|
|
981
|
+
if (!pageID) {
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
try {
|
|
985
|
+
const response = await fetch(
|
|
986
|
+
`/api/pages/versions?depth=0&limit=25&sort=-updatedAt&where[parent][equals]=${encodeURIComponent(pageID)}`,
|
|
987
|
+
{
|
|
988
|
+
credentials: "include"
|
|
989
|
+
}
|
|
990
|
+
);
|
|
991
|
+
if (!response.ok) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
const payload = await response.json();
|
|
995
|
+
const docs = Array.isArray(payload.docs) ? payload.docs : [];
|
|
996
|
+
let latestDraft = 0;
|
|
997
|
+
let latestPublished = 0;
|
|
998
|
+
docs.forEach((doc) => {
|
|
999
|
+
const status = doc.version?._status;
|
|
1000
|
+
const millis = typeof doc.updatedAt === "string" ? Date.parse(doc.updatedAt) : Number.NaN;
|
|
1001
|
+
if (!Number.isFinite(millis)) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
if (status === "draft") {
|
|
1005
|
+
latestDraft = Math.max(latestDraft, millis);
|
|
1006
|
+
} else if (status === "published") {
|
|
1007
|
+
latestPublished = Math.max(latestPublished, millis);
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
setHasUnpublishedChanges(latestDraft > 0 && latestDraft >= latestPublished);
|
|
1011
|
+
} catch {
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
const clearDirtyCheckTimer = () => {
|
|
1015
|
+
if (dirtyCheckTimerRef.current) {
|
|
1016
|
+
window.clearTimeout(dirtyCheckTimerRef.current);
|
|
1017
|
+
dirtyCheckTimerRef.current = null;
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
const continueNavigation = (nextURL) => {
|
|
1021
|
+
setPendingNavigationURL(null);
|
|
1022
|
+
setShowUnsavedDialog(false);
|
|
1023
|
+
setAwaitingDirtyCheck(false);
|
|
1024
|
+
clearDirtyCheckTimer();
|
|
1025
|
+
window.location.assign(nextURL);
|
|
1026
|
+
};
|
|
1027
|
+
const sendSave = (status) => {
|
|
1028
|
+
const iframe = iframeRef.current;
|
|
1029
|
+
if (!iframe?.contentWindow) {
|
|
1030
|
+
setError("Editor is still loading. Try again in a moment.");
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
setSaving(status);
|
|
1034
|
+
setError("");
|
|
1035
|
+
setMessage("");
|
|
1036
|
+
iframe.contentWindow.postMessage(
|
|
1037
|
+
{
|
|
1038
|
+
source: "payload-visual-builder-parent",
|
|
1039
|
+
type: "save",
|
|
1040
|
+
status
|
|
1041
|
+
},
|
|
1042
|
+
"*"
|
|
1043
|
+
);
|
|
1044
|
+
};
|
|
1045
|
+
const sendHistory = (type) => {
|
|
1046
|
+
const iframe = iframeRef.current;
|
|
1047
|
+
if (!iframe?.contentWindow) {
|
|
1048
|
+
setError("Editor is still loading. Try again in a moment.");
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
iframe.contentWindow.postMessage(
|
|
1052
|
+
{
|
|
1053
|
+
source: "payload-visual-builder-parent",
|
|
1054
|
+
type
|
|
1055
|
+
},
|
|
1056
|
+
"*"
|
|
1057
|
+
);
|
|
1058
|
+
};
|
|
1059
|
+
(0, import_react6.useEffect)(() => {
|
|
1060
|
+
const onMessage = (event) => {
|
|
1061
|
+
const data = event.data;
|
|
1062
|
+
if (!data || data.source !== "payload-visual-builder-child") {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (data.type === "dirty-state") {
|
|
1066
|
+
const dirty = Boolean(data.dirty);
|
|
1067
|
+
setHasUnsavedChanges(dirty);
|
|
1068
|
+
if (awaitingDirtyCheck && pendingNavigationURL) {
|
|
1069
|
+
clearDirtyCheckTimer();
|
|
1070
|
+
setAwaitingDirtyCheck(false);
|
|
1071
|
+
if (dirty) {
|
|
1072
|
+
setShowUnsavedDialog(true);
|
|
1073
|
+
} else {
|
|
1074
|
+
continueNavigation(pendingNavigationURL);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
if (data.type === "history-state") {
|
|
1080
|
+
setCanUndo(Boolean(data.canUndo));
|
|
1081
|
+
setCanRedo(Boolean(data.canRedo));
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
if (data.type === "session-expired") {
|
|
1085
|
+
setSessionExpired(true);
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
if (data.type !== "save-result") {
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
setSaving(null);
|
|
1092
|
+
if (data.ok) {
|
|
1093
|
+
if (data.status === "draft") {
|
|
1094
|
+
setHasUnpublishedChanges(true);
|
|
1095
|
+
} else if (data.status === "published") {
|
|
1096
|
+
setHasUnpublishedChanges(false);
|
|
1097
|
+
} else {
|
|
1098
|
+
void refreshUnpublishedChanges();
|
|
1099
|
+
}
|
|
1100
|
+
setMessage(typeof data.message === "string" ? data.message : "Saved.");
|
|
1101
|
+
setError("");
|
|
1102
|
+
setHasUnsavedChanges(false);
|
|
1103
|
+
} else {
|
|
1104
|
+
setError(typeof data.message === "string" ? data.message : "Could not save changes.");
|
|
1105
|
+
setMessage("");
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
window.addEventListener("message", onMessage);
|
|
1109
|
+
return () => window.removeEventListener("message", onMessage);
|
|
1110
|
+
}, [awaitingDirtyCheck, pendingNavigationURL]);
|
|
1111
|
+
(0, import_react6.useEffect)(() => {
|
|
1112
|
+
void refreshUnpublishedChanges();
|
|
1113
|
+
}, [pageID]);
|
|
1114
|
+
(0, import_react6.useEffect)(() => {
|
|
1115
|
+
const onDocumentClick = (event) => {
|
|
1116
|
+
if (!hasUnsavedChanges) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
const target = event.target;
|
|
1120
|
+
if (target?.closest('[data-orion-unsaved-dialog="true"]')) {
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
const link = target?.closest("a[href]");
|
|
1124
|
+
if (!link) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
if (link.target && link.target !== "_self") {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
const href = link.getAttribute("href");
|
|
1134
|
+
if (!href || href.startsWith("#") || href.startsWith("mailto:") || href.startsWith("tel:")) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
const destination = new URL(href, window.location.href);
|
|
1138
|
+
const current = new URL(window.location.href);
|
|
1139
|
+
const isSameDestination = destination.pathname === current.pathname && destination.search === current.search && destination.hash === current.hash;
|
|
1140
|
+
if (destination.origin !== current.origin || isSameDestination) {
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
event.preventDefault();
|
|
1144
|
+
const nextURL = `${destination.pathname}${destination.search}${destination.hash}`;
|
|
1145
|
+
setPendingNavigationURL(nextURL);
|
|
1146
|
+
const iframe = iframeRef.current;
|
|
1147
|
+
if (!iframe?.contentWindow) {
|
|
1148
|
+
if (hasUnsavedChanges) {
|
|
1149
|
+
setShowUnsavedDialog(true);
|
|
1150
|
+
} else {
|
|
1151
|
+
continueNavigation(nextURL);
|
|
1152
|
+
}
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
setAwaitingDirtyCheck(true);
|
|
1156
|
+
setShowUnsavedDialog(false);
|
|
1157
|
+
clearDirtyCheckTimer();
|
|
1158
|
+
iframe.contentWindow.postMessage(
|
|
1159
|
+
{
|
|
1160
|
+
source: "payload-visual-builder-parent",
|
|
1161
|
+
type: "dirty-check-request"
|
|
1162
|
+
},
|
|
1163
|
+
"*"
|
|
1164
|
+
);
|
|
1165
|
+
dirtyCheckTimerRef.current = window.setTimeout(() => {
|
|
1166
|
+
setAwaitingDirtyCheck(false);
|
|
1167
|
+
if (hasUnsavedChanges) {
|
|
1168
|
+
setShowUnsavedDialog(true);
|
|
1169
|
+
} else {
|
|
1170
|
+
continueNavigation(nextURL);
|
|
1171
|
+
}
|
|
1172
|
+
}, 250);
|
|
1173
|
+
};
|
|
1174
|
+
document.addEventListener("click", onDocumentClick, true);
|
|
1175
|
+
return () => document.removeEventListener("click", onDocumentClick, true);
|
|
1176
|
+
}, [hasUnsavedChanges]);
|
|
1177
|
+
(0, import_react6.useEffect)(() => {
|
|
1178
|
+
if (!hasUnsavedChanges) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
const onBeforeUnload = (event) => {
|
|
1182
|
+
event.preventDefault();
|
|
1183
|
+
event.returnValue = "";
|
|
1184
|
+
};
|
|
1185
|
+
window.addEventListener("beforeunload", onBeforeUnload);
|
|
1186
|
+
return () => window.removeEventListener("beforeunload", onBeforeUnload);
|
|
1187
|
+
}, [hasUnsavedChanges]);
|
|
1188
|
+
(0, import_react6.useEffect)(
|
|
1189
|
+
() => () => {
|
|
1190
|
+
clearDirtyCheckTimer();
|
|
1191
|
+
},
|
|
1192
|
+
[]
|
|
1193
|
+
);
|
|
1194
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", gap: "0.8rem" }, children: [
|
|
1195
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1196
|
+
"div",
|
|
1197
|
+
{
|
|
1198
|
+
style: {
|
|
1199
|
+
alignItems: "center",
|
|
1200
|
+
background: "var(--orion-admin-card-bg)",
|
|
1201
|
+
border: "1px solid var(--orion-admin-card-border)",
|
|
1202
|
+
borderRadius: 12,
|
|
1203
|
+
display: "flex",
|
|
1204
|
+
flexWrap: "wrap",
|
|
1205
|
+
gap: "0.6rem",
|
|
1206
|
+
justifyContent: "space-between",
|
|
1207
|
+
padding: "0.7rem 0.8rem"
|
|
1208
|
+
},
|
|
1209
|
+
children: [
|
|
1210
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", gap: "0.2rem" }, children: [
|
|
1211
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { color: "var(--orion-admin-muted)", fontSize: "0.9rem" }, children: "Save changes to update the page layout and content." }),
|
|
1212
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1213
|
+
"div",
|
|
1214
|
+
{
|
|
1215
|
+
style: {
|
|
1216
|
+
alignItems: "center",
|
|
1217
|
+
background: hasUnpublishedChanges ? "#fff3cd" : "#e7f7ee",
|
|
1218
|
+
border: `1px solid ${hasUnpublishedChanges ? "#f0c36d" : "#87c79e"}`,
|
|
1219
|
+
borderRadius: 999,
|
|
1220
|
+
color: hasUnpublishedChanges ? "#6a4a00" : "#0e5a2a",
|
|
1221
|
+
display: "inline-flex",
|
|
1222
|
+
fontSize: "0.75rem",
|
|
1223
|
+
fontWeight: 800,
|
|
1224
|
+
padding: "0.2rem 0.55rem",
|
|
1225
|
+
width: "fit-content"
|
|
1226
|
+
},
|
|
1227
|
+
title: hasUnpublishedChanges ? "This page has saved draft changes not published yet." : "The live page matches the latest published version.",
|
|
1228
|
+
children: hasUnpublishedChanges ? "Unpublished draft changes" : "Live is up to date"
|
|
1229
|
+
}
|
|
1230
|
+
)
|
|
1231
|
+
] }),
|
|
1232
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { alignItems: "center", display: "flex", flexWrap: "wrap", gap: "0.5rem" }, children: [
|
|
1233
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1234
|
+
"button",
|
|
1235
|
+
{
|
|
1236
|
+
className: "orion-admin-action-button",
|
|
1237
|
+
disabled: !canUndo,
|
|
1238
|
+
onClick: () => sendHistory("undo"),
|
|
1239
|
+
style: { background: "transparent", border: "1px solid var(--orion-admin-card-border)", color: "var(--orion-admin-text)" },
|
|
1240
|
+
type: "button",
|
|
1241
|
+
children: "Undo"
|
|
1242
|
+
}
|
|
1243
|
+
),
|
|
1244
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1245
|
+
"button",
|
|
1246
|
+
{
|
|
1247
|
+
className: "orion-admin-action-button",
|
|
1248
|
+
disabled: !canRedo,
|
|
1249
|
+
onClick: () => sendHistory("redo"),
|
|
1250
|
+
style: { background: "transparent", border: "1px solid var(--orion-admin-card-border)", color: "var(--orion-admin-text)" },
|
|
1251
|
+
type: "button",
|
|
1252
|
+
children: "Redo"
|
|
1253
|
+
}
|
|
1254
|
+
),
|
|
1255
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1256
|
+
"button",
|
|
1257
|
+
{
|
|
1258
|
+
className: "orion-admin-action-button",
|
|
1259
|
+
disabled: saving !== null,
|
|
1260
|
+
onClick: () => sendSave("draft"),
|
|
1261
|
+
type: "button",
|
|
1262
|
+
children: saving === "draft" ? "Saving..." : "Save Draft"
|
|
1263
|
+
}
|
|
1264
|
+
),
|
|
1265
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1266
|
+
"button",
|
|
1267
|
+
{
|
|
1268
|
+
className: "orion-admin-action-button",
|
|
1269
|
+
disabled: saving !== null,
|
|
1270
|
+
onClick: () => sendSave("published"),
|
|
1271
|
+
style: { background: "#0f7d52" },
|
|
1272
|
+
type: "button",
|
|
1273
|
+
children: saving === "published" ? "Publishing..." : "Publish"
|
|
1274
|
+
}
|
|
1275
|
+
)
|
|
1276
|
+
] })
|
|
1277
|
+
]
|
|
1278
|
+
}
|
|
1279
|
+
),
|
|
1280
|
+
message ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { color: "#0f7d52", fontSize: "0.9rem", fontWeight: 700 }, children: message }) : null,
|
|
1281
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "orion-admin-error", children: error }) : null,
|
|
1282
|
+
sessionExpired ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1283
|
+
"div",
|
|
1284
|
+
{
|
|
1285
|
+
style: {
|
|
1286
|
+
background: "#fef2f2",
|
|
1287
|
+
borderLeft: "4px solid #8d1d1d",
|
|
1288
|
+
borderRadius: 8,
|
|
1289
|
+
color: "#8d1d1d",
|
|
1290
|
+
fontSize: "0.9rem",
|
|
1291
|
+
fontWeight: 600,
|
|
1292
|
+
padding: "0.6rem 0.8rem"
|
|
1293
|
+
},
|
|
1294
|
+
children: "Session expired. Log in again in a new tab, then save your changes."
|
|
1295
|
+
}
|
|
1296
|
+
) : null,
|
|
1297
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1298
|
+
"iframe",
|
|
1299
|
+
{
|
|
1300
|
+
ref: iframeRef,
|
|
1301
|
+
src,
|
|
1302
|
+
style: {
|
|
1303
|
+
border: "1px solid var(--orion-admin-card-border)",
|
|
1304
|
+
borderRadius: 12,
|
|
1305
|
+
height: "calc(100vh - 280px)",
|
|
1306
|
+
width: "100%"
|
|
1307
|
+
},
|
|
1308
|
+
title: "Page Builder",
|
|
1309
|
+
onLoad: () => {
|
|
1310
|
+
const iframe = iframeRef.current;
|
|
1311
|
+
if (!iframe?.contentWindow) return;
|
|
1312
|
+
iframe.contentWindow.postMessage({ source: "payload-visual-builder-parent", type: "dirty-check-request" }, "*");
|
|
1313
|
+
iframe.contentWindow.postMessage({ source: "payload-visual-builder-parent", type: "history-check-request" }, "*");
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
),
|
|
1317
|
+
pendingNavigationURL && showUnsavedDialog ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1318
|
+
"div",
|
|
1319
|
+
{
|
|
1320
|
+
"data-orion-unsaved-dialog": "true",
|
|
1321
|
+
style: {
|
|
1322
|
+
alignItems: "center",
|
|
1323
|
+
background: "rgba(0, 0, 0, 0.35)",
|
|
1324
|
+
display: "grid",
|
|
1325
|
+
inset: 0,
|
|
1326
|
+
justifyItems: "center",
|
|
1327
|
+
padding: "1rem",
|
|
1328
|
+
position: "fixed",
|
|
1329
|
+
zIndex: 2e3
|
|
1330
|
+
},
|
|
1331
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1332
|
+
"div",
|
|
1333
|
+
{
|
|
1334
|
+
style: {
|
|
1335
|
+
background: "#ffffff",
|
|
1336
|
+
border: "1px solid var(--orion-admin-card-border)",
|
|
1337
|
+
borderRadius: 14,
|
|
1338
|
+
boxShadow: "0 20px 42px rgba(13, 74, 55, 0.28)",
|
|
1339
|
+
display: "grid",
|
|
1340
|
+
gap: "0.9rem",
|
|
1341
|
+
maxWidth: 420,
|
|
1342
|
+
padding: "1rem",
|
|
1343
|
+
width: "100%"
|
|
1344
|
+
},
|
|
1345
|
+
children: [
|
|
1346
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1347
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { color: "var(--orion-admin-text)", fontSize: "1rem", fontWeight: 700 }, children: "Unsaved changes" }),
|
|
1348
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { color: "var(--orion-admin-muted)", fontSize: "0.9rem", marginTop: "0.4rem" }, children: "You have unsaved edits in the page builder. Save before leaving this page?" })
|
|
1349
|
+
] }),
|
|
1350
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "flex", gap: "0.6rem", justifyContent: "flex-end" }, children: [
|
|
1351
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1352
|
+
"button",
|
|
1353
|
+
{
|
|
1354
|
+
className: "orion-admin-action-button",
|
|
1355
|
+
onClick: () => {
|
|
1356
|
+
setPendingNavigationURL(null);
|
|
1357
|
+
setShowUnsavedDialog(false);
|
|
1358
|
+
},
|
|
1359
|
+
type: "button",
|
|
1360
|
+
children: "Stay"
|
|
1361
|
+
}
|
|
1362
|
+
),
|
|
1363
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1364
|
+
"button",
|
|
1365
|
+
{
|
|
1366
|
+
className: "orion-admin-action-button",
|
|
1367
|
+
onClick: () => {
|
|
1368
|
+
const next = pendingNavigationURL;
|
|
1369
|
+
if (next) {
|
|
1370
|
+
continueNavigation(next);
|
|
1371
|
+
}
|
|
1372
|
+
},
|
|
1373
|
+
style: { background: "#8d1d1d" },
|
|
1374
|
+
type: "button",
|
|
1375
|
+
children: "Leave Without Saving"
|
|
1376
|
+
}
|
|
1377
|
+
)
|
|
1378
|
+
] })
|
|
1379
|
+
]
|
|
1380
|
+
}
|
|
1381
|
+
)
|
|
1382
|
+
}
|
|
1383
|
+
) : null
|
|
1384
|
+
] });
|
|
1385
|
+
}
|
|
133
1386
|
// Annotate the CommonJS export names for ESM import in node:
|
|
134
1387
|
0 && (module.exports = {
|
|
135
|
-
AdminShellClient
|
|
1388
|
+
AdminShellClient,
|
|
1389
|
+
HeaderNavEditorWithPreview,
|
|
1390
|
+
HeaderNavItemsEditor,
|
|
1391
|
+
MediaDetailPanel,
|
|
1392
|
+
MediaListItem,
|
|
1393
|
+
MediaUploadForm,
|
|
1394
|
+
PageEditorFrame
|
|
136
1395
|
});
|