@bison-lab/payload-core 3.31.0 → 3.33.0
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 +42 -4
- package/dist/admin.d.mts +54 -2
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +1886 -7
- package/dist/admin.mjs.map +1 -1
- package/dist/index.d.mts +132 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +367 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -174,16 +174,16 @@ const COLOR_USAGES_PATH = "/color-usages";
|
|
|
174
174
|
* (drafts included). A color only on an unpublished page is still in use.
|
|
175
175
|
*/
|
|
176
176
|
async function findColorUsages(payload, scopes, key) {
|
|
177
|
-
const { collections, globals } = resolveScopes(payload, scopes);
|
|
177
|
+
const { collections, globals } = resolveScopes$1(payload, scopes);
|
|
178
178
|
const usages = [];
|
|
179
|
-
for (const collection of collections) for await (const doc of eachCollectionDoc(payload, collection)) for (const hit of findColorTokens(doc, key)) usages.push({
|
|
179
|
+
for (const collection of collections) for await (const doc of eachCollectionDoc$1(payload, collection)) for (const hit of findColorTokens(doc, key)) usages.push({
|
|
180
180
|
collection,
|
|
181
181
|
id: idOf(doc),
|
|
182
182
|
path: hit.path,
|
|
183
183
|
token: hit.token
|
|
184
184
|
});
|
|
185
185
|
for (const slug of globals) {
|
|
186
|
-
const doc = await readGlobal(payload, slug);
|
|
186
|
+
const doc = await readGlobal$1(payload, slug);
|
|
187
187
|
if (!doc) continue;
|
|
188
188
|
for (const hit of findColorTokens(doc, key)) usages.push({
|
|
189
189
|
global: slug,
|
|
@@ -194,8 +194,8 @@ async function findColorUsages(payload, scopes, key) {
|
|
|
194
194
|
return usages;
|
|
195
195
|
}
|
|
196
196
|
async function rewriteColorUsages(payload, scopes, fromKey, toKey) {
|
|
197
|
-
const { collections, globals } = resolveScopes(payload, scopes);
|
|
198
|
-
for (const collection of collections) for await (const doc of eachCollectionDoc(payload, collection)) {
|
|
197
|
+
const { collections, globals } = resolveScopes$1(payload, scopes);
|
|
198
|
+
for (const collection of collections) for await (const doc of eachCollectionDoc$1(payload, collection)) {
|
|
199
199
|
if (findColorTokens(doc, fromKey).length === 0) continue;
|
|
200
200
|
const { id: _id, ...data } = rewriteColorTokens(doc, fromKey, toKey);
|
|
201
201
|
const id = idOf(doc);
|
|
@@ -209,7 +209,7 @@ async function rewriteColorUsages(payload, scopes, fromKey, toKey) {
|
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
211
|
for (const slug of globals) {
|
|
212
|
-
const doc = await readGlobal(payload, slug);
|
|
212
|
+
const doc = await readGlobal$1(payload, slug);
|
|
213
213
|
if (!doc || findColorTokens(doc, fromKey).length === 0) continue;
|
|
214
214
|
await payload.updateGlobal({
|
|
215
215
|
slug,
|
|
@@ -226,7 +226,7 @@ async function replacementKeys(payload, except) {
|
|
|
226
226
|
overrideAccess: true
|
|
227
227
|
})).map((look) => look.value).filter((key) => key !== except);
|
|
228
228
|
}
|
|
229
|
-
function resolveScopes(payload, scopes) {
|
|
229
|
+
function resolveScopes$1(payload, scopes) {
|
|
230
230
|
if (scopes === true) return registeredScopes(payload);
|
|
231
231
|
return {
|
|
232
232
|
collections: scopes?.collections ?? [],
|
|
@@ -235,16 +235,16 @@ function resolveScopes(payload, scopes) {
|
|
|
235
235
|
}
|
|
236
236
|
function registeredScopes(payload) {
|
|
237
237
|
return {
|
|
238
|
-
collections: slugsOf(payload.config?.collections ?? payload.collections).filter((slug) => !slug.startsWith("payload-")),
|
|
239
|
-
globals: slugsOf(payload.config?.globals ?? payload.globals?.config).filter((slug) => slug !== THEME_SLUG)
|
|
238
|
+
collections: slugsOf$1(payload.config?.collections ?? payload.collections).filter((slug) => !slug.startsWith("payload-")),
|
|
239
|
+
globals: slugsOf$1(payload.config?.globals ?? payload.globals?.config).filter((slug) => slug !== THEME_SLUG)
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
function slugsOf(value) {
|
|
242
|
+
function slugsOf$1(value) {
|
|
243
243
|
if (Array.isArray(value)) return value.map((item) => item?.slug).filter((slug) => Boolean(slug));
|
|
244
244
|
if (value && typeof value === "object") return Object.keys(value);
|
|
245
245
|
return [];
|
|
246
246
|
}
|
|
247
|
-
async function readGlobal(payload, slug) {
|
|
247
|
+
async function readGlobal$1(payload, slug) {
|
|
248
248
|
try {
|
|
249
249
|
return await payload.findGlobal({
|
|
250
250
|
slug,
|
|
@@ -256,7 +256,7 @@ async function readGlobal(payload, slug) {
|
|
|
256
256
|
return null;
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
-
async function* eachCollectionDoc(payload, collection) {
|
|
259
|
+
async function* eachCollectionDoc$1(payload, collection) {
|
|
260
260
|
let page = 1;
|
|
261
261
|
for (;;) {
|
|
262
262
|
let result;
|
|
@@ -995,7 +995,7 @@ function hideUnlessFeature(slug) {
|
|
|
995
995
|
//#region src/theme/global.ts
|
|
996
996
|
/** Same value as tokens `SUCCESS_SCALE_HEX`. Inlined so an older tokens peer still boots. */
|
|
997
997
|
const LIBRARY_SUCCESS_HEX = "#22c55e";
|
|
998
|
-
function requireAccess$
|
|
998
|
+
function requireAccess$2(options) {
|
|
999
999
|
const read = options.access?.read;
|
|
1000
1000
|
const update = options.access?.update;
|
|
1001
1001
|
if (!read || !update) throw new Error("createTheme requires access.read and access.update. Pass canManageBrand from this package as update.");
|
|
@@ -1301,7 +1301,7 @@ function identityFields(collection) {
|
|
|
1301
1301
|
* Locking is off. No draft mode, no preview pane.
|
|
1302
1302
|
*/
|
|
1303
1303
|
function createTheme(options) {
|
|
1304
|
-
const access = requireAccess$
|
|
1304
|
+
const access = requireAccess$2(options);
|
|
1305
1305
|
const destructive = requireDestructive(options);
|
|
1306
1306
|
const { seed, fonts = catalog, fontsBaseUrl = "/fonts", contrastTarget = 7, logo, identity, onPublish, colorUsages } = options;
|
|
1307
1307
|
const adminCustom = {
|
|
@@ -1398,7 +1398,7 @@ const BRAND_ASSETS_MIME_TYPES = [
|
|
|
1398
1398
|
"image/x-icon",
|
|
1399
1399
|
"image/vnd.microsoft.icon"
|
|
1400
1400
|
];
|
|
1401
|
-
function requireAccess(options) {
|
|
1401
|
+
function requireAccess$1(options) {
|
|
1402
1402
|
const read = options.access?.read;
|
|
1403
1403
|
const update = options.access?.update;
|
|
1404
1404
|
if (!read || !update) throw new Error("createBrandAssets requires access.read and access.update. Pass canManageBrand from this package as update.");
|
|
@@ -1413,7 +1413,7 @@ function requireAccess(options) {
|
|
|
1413
1413
|
* passes this slug as `logo.collection`.
|
|
1414
1414
|
*/
|
|
1415
1415
|
function createBrandAssets(options) {
|
|
1416
|
-
const access = requireAccess(options);
|
|
1416
|
+
const access = requireAccess$1(options);
|
|
1417
1417
|
return {
|
|
1418
1418
|
slug: options.slug ?? "brand-assets",
|
|
1419
1419
|
labels: {
|
|
@@ -2258,16 +2258,222 @@ function createUsers({ secureCookies, rolesField, extras = [] }) {
|
|
|
2258
2258
|
};
|
|
2259
2259
|
}
|
|
2260
2260
|
//#endregion
|
|
2261
|
+
//#region src/collections/media-alt.ts
|
|
2262
|
+
/** Alt text from an upload filename: drop the extension, hyphenate the rest. */
|
|
2263
|
+
function altFromFilename(filename) {
|
|
2264
|
+
if (typeof filename !== "string") return "";
|
|
2265
|
+
return filename.trim().replace(/\.[a-z0-9]{1,5}$/i, "").replace(/[_\s]+/g, "-");
|
|
2266
|
+
}
|
|
2267
|
+
function fillBlankAltFromFilename(data) {
|
|
2268
|
+
if (data.alt != null && data.alt !== "") return data;
|
|
2269
|
+
const generated = altFromFilename(data.filename);
|
|
2270
|
+
if (generated) data.alt = generated;
|
|
2271
|
+
return data;
|
|
2272
|
+
}
|
|
2273
|
+
//#endregion
|
|
2274
|
+
//#region src/collections/media-constants.ts
|
|
2275
|
+
/** Import-map strings and route paths shared by createMedia and admin views. */
|
|
2276
|
+
const MEDIA_LIST = "@bison-lab/payload-core/admin#MediaListView";
|
|
2277
|
+
const MEDIA_ALT_AUTOFILL = "@bison-lab/payload-core/admin#MediaAltAutofill";
|
|
2278
|
+
const MEDIA_IN_USE_PATH = "/in-use";
|
|
2279
|
+
//#endregion
|
|
2280
|
+
//#region src/collections/media-in-use.ts
|
|
2281
|
+
const MEDIA = "media";
|
|
2282
|
+
async function findMediaInUse(payload, scopes) {
|
|
2283
|
+
const { collections, globals } = resolveScopes(payload, scopes);
|
|
2284
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2285
|
+
const errors = [];
|
|
2286
|
+
for (const slug of collections) {
|
|
2287
|
+
const config = collectionOf(payload, slug);
|
|
2288
|
+
const publishedOnly = collectionHasDrafts(config);
|
|
2289
|
+
try {
|
|
2290
|
+
for await (const doc of eachCollectionDoc(payload, slug, publishedOnly)) collectFromFields(config?.fields ?? [], doc, ids);
|
|
2291
|
+
} catch {
|
|
2292
|
+
errors.push(slug);
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
for (const slug of globals) {
|
|
2296
|
+
const config = globalOf(payload, slug);
|
|
2297
|
+
try {
|
|
2298
|
+
const doc = await readGlobal(payload, slug);
|
|
2299
|
+
if (!doc) continue;
|
|
2300
|
+
collectFromFields(config?.fields ?? [], doc, ids);
|
|
2301
|
+
} catch {
|
|
2302
|
+
errors.push(slug);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
if (errors.length > 0) throw new Error(`Media in-use scan failed for: ${errors.join(", ")}`);
|
|
2306
|
+
return ids;
|
|
2307
|
+
}
|
|
2308
|
+
function resolveScopes(payload, scopes) {
|
|
2309
|
+
if (scopes === true) return {
|
|
2310
|
+
collections: slugsOf(payload.config?.collections ?? payload.collections).filter((slug) => !slug.startsWith("payload-") && slug !== MEDIA),
|
|
2311
|
+
globals: slugsOf(payload.config?.globals ?? payload.globals?.config)
|
|
2312
|
+
};
|
|
2313
|
+
return {
|
|
2314
|
+
collections: (scopes.collections ?? []).filter((slug) => slug !== MEDIA),
|
|
2315
|
+
globals: scopes.globals ?? []
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
function collectionOf(payload, slug) {
|
|
2319
|
+
const live = payload.collections?.[slug]?.config;
|
|
2320
|
+
if (live) return live;
|
|
2321
|
+
return payload.config?.collections?.find((entry) => entry.slug === slug);
|
|
2322
|
+
}
|
|
2323
|
+
function globalOf(payload, slug) {
|
|
2324
|
+
return payload.config?.globals?.find((entry) => entry.slug === slug) ?? payload.globals?.config?.find((entry) => entry.slug === slug);
|
|
2325
|
+
}
|
|
2326
|
+
function collectionHasDrafts(config) {
|
|
2327
|
+
const versions = config?.versions;
|
|
2328
|
+
if (!versions || typeof versions !== "object") return false;
|
|
2329
|
+
return Boolean(versions.drafts);
|
|
2330
|
+
}
|
|
2331
|
+
function slugsOf(value) {
|
|
2332
|
+
if (Array.isArray(value)) return value.map((item) => item?.slug).filter((slug) => Boolean(slug));
|
|
2333
|
+
if (value && typeof value === "object") return Object.keys(value);
|
|
2334
|
+
return [];
|
|
2335
|
+
}
|
|
2336
|
+
async function readGlobal(payload, slug) {
|
|
2337
|
+
return payload.findGlobal({
|
|
2338
|
+
slug,
|
|
2339
|
+
depth: 0,
|
|
2340
|
+
overrideAccess: true
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
async function* eachCollectionDoc(payload, collection, publishedOnly) {
|
|
2344
|
+
let page = 1;
|
|
2345
|
+
for (;;) {
|
|
2346
|
+
let result;
|
|
2347
|
+
result = await payload.find({
|
|
2348
|
+
collection,
|
|
2349
|
+
depth: 0,
|
|
2350
|
+
limit: 100,
|
|
2351
|
+
page,
|
|
2352
|
+
overrideAccess: true,
|
|
2353
|
+
...publishedOnly ? { where: { _status: { equals: "published" } } } : {}
|
|
2354
|
+
});
|
|
2355
|
+
for (const doc of result.docs) yield doc;
|
|
2356
|
+
const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);
|
|
2357
|
+
if (page >= totalPages || result.docs.length === 0) break;
|
|
2358
|
+
page += 1;
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
function collectFromFields(fields, doc, ids) {
|
|
2362
|
+
for (const field of fields) {
|
|
2363
|
+
if (!field) continue;
|
|
2364
|
+
if (field.type === "tabs") {
|
|
2365
|
+
for (const tab of field.tabs ?? []) collectFromFields(tab.fields ?? [], doc, ids);
|
|
2366
|
+
continue;
|
|
2367
|
+
}
|
|
2368
|
+
if (field.type === "row" || field.type === "collapsible") {
|
|
2369
|
+
collectFromFields(field.fields ?? [], doc, ids);
|
|
2370
|
+
continue;
|
|
2371
|
+
}
|
|
2372
|
+
if (field.type === "group") {
|
|
2373
|
+
collectFromFields(field.fields ?? [], field.name ? get(doc, field.name) : doc, ids);
|
|
2374
|
+
continue;
|
|
2375
|
+
}
|
|
2376
|
+
if (field.type === "array" && field.name) {
|
|
2377
|
+
const rows = get(doc, field.name);
|
|
2378
|
+
if (Array.isArray(rows)) for (const row of rows) collectFromFields(field.fields ?? [], row, ids);
|
|
2379
|
+
continue;
|
|
2380
|
+
}
|
|
2381
|
+
if (field.type === "blocks" && field.name) {
|
|
2382
|
+
const rows = get(doc, field.name);
|
|
2383
|
+
if (Array.isArray(rows)) for (const row of rows) {
|
|
2384
|
+
if (!row || typeof row !== "object") continue;
|
|
2385
|
+
const type = row.blockType;
|
|
2386
|
+
const block = field.blocks?.find((entry) => entry.slug === type);
|
|
2387
|
+
if (block) collectFromFields(block.fields ?? [], row, ids);
|
|
2388
|
+
}
|
|
2389
|
+
continue;
|
|
2390
|
+
}
|
|
2391
|
+
if ((field.type === "upload" || field.type === "relationship") && field.name && relationToMedia(field.relationTo)) {
|
|
2392
|
+
collectMediaIds(get(doc, field.name), ids);
|
|
2393
|
+
continue;
|
|
2394
|
+
}
|
|
2395
|
+
if (field.type === "richText" && field.name) collectLexicalUploads(get(doc, field.name), ids);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
function relationToMedia(relationTo) {
|
|
2399
|
+
if (relationTo === MEDIA) return true;
|
|
2400
|
+
return Array.isArray(relationTo) && relationTo.includes(MEDIA);
|
|
2401
|
+
}
|
|
2402
|
+
function collectMediaIds(value, ids) {
|
|
2403
|
+
if (value == null) return;
|
|
2404
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
2405
|
+
ids.add(String(value));
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
if (Array.isArray(value)) {
|
|
2409
|
+
for (const item of value) collectMediaIds(item, ids);
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
if (typeof value === "object") {
|
|
2413
|
+
const obj = value;
|
|
2414
|
+
if (obj.relationTo && obj.relationTo !== MEDIA) return;
|
|
2415
|
+
collectMediaIds(obj.value ?? obj.id, ids);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
function collectLexicalUploads(node, ids) {
|
|
2419
|
+
if (!node || typeof node !== "object") return;
|
|
2420
|
+
const obj = node;
|
|
2421
|
+
if (obj.type === "upload" && (obj.relationTo == null || obj.relationTo === MEDIA)) collectMediaIds(obj.value, ids);
|
|
2422
|
+
if (obj.root) collectLexicalUploads(obj.root, ids);
|
|
2423
|
+
if (Array.isArray(obj.children)) for (const child of obj.children) collectLexicalUploads(child, ids);
|
|
2424
|
+
}
|
|
2425
|
+
function get(doc, name) {
|
|
2426
|
+
if (!doc || typeof doc !== "object") return void 0;
|
|
2427
|
+
return doc[name];
|
|
2428
|
+
}
|
|
2429
|
+
//#endregion
|
|
2261
2430
|
//#region src/collections/media.ts
|
|
2431
|
+
const DEFAULT_RESIZE = {
|
|
2432
|
+
width: 2560,
|
|
2433
|
+
height: 2560,
|
|
2434
|
+
fit: "inside",
|
|
2435
|
+
withoutEnlargement: true
|
|
2436
|
+
};
|
|
2437
|
+
function defaultShareSizes() {
|
|
2438
|
+
return [{
|
|
2439
|
+
...SHARE_IMAGE_SIZE,
|
|
2440
|
+
admin: {
|
|
2441
|
+
disableGroupBy: true,
|
|
2442
|
+
disableListColumn: true,
|
|
2443
|
+
disableListFilter: true
|
|
2444
|
+
}
|
|
2445
|
+
}];
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Client uploads write the original before Sharp resizes `req.file`.
|
|
2449
|
+
* Drop the flag so the resized buffer overwrites that object. Disk
|
|
2450
|
+
* uploads have no flag; this is a no-op.
|
|
2451
|
+
*/
|
|
2452
|
+
function replaceClientOriginalWithResizedFile(req) {
|
|
2453
|
+
if (req.file && "clientUploadContext" in req.file) delete req.file.clientUploadContext;
|
|
2454
|
+
}
|
|
2262
2455
|
/**
|
|
2263
2456
|
* Uploads, readable by anyone: the public site serves these files. Writing is
|
|
2264
2457
|
* an editorial action, deleting is not — removing an asset a live page
|
|
2265
2458
|
* references breaks that page.
|
|
2266
2459
|
*/
|
|
2267
|
-
function createMedia({ staticDir = "media", mimeTypes = ["image/*"], imageSizes } = {}) {
|
|
2460
|
+
function createMedia({ staticDir = "media", mimeTypes = ["image/*"], imageSizes, inUse = true } = {}) {
|
|
2268
2461
|
return {
|
|
2269
2462
|
slug: "media",
|
|
2270
|
-
admin: {
|
|
2463
|
+
admin: {
|
|
2464
|
+
hidden: hideUnlessFeature("media"),
|
|
2465
|
+
useAsTitle: "filename",
|
|
2466
|
+
defaultColumns: [
|
|
2467
|
+
"filename",
|
|
2468
|
+
"alt",
|
|
2469
|
+
"updatedAt",
|
|
2470
|
+
"createdAt"
|
|
2471
|
+
],
|
|
2472
|
+
listSearchableFields: ["filename", "alt"],
|
|
2473
|
+
pagination: { defaultLimit: 10 },
|
|
2474
|
+
custom: { mediaInUse: inUse !== false },
|
|
2475
|
+
components: { views: { list: { Component: MEDIA_LIST } } }
|
|
2476
|
+
},
|
|
2271
2477
|
access: {
|
|
2272
2478
|
read: () => true,
|
|
2273
2479
|
create: canUseFeature("media"),
|
|
@@ -2277,15 +2483,155 @@ function createMedia({ staticDir = "media", mimeTypes = ["image/*"], imageSizes
|
|
|
2277
2483
|
upload: {
|
|
2278
2484
|
staticDir,
|
|
2279
2485
|
mimeTypes,
|
|
2280
|
-
imageSizes
|
|
2486
|
+
imageSizes: imageSizes ?? defaultShareSizes(),
|
|
2487
|
+
resizeOptions: DEFAULT_RESIZE
|
|
2281
2488
|
},
|
|
2489
|
+
hooks: {
|
|
2490
|
+
beforeValidate: [({ data }) => data ? fillBlankAltFromFilename(data) : data],
|
|
2491
|
+
beforeChange: [({ data, req }) => {
|
|
2492
|
+
replaceClientOriginalWithResizedFile(req);
|
|
2493
|
+
return data;
|
|
2494
|
+
}]
|
|
2495
|
+
},
|
|
2496
|
+
endpoints: inUse === false ? [] : [inUseEndpoint(inUse)],
|
|
2282
2497
|
fields: [{
|
|
2283
2498
|
name: "alt",
|
|
2284
2499
|
type: "text",
|
|
2285
|
-
required: true
|
|
2500
|
+
required: true,
|
|
2501
|
+
admin: { components: { afterInput: [MEDIA_ALT_AUTOFILL] } }
|
|
2286
2502
|
}]
|
|
2287
2503
|
};
|
|
2288
2504
|
}
|
|
2505
|
+
function inUseEndpoint(scopes) {
|
|
2506
|
+
return {
|
|
2507
|
+
path: MEDIA_IN_USE_PATH,
|
|
2508
|
+
method: "get",
|
|
2509
|
+
handler: async (req) => {
|
|
2510
|
+
if (!req.user) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
2511
|
+
try {
|
|
2512
|
+
const ids = [...await findMediaInUse(req.payload, scopes)];
|
|
2513
|
+
return Response.json({ ids });
|
|
2514
|
+
} catch (error) {
|
|
2515
|
+
const message = error instanceof Error ? error.message : "Media in-use scan failed";
|
|
2516
|
+
return Response.json({ error: message }, { status: 503 });
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
};
|
|
2520
|
+
}
|
|
2521
|
+
//#endregion
|
|
2522
|
+
//#region src/taxonomy/collection.ts
|
|
2523
|
+
function requireAccess(options) {
|
|
2524
|
+
const read = options.access?.read;
|
|
2525
|
+
const update = options.access?.update;
|
|
2526
|
+
if (!read || !update) throw new Error("createTaxonomy requires access.read and access.update. Pass canUseFeature(\"questions\") as update when Topics are edited from the FAQ Library.");
|
|
2527
|
+
return {
|
|
2528
|
+
read,
|
|
2529
|
+
update
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* Name-only terms collection. Topics (and later news or blog) share the
|
|
2534
|
+
* same documents. Hidden from the left nav by default; add and delete for
|
|
2535
|
+
* `manage: true` facets happen on the FAQ Library list.
|
|
2536
|
+
*/
|
|
2537
|
+
function createTaxonomy(options) {
|
|
2538
|
+
const access = requireAccess(options);
|
|
2539
|
+
const hidden = options.hidden ?? true;
|
|
2540
|
+
return {
|
|
2541
|
+
slug: options.slug,
|
|
2542
|
+
labels: options.labels,
|
|
2543
|
+
admin: {
|
|
2544
|
+
useAsTitle: "name",
|
|
2545
|
+
hidden
|
|
2546
|
+
},
|
|
2547
|
+
versions: true,
|
|
2548
|
+
access: {
|
|
2549
|
+
read: access.read,
|
|
2550
|
+
create: access.update,
|
|
2551
|
+
update: access.update,
|
|
2552
|
+
delete: access.update,
|
|
2553
|
+
readVersions: access.update
|
|
2554
|
+
},
|
|
2555
|
+
fields: [{
|
|
2556
|
+
name: "name",
|
|
2557
|
+
type: "text",
|
|
2558
|
+
required: true,
|
|
2559
|
+
label: "Name"
|
|
2560
|
+
}]
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
//#endregion
|
|
2564
|
+
//#region src/questions/fields.ts
|
|
2565
|
+
/** Import-map string. A site runs `payload generate:importmap`. */
|
|
2566
|
+
const QUESTIONS_LIST = "@bison-lab/payload-core/admin#QuestionsList";
|
|
2567
|
+
//#endregion
|
|
2568
|
+
//#region src/questions/types.ts
|
|
2569
|
+
const QUESTIONS_SLUG = "questions";
|
|
2570
|
+
const QUESTIONS_FEATURE = "questions";
|
|
2571
|
+
//#endregion
|
|
2572
|
+
//#region src/questions/collection.ts
|
|
2573
|
+
function organizeByFields(entries) {
|
|
2574
|
+
return entries.map((entry) => ({
|
|
2575
|
+
name: entry.name,
|
|
2576
|
+
type: "relationship",
|
|
2577
|
+
relationTo: entry.collection,
|
|
2578
|
+
hasMany: true,
|
|
2579
|
+
label: entry.label
|
|
2580
|
+
}));
|
|
2581
|
+
}
|
|
2582
|
+
/**
|
|
2583
|
+
* One document per FAQ, drafts, a kit List that replaces Payload's stock
|
|
2584
|
+
* collection list. Used-on stays 0 until BIS-127 stores block
|
|
2585
|
+
* relationships (BIS-125 is the consume mockup).
|
|
2586
|
+
*/
|
|
2587
|
+
function createQuestions(options = {}) {
|
|
2588
|
+
const organizeBy = options.organizeBy ?? [];
|
|
2589
|
+
const slug = options.slug ?? "questions";
|
|
2590
|
+
const labels = options.labels ?? {
|
|
2591
|
+
singular: "FAQ",
|
|
2592
|
+
plural: "FAQ Library"
|
|
2593
|
+
};
|
|
2594
|
+
const hidden = hideUnlessFeature(QUESTIONS_FEATURE);
|
|
2595
|
+
const write = canUseFeature(QUESTIONS_FEATURE);
|
|
2596
|
+
return {
|
|
2597
|
+
slug,
|
|
2598
|
+
labels,
|
|
2599
|
+
admin: {
|
|
2600
|
+
group: "Content",
|
|
2601
|
+
useAsTitle: "question",
|
|
2602
|
+
hidden,
|
|
2603
|
+
listSearchableFields: ["question", "answer"],
|
|
2604
|
+
custom: { organizeBy },
|
|
2605
|
+
components: { views: { list: { Component: {
|
|
2606
|
+
path: QUESTIONS_LIST,
|
|
2607
|
+
clientProps: { organizeBy }
|
|
2608
|
+
} } } }
|
|
2609
|
+
},
|
|
2610
|
+
access: {
|
|
2611
|
+
read: authenticatedOrPublished,
|
|
2612
|
+
create: write,
|
|
2613
|
+
update: write,
|
|
2614
|
+
delete: write,
|
|
2615
|
+
readVersions: write
|
|
2616
|
+
},
|
|
2617
|
+
versions: { drafts: true },
|
|
2618
|
+
fields: [
|
|
2619
|
+
{
|
|
2620
|
+
name: "question",
|
|
2621
|
+
type: "text",
|
|
2622
|
+
required: true,
|
|
2623
|
+
label: "Question"
|
|
2624
|
+
},
|
|
2625
|
+
{
|
|
2626
|
+
name: "answer",
|
|
2627
|
+
type: "textarea",
|
|
2628
|
+
required: true,
|
|
2629
|
+
label: "Answer"
|
|
2630
|
+
},
|
|
2631
|
+
...organizeByFields(organizeBy)
|
|
2632
|
+
]
|
|
2633
|
+
};
|
|
2634
|
+
}
|
|
2289
2635
|
//#endregion
|
|
2290
2636
|
//#region src/plugins/redirects.ts
|
|
2291
2637
|
const REDIRECTS_SLUG = "redirects";
|
|
@@ -2842,6 +3188,6 @@ const documentTitleActions = definePlugin({
|
|
|
2842
3188
|
plugin: ({ config }) => withTitleActions(config)
|
|
2843
3189
|
});
|
|
2844
3190
|
//#endregion
|
|
2845
|
-
export { ADMIN_NAV, ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL, ADMIN_NAV_SLUG, BRAND_ASSETS_MIME_TYPES, BRAND_ASSETS_SLUG, CAPABILITIES, CAPABILITY_FEATURES, DEFAULT_ROLE_GRANTS, DEFAULT_ROLE_MATRIX, DESCRIPTION_LENGTH, DEVELOPER_DESCRIPTION, DOCUMENT_CREATE_NEW, DOCUMENT_TITLE_ACTIONS, DUPLICATE_ROLE_NAME_MESSAGE, DUPLICATE_ROLE_SLUG_MESSAGE, EXISTING_PARENT_MESSAGE, EXTERNAL_HREF_MESSAGE, FEATURES_MATRIX_FIELD, FEATURES_SLUG, FEATURE_GROUPS, FEATURE_GROUP_LABELS, FOOTER_COLUMNS_FIELD, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, INVALID_ROLE_NAME_MESSAGE, LAST_ADMIN_DELETE_MESSAGE, LAST_ADMIN_DEMOTE_MESSAGE, LAST_USERS_TICK_MESSAGE, LAYOUT_DESCRIPTION, LAYOUT_REQUIRED_LABEL, LAYOUT_REQUIRED_MESSAGE, LOOK_FIELD, MISSING_PACKAGE_FEATURES_MESSAGE, MISSING_SEED_ROLES_MESSAGE, NAVIGATION_DB_NAME, NAVIGATION_FEATURE, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, NEW_FOLDER_PARENT, PACKAGE_FEATURES, PACKAGE_FEATURE_SLUGS, PAGE_EDITOR_SYSTEM_KEYS, PAGE_TITLE_CELL, REDIRECTS_SLUG, ROLES, ROLES_FIELD, ROLES_FIELD_DESCRIPTION, ROLES_GLOBAL_DESCRIPTION, ROLES_GRANTS_FIELD, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL, ROLES_SLUG, ROLE_LABELS, ROLE_NAME_FIELD, ROLE_SLUG_FIELD, SHARE_IMAGE_SIZE, SLUG_FIELD, SLUG_UNLOCK_WARNING, SYSTEM_COLOR_KEYS, THEME_APPEARANCE_FIELD, THEME_APPEARANCE_SLUG, THEME_COLORS_SLUG, THEME_COLOR_FIELD, THEME_COLOR_SCALE_FIELD, THEME_CONTRAST_REPORT, THEME_DOCUMENT_CONTROLS, THEME_FEATURE_SLUGS, THEME_FONT_FIELD, THEME_GREY_SCALE_FIELD, THEME_IDENTITY_FALLBACK, THEME_IDENTITY_SLUG, THEME_LIBRARY_FIELD, THEME_PAIRING_FIELD, THEME_PREVIEW_BREAKPOINTS, THEME_PUBLISH_FIELD, THEME_SAVE_BUTTON, THEME_SECTION_HEADING, THEME_SLUG, THEME_TYPOGRAPHY_SLUG, adminNav, adminOnlyApiTab, allowedFeaturesForUser, applyRoleSlugsFromNames, authenticatedOrPublished, canManageBrand, canManageContent, canPublish, canUseFeature, colorTokenField, composeSlug, createAdminNav, createBrandAssets, createFeatures, createMedia, createNavigation, createPages, createRedirects, createRoles, createTheme, createUsers, defaultFeaturesFieldValue, defaultRolesFieldValue, deleteLibraryColor, developerOnlyAccess, documentCreateNew, documentTitle, documentTitleActions, featureCatalogue, featureGroupLabel, findColorTokens, findColorUsages, firstImageIn, getFeaturesMatrix, getNavigation, getRolesMatrix, hasCapability, hasFeature, hasGrant, hasRole, headerCtaEnabled, hideUnlessDeveloper, hideUnlessFeature, inferredFolders, isAdmin, isAdminOrSelf, isAuthenticated, isDeveloper, isDeveloperTab, isFeatureGroupId, isFeatureSlug, isLockedFeature, isPackageFeatureSlug, isPrivilegedRole, isRole, isRoleName, isRoleSlug, isValidExternalHref, lockSlugOnPublish, lookField, noIndexField, normalizeFooterDesktop, normalizeSlug, normalizeStoredRoles, pageEditorLooks, pageEditorTokens, parentPrefix, parseFeaturesMatrix, parseRolesMatrix, persistThemeChild, publishThemeChild, recordPublishedSlugRedirect, redirectPath, requireLayoutOnPublish, resetRolesMatrix, resolveAdminNav, resolveThemeIdentity, rewriteColorToken, rewriteColorTokens, rewriteColorUsages, roleDescription, roleLabel, roleSelectOptions, sanitizeRoleNameInput, sanitizeSvg, seedFeatures, seedRoleRows, seedRoles, seedTheme, seoPlugin, slugDepth, slugField, slugLeaf, slugifyRoleName, stampFeatureCatalogue, storedRoles, themeColorKeys, themeLibraryFromDoc, titleTemplate, truncateAtWord, validateExternalHref, validateFeaturesMatrix, validateFooterColumns, validateFooterSocialUrl, validateHeaderCta, validateRolesMatrix, writePublishedSlugRedirect };
|
|
3191
|
+
export { ADMIN_NAV, ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL, ADMIN_NAV_SLUG, BRAND_ASSETS_MIME_TYPES, BRAND_ASSETS_SLUG, CAPABILITIES, CAPABILITY_FEATURES, DEFAULT_ROLE_GRANTS, DEFAULT_ROLE_MATRIX, DESCRIPTION_LENGTH, DEVELOPER_DESCRIPTION, DOCUMENT_CREATE_NEW, DOCUMENT_TITLE_ACTIONS, DUPLICATE_ROLE_NAME_MESSAGE, DUPLICATE_ROLE_SLUG_MESSAGE, EXISTING_PARENT_MESSAGE, EXTERNAL_HREF_MESSAGE, FEATURES_MATRIX_FIELD, FEATURES_SLUG, FEATURE_GROUPS, FEATURE_GROUP_LABELS, FOOTER_COLUMNS_FIELD, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, INVALID_ROLE_NAME_MESSAGE, LAST_ADMIN_DELETE_MESSAGE, LAST_ADMIN_DEMOTE_MESSAGE, LAST_USERS_TICK_MESSAGE, LAYOUT_DESCRIPTION, LAYOUT_REQUIRED_LABEL, LAYOUT_REQUIRED_MESSAGE, LOOK_FIELD, MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST, MISSING_PACKAGE_FEATURES_MESSAGE, MISSING_SEED_ROLES_MESSAGE, NAVIGATION_DB_NAME, NAVIGATION_FEATURE, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, NEW_FOLDER_PARENT, PACKAGE_FEATURES, PACKAGE_FEATURE_SLUGS, PAGE_EDITOR_SYSTEM_KEYS, PAGE_TITLE_CELL, QUESTIONS_FEATURE, QUESTIONS_LIST, QUESTIONS_SLUG, REDIRECTS_SLUG, ROLES, ROLES_FIELD, ROLES_FIELD_DESCRIPTION, ROLES_GLOBAL_DESCRIPTION, ROLES_GRANTS_FIELD, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL, ROLES_SLUG, ROLE_LABELS, ROLE_NAME_FIELD, ROLE_SLUG_FIELD, SHARE_IMAGE_SIZE, SLUG_FIELD, SLUG_UNLOCK_WARNING, SYSTEM_COLOR_KEYS, THEME_APPEARANCE_FIELD, THEME_APPEARANCE_SLUG, THEME_COLORS_SLUG, THEME_COLOR_FIELD, THEME_COLOR_SCALE_FIELD, THEME_CONTRAST_REPORT, THEME_DOCUMENT_CONTROLS, THEME_FEATURE_SLUGS, THEME_FONT_FIELD, THEME_GREY_SCALE_FIELD, THEME_IDENTITY_FALLBACK, THEME_IDENTITY_SLUG, THEME_LIBRARY_FIELD, THEME_PAIRING_FIELD, THEME_PREVIEW_BREAKPOINTS, THEME_PUBLISH_FIELD, THEME_SAVE_BUTTON, THEME_SECTION_HEADING, THEME_SLUG, THEME_TYPOGRAPHY_SLUG, adminNav, adminOnlyApiTab, allowedFeaturesForUser, altFromFilename, applyRoleSlugsFromNames, authenticatedOrPublished, canManageBrand, canManageContent, canPublish, canUseFeature, colorTokenField, composeSlug, createAdminNav, createBrandAssets, createFeatures, createMedia, createNavigation, createPages, createQuestions, createRedirects, createRoles, createTaxonomy, createTheme, createUsers, defaultFeaturesFieldValue, defaultRolesFieldValue, deleteLibraryColor, developerOnlyAccess, documentCreateNew, documentTitle, documentTitleActions, featureCatalogue, featureGroupLabel, fillBlankAltFromFilename, findColorTokens, findColorUsages, firstImageIn, getFeaturesMatrix, getNavigation, getRolesMatrix, hasCapability, hasFeature, hasGrant, hasRole, headerCtaEnabled, hideUnlessDeveloper, hideUnlessFeature, inferredFolders, isAdmin, isAdminOrSelf, isAuthenticated, isDeveloper, isDeveloperTab, isFeatureGroupId, isFeatureSlug, isLockedFeature, isPackageFeatureSlug, isPrivilegedRole, isRole, isRoleName, isRoleSlug, isValidExternalHref, lockSlugOnPublish, lookField, noIndexField, normalizeFooterDesktop, normalizeSlug, normalizeStoredRoles, pageEditorLooks, pageEditorTokens, parentPrefix, parseFeaturesMatrix, parseRolesMatrix, persistThemeChild, publishThemeChild, recordPublishedSlugRedirect, redirectPath, replaceClientOriginalWithResizedFile, requireLayoutOnPublish, resetRolesMatrix, resolveAdminNav, resolveThemeIdentity, rewriteColorToken, rewriteColorTokens, rewriteColorUsages, roleDescription, roleLabel, roleSelectOptions, sanitizeRoleNameInput, sanitizeSvg, seedFeatures, seedRoleRows, seedRoles, seedTheme, seoPlugin, slugDepth, slugField, slugLeaf, slugifyRoleName, stampFeatureCatalogue, storedRoles, themeColorKeys, themeLibraryFromDoc, titleTemplate, truncateAtWord, validateExternalHref, validateFeaturesMatrix, validateFooterColumns, validateFooterSocialUrl, validateHeaderCta, validateRolesMatrix, writePublishedSlugRedirect };
|
|
2846
3192
|
|
|
2847
3193
|
//# sourceMappingURL=index.mjs.map
|