@orion-studios/payload-studio 0.5.0-beta.11 → 0.5.0-beta.111
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 +54 -0
- package/dist/admin/client.d.mts +3 -0
- package/dist/admin/client.d.ts +3 -0
- package/dist/admin/client.js +1745 -200
- package/dist/admin/client.mjs +1756 -214
- package/dist/admin/index.d.mts +2 -1
- package/dist/admin/index.d.ts +2 -1
- package/dist/admin/index.js +424 -11
- package/dist/admin/index.mjs +19 -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 +1270 -3
- package/dist/admin-app/client.mjs +1172 -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 +247 -0
- package/dist/admin.css +8 -0
- package/dist/blocks/index.js +1011 -191
- package/dist/blocks/index.mjs +2 -2
- package/dist/chunk-ADIIWIYL.mjs +322 -0
- package/dist/{chunk-ZLLNO5FM.mjs → chunk-BET2YLAS.mjs} +104 -15
- package/dist/chunk-DAIZDGHL.mjs +614 -0
- package/dist/chunk-GKMBYYXF.mjs +776 -0
- package/dist/chunk-JQAHXYAM.mjs +1829 -0
- package/dist/chunk-OQSEJXC4.mjs +166 -0
- package/dist/chunk-PF3EBZXF.mjs +326 -0
- package/dist/chunk-ROTPP5CU.mjs +99 -0
- package/dist/chunk-XVH5SCBD.mjs +234 -0
- package/dist/chunk-ZTXJG4K5.mjs +85 -0
- package/dist/index-7lxTrxSG.d.mts +128 -0
- package/dist/index-7lxTrxSG.d.ts +128 -0
- package/dist/index-B7QvY3yF.d.mts +245 -0
- package/dist/index-BK03FiEM.d.ts +245 -0
- package/dist/{index-CmR6NInu.d.ts → index-BzKOThsI.d.mts} +30 -3
- package/dist/{index-CmR6NInu.d.mts → index-BzKOThsI.d.ts} +30 -3
- package/dist/{index-DbH0Ljwp.d.mts → index-D8BNfUJb.d.mts} +17 -2
- package/dist/{index-DbH0Ljwp.d.ts → index-DD_E2UfJ.d.ts} +17 -2
- package/dist/index-DUi_XND6.d.ts +193 -0
- package/dist/index-gLl_358v.d.mts +193 -0
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +2876 -460
- package/dist/index.mjs +12 -10
- package/dist/nextjs/index.d.mts +2 -1
- package/dist/nextjs/index.d.ts +2 -1
- package/dist/nextjs/index.js +497 -16
- package/dist/nextjs/index.mjs +8 -3
- package/dist/socialMedia-C05Iy-SV.d.mts +21 -0
- package/dist/socialMedia-C05Iy-SV.d.ts +21 -0
- package/dist/studio/index.d.mts +2 -1
- package/dist/studio/index.d.ts +2 -1
- package/dist/studio/index.js +171 -5
- package/dist/studio/index.mjs +7 -3
- package/dist/studio-pages/builder.css +517 -32
- package/dist/studio-pages/client.d.mts +75 -1
- package/dist/studio-pages/client.d.ts +75 -1
- package/dist/studio-pages/client.js +5662 -2759
- package/dist/studio-pages/client.mjs +5578 -2767
- package/dist/studio-pages/index.d.mts +4 -2
- package/dist/studio-pages/index.d.ts +4 -2
- package/dist/studio-pages/index.js +859 -71
- package/dist/studio-pages/index.mjs +10 -4
- package/package.json +35 -13
- package/dist/chunk-AAOHJDNS.mjs +0 -67
- package/dist/chunk-ETRRXURT.mjs +0 -141
- package/dist/chunk-J7W5EE3B.mjs +0 -278
- package/dist/chunk-N67KVM2S.mjs +0 -156
- package/dist/chunk-NESLJZFE.mjs +0 -303
- package/dist/chunk-U5BSPWAD.mjs +0 -1034
- 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-DJFhANvJ.d.mts +0 -128
- package/dist/index-DJFhANvJ.d.ts +0 -128
- package/dist/index-g8tBHLKD.d.ts +0 -39
package/dist/blocks/index.mjs
CHANGED
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
defaultPageLayoutBlocks,
|
|
18
18
|
sectionPresets,
|
|
19
19
|
templateStarterPresets
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import "../chunk-
|
|
20
|
+
} from "../chunk-JQAHXYAM.mjs";
|
|
21
|
+
import "../chunk-OQSEJXC4.mjs";
|
|
22
22
|
import "../chunk-6BWS3CLP.mjs";
|
|
23
23
|
export {
|
|
24
24
|
BeforeAfterBlock,
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-6BWS3CLP.mjs";
|
|
4
|
+
|
|
5
|
+
// src/studio/index.ts
|
|
6
|
+
var studio_exports = {};
|
|
7
|
+
__export(studio_exports, {
|
|
8
|
+
assertStudioDocumentV1: () => assertStudioDocumentV1,
|
|
9
|
+
compileStudioDocument: () => compileStudioDocument,
|
|
10
|
+
createEmptyStudioDocument: () => createEmptyStudioDocument,
|
|
11
|
+
createImageUploadOptimizationHook: () => createImageUploadOptimizationHook,
|
|
12
|
+
createStudioRegistry: () => createStudioRegistry,
|
|
13
|
+
migrateStudioDocument: () => migrateStudioDocument,
|
|
14
|
+
validateStudioDocument: () => validateStudioDocument,
|
|
15
|
+
withImageUploadOptimization: () => withImageUploadOptimization
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// src/studio/imageUploadOptimization.ts
|
|
19
|
+
import { readFile, unlink } from "fs/promises";
|
|
20
|
+
var DEFAULT_SUPPORTED_MIME_TYPES = [
|
|
21
|
+
"image/jpeg",
|
|
22
|
+
"image/jpg",
|
|
23
|
+
"image/png",
|
|
24
|
+
"image/webp",
|
|
25
|
+
"image/avif",
|
|
26
|
+
"image/tiff"
|
|
27
|
+
];
|
|
28
|
+
var DEFAULT_OPTIONS = {
|
|
29
|
+
avifQuality: 50,
|
|
30
|
+
enforceSmallerForLossy: true,
|
|
31
|
+
jpegQuality: 78,
|
|
32
|
+
minBytes: 48 * 1024,
|
|
33
|
+
minQualityFloor: 42,
|
|
34
|
+
onlyIfSmaller: true,
|
|
35
|
+
pngCompressionLevel: 9,
|
|
36
|
+
skipAnimated: true,
|
|
37
|
+
tiffQuality: 75,
|
|
38
|
+
webpQuality: 78
|
|
39
|
+
};
|
|
40
|
+
var clamp = (value, min, max) => Math.max(min, Math.min(max, Math.round(value)));
|
|
41
|
+
var isUploadMutationOperation = (operation) => operation === "create" || operation === "update" || operation === "updateByID";
|
|
42
|
+
var isLossyMimeType = (mimetype) => mimetype === "image/jpeg" || mimetype === "image/jpg" || mimetype === "image/webp" || mimetype === "image/avif" || mimetype === "image/tiff";
|
|
43
|
+
var readIncomingBuffer = async (file) => {
|
|
44
|
+
if (file.tempFilePath) {
|
|
45
|
+
return readFile(file.tempFilePath);
|
|
46
|
+
}
|
|
47
|
+
return file.data;
|
|
48
|
+
};
|
|
49
|
+
var writeOptimizedBuffer = async (file, buffer) => {
|
|
50
|
+
if (file.tempFilePath) {
|
|
51
|
+
await unlink(file.tempFilePath).catch(() => void 0);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...file,
|
|
55
|
+
data: buffer,
|
|
56
|
+
size: buffer.length,
|
|
57
|
+
tempFilePath: void 0
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var createImageUploadOptimizationHook = (options = {}) => {
|
|
61
|
+
const supportedMimeTypes = new Set(options.supportedMimeTypes || DEFAULT_SUPPORTED_MIME_TYPES);
|
|
62
|
+
const settings = { ...DEFAULT_OPTIONS, ...options };
|
|
63
|
+
return async ({ operation, req }) => {
|
|
64
|
+
if (!isUploadMutationOperation(operation)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const file = req.file;
|
|
68
|
+
if (!file) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!supportedMimeTypes.has(file.mimetype)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (typeof file.size === "number" && file.size < settings.minBytes) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const sharpFactory = req.payload?.config?.sharp;
|
|
78
|
+
if (typeof sharpFactory !== "function") {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const originalBuffer = await readIncomingBuffer(file);
|
|
82
|
+
if (!Buffer.isBuffer(originalBuffer) || originalBuffer.length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const animatedInput = file.mimetype === "image/avif" || file.mimetype === "image/webp";
|
|
86
|
+
const metadataProbe = await sharpFactory(
|
|
87
|
+
originalBuffer,
|
|
88
|
+
animatedInput ? {
|
|
89
|
+
animated: true
|
|
90
|
+
} : void 0
|
|
91
|
+
).metadata();
|
|
92
|
+
if (settings.skipAnimated && typeof metadataProbe.pages === "number" && metadataProbe.pages > 1) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const buildPipeline = (qualityOverride) => {
|
|
96
|
+
let pipeline = sharpFactory(
|
|
97
|
+
originalBuffer,
|
|
98
|
+
animatedInput ? {
|
|
99
|
+
animated: true
|
|
100
|
+
} : void 0
|
|
101
|
+
);
|
|
102
|
+
switch (file.mimetype) {
|
|
103
|
+
case "image/jpeg":
|
|
104
|
+
case "image/jpg":
|
|
105
|
+
pipeline = pipeline.jpeg({
|
|
106
|
+
mozjpeg: true,
|
|
107
|
+
progressive: true,
|
|
108
|
+
quality: clamp(qualityOverride ?? settings.jpegQuality, 20, 100)
|
|
109
|
+
});
|
|
110
|
+
break;
|
|
111
|
+
case "image/png":
|
|
112
|
+
pipeline = pipeline.png({
|
|
113
|
+
compressionLevel: clamp(settings.pngCompressionLevel, 0, 9),
|
|
114
|
+
palette: false
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
case "image/webp":
|
|
118
|
+
pipeline = pipeline.webp({
|
|
119
|
+
quality: clamp(qualityOverride ?? settings.webpQuality, 20, 100)
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
case "image/avif":
|
|
123
|
+
pipeline = pipeline.avif({
|
|
124
|
+
quality: clamp(qualityOverride ?? settings.avifQuality, 20, 100)
|
|
125
|
+
});
|
|
126
|
+
break;
|
|
127
|
+
case "image/tiff":
|
|
128
|
+
pipeline = pipeline.tiff({
|
|
129
|
+
quality: clamp(qualityOverride ?? settings.tiffQuality, 20, 100)
|
|
130
|
+
});
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return pipeline;
|
|
136
|
+
};
|
|
137
|
+
const initialPipeline = buildPipeline();
|
|
138
|
+
if (!initialPipeline) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
let optimizedBuffer = await initialPipeline.toBuffer();
|
|
142
|
+
const shouldSweepQuality = settings.enforceSmallerForLossy && isLossyMimeType(file.mimetype);
|
|
143
|
+
if (shouldSweepQuality) {
|
|
144
|
+
const initialQuality = file.mimetype === "image/jpeg" || file.mimetype === "image/jpg" ? settings.jpegQuality : file.mimetype === "image/webp" ? settings.webpQuality : file.mimetype === "image/avif" ? settings.avifQuality : settings.tiffQuality;
|
|
145
|
+
let bestBuffer = optimizedBuffer;
|
|
146
|
+
let quality = clamp(initialQuality - 5, settings.minQualityFloor, 100);
|
|
147
|
+
while (quality >= settings.minQualityFloor) {
|
|
148
|
+
const retryPipeline = buildPipeline(quality);
|
|
149
|
+
if (!retryPipeline) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
const retryBuffer = await retryPipeline.toBuffer();
|
|
153
|
+
if (retryBuffer.length < bestBuffer.length) {
|
|
154
|
+
bestBuffer = retryBuffer;
|
|
155
|
+
}
|
|
156
|
+
quality -= 5;
|
|
157
|
+
}
|
|
158
|
+
optimizedBuffer = bestBuffer;
|
|
159
|
+
}
|
|
160
|
+
if (settings.onlyIfSmaller && optimizedBuffer.length >= originalBuffer.length) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
req.file = await writeOptimizedBuffer(file, optimizedBuffer);
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
var withImageUploadOptimization = (collection, options = {}) => {
|
|
167
|
+
if (!collection.upload) {
|
|
168
|
+
return collection;
|
|
169
|
+
}
|
|
170
|
+
const existingHooks = collection.hooks || {};
|
|
171
|
+
const beforeOperation = existingHooks.beforeOperation || [];
|
|
172
|
+
return {
|
|
173
|
+
...collection,
|
|
174
|
+
hooks: {
|
|
175
|
+
...existingHooks,
|
|
176
|
+
beforeOperation: [createImageUploadOptimizationHook(options), ...beforeOperation]
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/studio/index.ts
|
|
182
|
+
var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
183
|
+
var makeIssue = (message, path, code = "studio.invalid") => ({
|
|
184
|
+
code,
|
|
185
|
+
message,
|
|
186
|
+
path,
|
|
187
|
+
severity: "error"
|
|
188
|
+
});
|
|
189
|
+
var createEmptyStudioDocument = (title) => ({
|
|
190
|
+
metadata: {},
|
|
191
|
+
schemaVersion: 1,
|
|
192
|
+
title,
|
|
193
|
+
nodes: [],
|
|
194
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
195
|
+
});
|
|
196
|
+
function assertStudioDocumentV1(input) {
|
|
197
|
+
if (!isRecord(input)) {
|
|
198
|
+
throw new Error("Studio document must be an object");
|
|
199
|
+
}
|
|
200
|
+
if (input.schemaVersion !== 1) {
|
|
201
|
+
throw new Error("Unsupported studio schemaVersion");
|
|
202
|
+
}
|
|
203
|
+
if (!Array.isArray(input.nodes)) {
|
|
204
|
+
throw new Error("Studio document nodes must be an array");
|
|
205
|
+
}
|
|
206
|
+
const nodes = input.nodes.map((node, index) => {
|
|
207
|
+
if (!isRecord(node)) {
|
|
208
|
+
throw new Error(`Node at index ${index} must be an object`);
|
|
209
|
+
}
|
|
210
|
+
if (typeof node.id !== "string" || node.id.length === 0) {
|
|
211
|
+
throw new Error(`Node at index ${index} has invalid id`);
|
|
212
|
+
}
|
|
213
|
+
if (typeof node.type !== "string" || node.type.length === 0) {
|
|
214
|
+
throw new Error(`Node at index ${index} has invalid type`);
|
|
215
|
+
}
|
|
216
|
+
if (!isRecord(node.data)) {
|
|
217
|
+
throw new Error(`Node at index ${index} has invalid data`);
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
id: node.id,
|
|
221
|
+
type: node.type,
|
|
222
|
+
data: node.data
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
metadata: isRecord(input.metadata) ? input.metadata : void 0,
|
|
227
|
+
schemaVersion: 1,
|
|
228
|
+
title: typeof input.title === "string" ? input.title : void 0,
|
|
229
|
+
nodes,
|
|
230
|
+
updatedAt: typeof input.updatedAt === "string" ? input.updatedAt : void 0
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function createStudioRegistry(modules) {
|
|
234
|
+
const moduleByID = new Map(modules.map((mod) => [mod.id, mod]));
|
|
235
|
+
const nodeTypes = modules.flatMap((mod) => mod.nodeTypes);
|
|
236
|
+
const nodeTypeByName = new Map(nodeTypes.map((definition) => [definition.type, definition]));
|
|
237
|
+
return {
|
|
238
|
+
getModuleByID: (id) => moduleByID.get(id),
|
|
239
|
+
getNodeTypeByName: (type) => nodeTypeByName.get(type),
|
|
240
|
+
listInspectorPanels: () => modules.flatMap((mod) => mod.inspectorPanels),
|
|
241
|
+
listModules: () => [...modules],
|
|
242
|
+
listPaletteGroups: () => modules.flatMap((mod) => mod.paletteGroups),
|
|
243
|
+
listNodeTypes: () => [...nodeTypes]
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function validateStudioDocument(document, modules) {
|
|
247
|
+
const issues = [];
|
|
248
|
+
if (document.schemaVersion !== 1) {
|
|
249
|
+
issues.push(makeIssue("Unsupported schema version", "schemaVersion", "studio.schemaVersion"));
|
|
250
|
+
}
|
|
251
|
+
if (!Array.isArray(document.nodes)) {
|
|
252
|
+
issues.push(makeIssue("Nodes must be an array", "nodes", "studio.nodes"));
|
|
253
|
+
return issues;
|
|
254
|
+
}
|
|
255
|
+
const registry = createStudioRegistry(modules);
|
|
256
|
+
const nodeIDs = /* @__PURE__ */ new Set();
|
|
257
|
+
document.nodes.forEach((node, index) => {
|
|
258
|
+
if (!node.id) {
|
|
259
|
+
issues.push(makeIssue("Node id is required", `nodes.${index}.id`, "studio.node.id"));
|
|
260
|
+
}
|
|
261
|
+
if (nodeIDs.has(node.id)) {
|
|
262
|
+
issues.push(makeIssue("Node id must be unique", `nodes.${index}.id`, "studio.node.id.duplicate"));
|
|
263
|
+
}
|
|
264
|
+
nodeIDs.add(node.id);
|
|
265
|
+
if (!registry.getNodeTypeByName(node.type)) {
|
|
266
|
+
issues.push(makeIssue("Unsupported node type", `nodes.${index}.type`, "studio.node.type"));
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
for (const module of modules) {
|
|
270
|
+
for (const validate of module.validators) {
|
|
271
|
+
issues.push(...validate(document));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return issues;
|
|
275
|
+
}
|
|
276
|
+
function compileStudioDocument(document, modules) {
|
|
277
|
+
const issues = validateStudioDocument(document, modules);
|
|
278
|
+
const compilerEntries = modules.filter((mod) => typeof mod.compiler?.compileNode === "function").map((mod) => mod.compiler?.compileNode);
|
|
279
|
+
const layout = document.nodes.map((node) => {
|
|
280
|
+
for (const compileNode of compilerEntries) {
|
|
281
|
+
if (!compileNode) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const compiled = compileNode(node);
|
|
285
|
+
if (compiled) {
|
|
286
|
+
return compiled;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
id: node.id,
|
|
291
|
+
blockType: node.type,
|
|
292
|
+
...node.data
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
issues,
|
|
297
|
+
layout
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function migrateStudioDocument(value, migrations) {
|
|
301
|
+
const sorted = [...migrations].sort((a, b) => a.fromVersion - b.fromVersion);
|
|
302
|
+
let current = value;
|
|
303
|
+
for (const migration of sorted) {
|
|
304
|
+
if (!isRecord(current) || current.schemaVersion !== migration.fromVersion) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
current = migration.migrate(current);
|
|
308
|
+
}
|
|
309
|
+
return assertStudioDocumentV1(current);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export {
|
|
313
|
+
createImageUploadOptimizationHook,
|
|
314
|
+
withImageUploadOptimization,
|
|
315
|
+
createEmptyStudioDocument,
|
|
316
|
+
assertStudioDocumentV1,
|
|
317
|
+
createStudioRegistry,
|
|
318
|
+
validateStudioDocument,
|
|
319
|
+
compileStudioDocument,
|
|
320
|
+
migrateStudioDocument,
|
|
321
|
+
studio_exports
|
|
322
|
+
};
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SOCIAL_MEDIA_DEFAULT_ICON_BY_PLATFORM,
|
|
3
|
+
SOCIAL_MEDIA_PLATFORMS,
|
|
4
|
+
SOCIAL_MEDIA_PLATFORM_LABELS
|
|
5
|
+
} from "./chunk-ZTXJG4K5.mjs";
|
|
6
|
+
import {
|
|
7
|
+
assertStudioDocumentV1
|
|
8
|
+
} from "./chunk-ADIIWIYL.mjs";
|
|
9
|
+
import {
|
|
10
|
+
studioDocumentToLayout
|
|
11
|
+
} from "./chunk-PF3EBZXF.mjs";
|
|
1
12
|
import {
|
|
2
13
|
__export
|
|
3
14
|
} from "./chunk-6BWS3CLP.mjs";
|
|
@@ -9,7 +20,8 @@ __export(nextjs_exports, {
|
|
|
9
20
|
createPageQueries: () => createPageQueries,
|
|
10
21
|
createPayloadClient: () => createPayloadClient,
|
|
11
22
|
createSiteQueries: () => createSiteQueries,
|
|
12
|
-
resolveMedia: () => resolveMedia
|
|
23
|
+
resolveMedia: () => resolveMedia,
|
|
24
|
+
resolveSocialMediaLinks: () => resolveSocialMediaLinks
|
|
13
25
|
});
|
|
14
26
|
|
|
15
27
|
// src/nextjs/client/payload.ts
|
|
@@ -27,6 +39,24 @@ function createPayloadClient(config) {
|
|
|
27
39
|
|
|
28
40
|
// src/nextjs/queries/pages.ts
|
|
29
41
|
import { unstable_cache } from "next/cache";
|
|
42
|
+
var PAGE_QUERY_CACHE_VERSION = "v4-published-only-public";
|
|
43
|
+
function withStudioDocumentLayout(page) {
|
|
44
|
+
if (!page) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const studioDocument = assertStudioDocumentV1(page.studioDocument);
|
|
49
|
+
const compiledLayout = studioDocumentToLayout(studioDocument);
|
|
50
|
+
if (Array.isArray(compiledLayout) && compiledLayout.length > 0) {
|
|
51
|
+
return {
|
|
52
|
+
...page,
|
|
53
|
+
layout: compiledLayout
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
return page;
|
|
59
|
+
}
|
|
30
60
|
function normalizePath(segments) {
|
|
31
61
|
if (!segments || segments.length === 0) {
|
|
32
62
|
return "/";
|
|
@@ -35,35 +65,42 @@ function normalizePath(segments) {
|
|
|
35
65
|
return cleaned.length > 0 ? `/${cleaned}` : "/";
|
|
36
66
|
}
|
|
37
67
|
async function queryPageByPath(payload, path, draft) {
|
|
68
|
+
const pathWhere = {
|
|
69
|
+
path: {
|
|
70
|
+
equals: path
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const publishedWhere = {
|
|
74
|
+
_status: {
|
|
75
|
+
equals: "published"
|
|
76
|
+
}
|
|
77
|
+
};
|
|
38
78
|
const result = await payload.find({
|
|
39
79
|
collection: "pages",
|
|
40
80
|
depth: 2,
|
|
41
81
|
draft,
|
|
42
82
|
limit: 1,
|
|
43
83
|
overrideAccess: false,
|
|
44
|
-
where: {
|
|
45
|
-
path: {
|
|
46
|
-
equals: path
|
|
47
|
-
}
|
|
48
|
-
}
|
|
84
|
+
where: draft ? pathWhere : { and: [pathWhere, publishedWhere] }
|
|
49
85
|
});
|
|
50
86
|
if (result.docs.length > 0) {
|
|
51
|
-
return result.docs[0] || null;
|
|
87
|
+
return withStudioDocumentLayout(result.docs[0] || null);
|
|
52
88
|
}
|
|
53
89
|
if (path === "/") {
|
|
90
|
+
const homeWhere = {
|
|
91
|
+
slug: {
|
|
92
|
+
equals: "home"
|
|
93
|
+
}
|
|
94
|
+
};
|
|
54
95
|
const homeResult = await payload.find({
|
|
55
96
|
collection: "pages",
|
|
56
97
|
depth: 2,
|
|
57
98
|
draft,
|
|
58
99
|
limit: 1,
|
|
59
100
|
overrideAccess: false,
|
|
60
|
-
where: {
|
|
61
|
-
slug: {
|
|
62
|
-
equals: "home"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
101
|
+
where: draft ? homeWhere : { and: [homeWhere, publishedWhere] }
|
|
65
102
|
});
|
|
66
|
-
return homeResult.docs[0] || null;
|
|
103
|
+
return withStudioDocumentLayout(homeResult.docs[0] || null);
|
|
67
104
|
}
|
|
68
105
|
return null;
|
|
69
106
|
}
|
|
@@ -73,7 +110,7 @@ function createPageQueries(getPayloadClient, contentTag = "website-content") {
|
|
|
73
110
|
const payload = await getPayloadClient();
|
|
74
111
|
return queryPageByPath(payload, path, false);
|
|
75
112
|
},
|
|
76
|
-
["page-by-path"],
|
|
113
|
+
["page-by-path", PAGE_QUERY_CACHE_VERSION],
|
|
77
114
|
{ tags: [contentTag] }
|
|
78
115
|
);
|
|
79
116
|
async function getPageBySegments(segments, draft = false) {
|
|
@@ -153,6 +190,18 @@ function createSiteQueries(getPayloadClient, contentTag = "website-content") {
|
|
|
153
190
|
["footer-global"],
|
|
154
191
|
{ tags: [contentTag] }
|
|
155
192
|
);
|
|
193
|
+
const getSocialMediaCached = unstable_cache2(
|
|
194
|
+
async () => {
|
|
195
|
+
const payload = await getPayloadClient();
|
|
196
|
+
const socialMedia = await payload.findGlobal({
|
|
197
|
+
slug: "social-media",
|
|
198
|
+
depth: 1
|
|
199
|
+
});
|
|
200
|
+
return socialMedia;
|
|
201
|
+
},
|
|
202
|
+
["social-media-global"],
|
|
203
|
+
{ tags: [contentTag] }
|
|
204
|
+
);
|
|
156
205
|
async function getSiteSettings(draft = false) {
|
|
157
206
|
if (draft) {
|
|
158
207
|
const payload = await getPayloadClient();
|
|
@@ -189,10 +238,23 @@ function createSiteQueries(getPayloadClient, contentTag = "website-content") {
|
|
|
189
238
|
}
|
|
190
239
|
return getFooterCached();
|
|
191
240
|
}
|
|
241
|
+
async function getSocialMedia(draft = false) {
|
|
242
|
+
if (draft) {
|
|
243
|
+
const payload = await getPayloadClient();
|
|
244
|
+
const socialMedia = await payload.findGlobal({
|
|
245
|
+
slug: "social-media",
|
|
246
|
+
depth: 1,
|
|
247
|
+
draft: true
|
|
248
|
+
});
|
|
249
|
+
return socialMedia;
|
|
250
|
+
}
|
|
251
|
+
return getSocialMediaCached();
|
|
252
|
+
}
|
|
192
253
|
return {
|
|
193
254
|
getSiteSettings,
|
|
194
255
|
getHeader,
|
|
195
|
-
getFooter
|
|
256
|
+
getFooter,
|
|
257
|
+
getSocialMedia
|
|
196
258
|
};
|
|
197
259
|
}
|
|
198
260
|
|
|
@@ -219,11 +281,38 @@ function resolveMedia(media) {
|
|
|
219
281
|
return null;
|
|
220
282
|
}
|
|
221
283
|
|
|
284
|
+
// src/nextjs/utilities/socialMedia.ts
|
|
285
|
+
function resolveSocialMediaLinks(data) {
|
|
286
|
+
const profiles = data?.profiles;
|
|
287
|
+
if (!profiles || typeof profiles !== "object") {
|
|
288
|
+
return [];
|
|
289
|
+
}
|
|
290
|
+
return SOCIAL_MEDIA_PLATFORMS.reduce((acc, platform) => {
|
|
291
|
+
const profile = profiles[platform];
|
|
292
|
+
if (!profile || typeof profile !== "object") {
|
|
293
|
+
return acc;
|
|
294
|
+
}
|
|
295
|
+
const url = typeof profile.url === "string" ? profile.url.trim() : "";
|
|
296
|
+
if (!url) {
|
|
297
|
+
return acc;
|
|
298
|
+
}
|
|
299
|
+
const icon = typeof profile.icon === "string" && profile.icon.trim().length > 0 ? profile.icon.trim() : SOCIAL_MEDIA_DEFAULT_ICON_BY_PLATFORM[platform];
|
|
300
|
+
acc.push({
|
|
301
|
+
icon,
|
|
302
|
+
label: SOCIAL_MEDIA_PLATFORM_LABELS[platform],
|
|
303
|
+
platform,
|
|
304
|
+
url
|
|
305
|
+
});
|
|
306
|
+
return acc;
|
|
307
|
+
}, []);
|
|
308
|
+
}
|
|
309
|
+
|
|
222
310
|
export {
|
|
223
311
|
WEBSITE_CONTENT_TAG,
|
|
224
312
|
createPayloadClient,
|
|
225
313
|
createPageQueries,
|
|
226
314
|
createSiteQueries,
|
|
227
315
|
resolveMedia,
|
|
316
|
+
resolveSocialMediaLinks,
|
|
228
317
|
nextjs_exports
|
|
229
318
|
};
|