@bison-lab/payload-core 4.6.0 → 4.9.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 +44 -7
- package/dist/admin.d.mts +18 -2
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +120 -24
- package/dist/admin.mjs.map +1 -1
- package/dist/index.d.mts +146 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +350 -54
- package/dist/index.mjs.map +1 -1
- package/dist/navigation.mjs +1 -1
- package/dist/{published-BltDUYZv.mjs → published-BvTPQqAF.mjs} +9 -9
- package/dist/published-BvTPQqAF.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/published-BltDUYZv.mjs.map +0 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["payloadSeoPlugin","resolveScopes","eachCollectionDoc","readGlobal","slugsOf","isAccessArgs","resolveAccess","slugsOf","catalog"],"sources":["../src/seo/fields.ts","../src/seo/text.ts","../src/seo/plugin.ts","../src/theme/appearance-labels.ts","../src/theme/color-usages.ts","../src/theme/color-usage-endpoints.ts","../src/features/types.ts","../src/roles/types.ts","../src/features/matrix.ts","../src/roles/matrix.ts","../src/roles/access.ts","../src/features/access.ts","../src/theme/global.ts","../src/brand-assets/sanitize.ts","../src/brand-assets/collection.ts","../src/theme/seed.ts","../src/theme/publish.ts","../src/admin/document-controls.ts","../src/roles/fields.ts","../src/roles/global.ts","../src/roles/seed.ts","../src/block-library/types.ts","../src/block-library/catalogue.ts","../src/block-library/fields.ts","../src/block-library/holders.ts","../src/block-library/global.ts","../src/features/fields.ts","../src/features/global.ts","../src/features/seed.ts","../src/collections/root-page-key.ts","../src/fields/slug.ts","../src/collections/root-page.ts","../src/collections/pages.ts","../src/collections/users.ts","../src/collections/media-alt.ts","../src/collections/media-constants.ts","../src/collections/media-in-use.ts","../src/collections/media.ts","../src/taxonomy/collection.ts","../src/questions/fields.ts","../src/questions/lexical-text.ts","../src/questions/types.ts","../src/questions/collection.ts","../src/plugins/redirects.ts","../src/admin-nav/fields.ts","../src/admin-nav/types.ts","../src/admin-nav/validate.ts","../src/admin-nav/global.ts","../src/admin-nav/plugin.ts","../src/admin-nav/resolve.ts","../src/navigation/global.ts","../src/plugins/admin-only-api-tab.ts","../src/plugins/document-title-actions.ts"],"sourcesContent":["import type { CheckboxField } from \"payload\";\n\n/**\n * The index switch, last in the SEO tab. Off by default: a page is public\n * unless an editor says otherwise. `pageMetadata` turns it into\n * `noindex, nofollow`; a site's sitemap should filter on it too.\n */\nexport const noIndexField: CheckboxField = {\n name: \"noIndex\",\n type: \"checkbox\",\n label: \"Hide this page from search engines\",\n defaultValue: false,\n admin: {\n description:\n \"Search engines will not list this page and the sitemap will leave it out. Anyone with the link can still open it.\",\n },\n};\n","/** The length a search result shows of a description before it is cut. */\nexport const DESCRIPTION_LENGTH = 155;\n\n/**\n * Prose cut to `max` characters at a word, with an ellipsis, so a generated\n * description does not end mid-syllable. Text that fits is returned trimmed\n * and whole. A first word longer than `max` is cut mid-word, since there is\n * no boundary to cut at.\n */\nexport function truncateAtWord(text: string, max = DESCRIPTION_LENGTH): string {\n const trimmed = text.trim();\n if (trimmed.length <= max) return trimmed;\n const cut = trimmed.slice(0, max);\n const lastSpace = cut.lastIndexOf(\" \");\n return `${lastSpace > 0 ? cut.slice(0, lastSpace) : cut}…`;\n}\n","import { seoPlugin as payloadSeoPlugin } from \"@payloadcms/plugin-seo\";\nimport type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n} from \"@payloadcms/plugin-seo/types\";\nimport type { CollectionSlug, Plugin, UploadCollectionSlug } from \"payload\";\n\nimport { noIndexField } from \"./fields\";\nimport { truncateAtWord } from \"./text\";\nimport { documentTitle } from \"./title\";\nimport type { MediaId } from \"./types\";\n\n/**\n * What the plugin reads off a document: its title, for the generated meta\n * title. The site's generated `Page` is assignable to this; the `urlFor`,\n * `describeFrom` and `imageFor` callbacks read the rest, typed as the site\n * chooses through `TDoc`.\n */\nexport interface SeoDoc {\n title?: string | null;\n}\n\nexport interface SeoPluginOptions<TDoc extends SeoDoc = SeoDoc> {\n /** Appended to every generated title: `<page title> | <siteName>`. */\n siteName: string;\n /**\n * The absolute public URL of a document from the form's data, for the\n * search-result preview and the Generate button beside it. `undefined`\n * when the document has no address yet (a slug not typed), which leaves\n * the preview empty rather than pointing at the home page.\n */\n urlFor: (doc: TDoc) => string | undefined;\n /**\n * Prose to cut a generated description from, the first plain-text field a\n * page always has near the top (a hero's body, say). Cut at a word near\n * 155 characters. Without it the Generate button fills in nothing.\n */\n describeFrom?: (doc: TDoc) => string | null | undefined;\n /**\n * An image already on the page, for the Meta Image Generate button, so an\n * editor need not upload a second copy of the hero picture. `firstImageIn`\n * walks block rows for one. The upload chooser stays, so any other media\n * row can still be picked.\n */\n imageFor?: (doc: TDoc) => MediaId | null | undefined;\n /** Collections that get the SEO tab. Default `['pages']`. */\n collections?: CollectionSlug[];\n /** The upload collection the meta image comes from. Default `'media'`. */\n uploadsCollection?: UploadCollectionSlug;\n}\n\n/**\n * `@payloadcms/plugin-seo` configured the Bison Lab way: an SEO tab beside a\n * Content tab (never below the block editor), holding the overview with its\n * character counts, meta title, description and image with Generate buttons,\n * the search-result preview, and the `noIndex` switch.\n *\n * Every string the tab generates comes from the options, so a site spells\n * its name and its URL scheme once. Pin `@payloadcms/plugin-seo` to the same\n * version as `payload` in the site; the plugin's admin components are\n * resolved from the site's import map, so run `payload generate:importmap`\n * after adding it.\n */\nexport function seoPlugin<TDoc extends SeoDoc = SeoDoc>({\n siteName,\n urlFor,\n describeFrom,\n imageFor,\n collections = [\"pages\"],\n uploadsCollection = \"media\",\n}: SeoPluginOptions<TDoc>): Plugin {\n const generateTitle: GenerateTitle<TDoc> = ({ doc }) =>\n doc?.title ? documentTitle(siteName, doc.title) : \"\";\n const generateDescription: GenerateDescription<TDoc> = ({ doc }) =>\n truncateAtWord(describeFrom?.(doc) ?? \"\");\n const generateURL: GenerateURL<TDoc> = ({ doc }) => urlFor(doc) ?? \"\";\n // Only when the site can name one: the button appears with the function.\n const generateImage: GenerateImage<TDoc> | undefined = imageFor\n ? ({ doc }) => imageFor(doc) ?? \"\"\n : undefined;\n\n return payloadSeoPlugin({\n collections,\n uploadsCollection,\n tabbedUI: true,\n generateTitle,\n generateDescription,\n generateURL,\n ...(generateImage ? { generateImage } : {}),\n fields: ({ defaultFields }) => [...defaultFields, noIndexField],\n });\n}\n\n/**\n * The first image among some block rows, as a media id, for `imageFor`. Each\n * row is checked for `field` holding either a bare id or a populated upload\n * document; rows without one are skipped. Pass the page's hero and layout\n * together (`[...doc.hero, ...doc.layout]`) to search in reading order.\n */\nexport function firstImageIn(\n blocks: unknown,\n field = \"image\",\n): MediaId | undefined {\n if (!Array.isArray(blocks)) return undefined;\n for (const block of blocks) {\n if (typeof block !== \"object\" || block === null) continue;\n const value = (block as Record<string, unknown>)[field];\n const id =\n typeof value === \"object\" && value !== null && \"id\" in value\n ? (value as { id: unknown }).id\n : value;\n if (typeof id === \"number\" || (typeof id === \"string\" && id !== \"\"))\n return id;\n }\n return undefined;\n}\n","/**\n * Named choices the Appearance child shows. Values stay the token presets;\n * labels match the mock workflow (Soft → pill, Gentle → minimal, Balanced\n * → default, Follow device → system). No rem, ms, or CSS variable tables.\n */\nexport const APPEARANCE_CHOICES = {\n defaultTheme: {\n light: { label: \"Light\", hint: \"Always opens in light mode\" },\n dark: { label: \"Dark\", hint: \"Always opens in dark mode\" },\n system: { label: \"Follow device\", hint: \"Matches the visitor’s system setting\" },\n },\n radius: {\n sharp: { label: \"Sharp\", hint: \"Crisp and structured\" },\n subtle: { label: \"Subtle\", hint: \"Clean with a little softness\" },\n rounded: { label: \"Rounded\", hint: \"Friendly and contemporary\" },\n pill: { label: \"Soft\", hint: \"Very rounded and expressive\" },\n },\n shadow: {\n flat: { label: \"Flat\", hint: \"Minimal visual depth\" },\n subtle: { label: \"Subtle\", hint: \"Light separation between surfaces\" },\n elevated: { label: \"Elevated\", hint: \"More noticeable layering and depth\" },\n },\n motion: {\n snappy: { label: \"Quick\", hint: \"Fast and responsive\" },\n smooth: { label: \"Smooth\", hint: \"Balanced and natural\" },\n minimal: { label: \"Gentle\", hint: \"Slower and more relaxed\" },\n },\n density: {\n compact: { label: \"Compact\", hint: \"Fits more content on screen\" },\n default: { label: \"Balanced\", hint: \"Comfortable for most sites\" },\n spacious: { label: \"Spacious\", hint: \"More breathing room and larger controls\" },\n },\n} as const;\n\nexport const APPEARANCE_FAMILY_COPY: Record<\n keyof typeof APPEARANCE_CHOICES,\n { title: string; hint: string }\n> = {\n defaultTheme: {\n title: \"Default theme\",\n hint: \"Choose how the public site opens for visitors.\",\n },\n radius: {\n title: \"Corner style\",\n hint: \"Controls the shape of buttons, inputs, cards, and panels across the site.\",\n },\n shadow: {\n title: \"Depth\",\n hint: \"Choose how much cards and floating elements stand out from the page.\",\n },\n motion: {\n title: \"Motion\",\n hint: \"Controls how quickly menus, cards, and interface transitions move.\",\n },\n density: {\n title: \"Spacing\",\n hint: \"Choose how compact or roomy forms, buttons, cards, and page sections feel.\",\n },\n};\n\nexport const FONT_ROLE_COPY = {\n heading: {\n label: \"Heading font\",\n hint: \"Used for page titles, section headings, and cards\",\n },\n body: {\n label: \"Body font\",\n hint: \"Used for paragraphs, navigation, forms, and buttons\",\n },\n} as const;\n\nexport const SYSTEM_COLOR_COPY: Record<\n \"primary\" | \"secondary\" | \"accent\" | \"highlight\" | \"success\" | \"destructive\",\n { label: string; hint: string; group: \"brand\" | \"status\" }\n> = {\n primary: { label: \"Primary\", hint: \"Primary actions and key links\", group: \"brand\" },\n secondary: { label: \"Secondary\", hint: \"Supporting accents and eyebrows\", group: \"brand\" },\n accent: { label: \"Accent\", hint: \"Dark brand surfaces\", group: \"brand\" },\n highlight: { label: \"Highlight\", hint: \"Promotional and emphasis fills\", group: \"brand\" },\n success: {\n label: \"Success\",\n hint: \"Success messages and confirmations\",\n group: \"status\",\n },\n destructive: {\n label: \"Destructive\",\n hint: \"Errors, dangerous actions, and destructive confirmations\",\n group: \"status\",\n },\n};\n","import { findColorTokens, rewriteColorTokens } from \"./color-tokens\";\nimport { pageEditorLooks } from \"./looks\";\nimport { THEME_SLUG, type ThemeDoc } from \"./types\";\n\n/** Theme-store REST path. LibraryField calls `/api/globals/theme` + this. */\nexport const COLOR_USAGES_PATH = \"/color-usages\";\n\nexport interface ColorUsagesList {\n collections?: string[];\n globals?: string[];\n}\n\n/**\n * `true` scans every registered collection and global at request time\n * (Payload internals and Theme itself are skipped). A list still names\n * slugs. Omit or pass empty: every additional color is unused.\n */\nexport type ColorUsagesOption = true | ColorUsagesList;\n\nexport interface ColorUsage {\n collection?: string;\n global?: string;\n id?: string | number;\n path: string;\n token: string;\n}\n\ntype FindResult = { docs: Record<string, unknown>[]; totalPages?: number; page?: number };\n\ntype Slugged = { slug?: string };\n\nexport interface ColorUsagePayload {\n find: (args: {\n collection: string;\n draft?: boolean;\n depth?: number;\n limit?: number;\n page?: number;\n overrideAccess?: boolean;\n }) => Promise<FindResult>;\n findGlobal: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n }) => Promise<Record<string, unknown> | ThemeDoc | null | undefined>;\n update: (args: {\n collection: string;\n id: string | number;\n data: Record<string, unknown>;\n draft?: boolean;\n overrideAccess?: boolean;\n }) => Promise<unknown>;\n updateGlobal: (args: {\n slug: string;\n data: Record<string, unknown>;\n draft?: boolean;\n overrideAccess?: boolean;\n }) => Promise<unknown>;\n collections?: Record<string, unknown>;\n globals?: { config?: Slugged[] };\n config?: {\n collections?: Slugged[];\n globals?: Slugged[];\n };\n}\n\n/**\n * Walk every current document in the resolved collections and globals\n * (drafts included). A color only on an unpublished page is still in use.\n */\nexport async function findColorUsages(\n payload: ColorUsagePayload,\n scopes: ColorUsagesOption | undefined,\n key: string,\n): Promise<ColorUsage[]> {\n const { collections, globals } = resolveScopes(payload, scopes);\n const usages: ColorUsage[] = [];\n for (const collection of collections) {\n for await (const doc of eachCollectionDoc(payload, collection)) {\n for (const hit of findColorTokens(doc, key)) {\n usages.push({ collection, id: idOf(doc), path: hit.path, token: hit.token });\n }\n }\n }\n for (const slug of globals) {\n const doc = await readGlobal(payload, slug);\n if (!doc) continue;\n for (const hit of findColorTokens(doc, key)) {\n usages.push({ global: slug, path: hit.path, token: hit.token });\n }\n }\n return usages;\n}\n\nexport async function rewriteColorUsages(\n payload: ColorUsagePayload,\n scopes: ColorUsagesOption | undefined,\n fromKey: string,\n toKey: string,\n): Promise<void> {\n const { collections, globals } = resolveScopes(payload, scopes);\n for (const collection of collections) {\n for await (const doc of eachCollectionDoc(payload, collection)) {\n if (findColorTokens(doc, fromKey).length === 0) continue;\n const { id: _id, ...data } = rewriteColorTokens(doc, fromKey, toKey);\n const id = idOf(doc);\n if (id == null) continue;\n await payload.update({\n collection,\n id,\n data,\n draft: true,\n overrideAccess: true,\n });\n }\n }\n for (const slug of globals) {\n const doc = await readGlobal(payload, slug);\n if (!doc || findColorTokens(doc, fromKey).length === 0) continue;\n await payload.updateGlobal({\n slug,\n data: rewriteColorTokens(doc, fromKey, toKey) as Record<string, unknown>,\n draft: true,\n overrideAccess: true,\n });\n }\n}\n\nexport async function replacementKeys(payload: ColorUsagePayload, except: string): Promise<string[]> {\n const doc = (await payload.findGlobal({\n slug: THEME_SLUG,\n depth: 0,\n overrideAccess: true,\n })) as ThemeDoc | null;\n return pageEditorLooks(doc)\n .map((look) => look.value)\n .filter((key) => key !== except);\n}\n\nexport function resolveScopes(\n payload: ColorUsagePayload,\n scopes: ColorUsagesOption | undefined,\n): ColorUsagesList & { collections: string[]; globals: string[] } {\n if (scopes === true) return registeredScopes(payload);\n return {\n collections: scopes?.collections ?? [],\n globals: scopes?.globals ?? [],\n };\n}\n\nfunction registeredScopes(payload: ColorUsagePayload): { collections: string[]; globals: string[] } {\n return {\n collections: slugsOf(payload.config?.collections ?? payload.collections).filter(\n (slug) => !slug.startsWith(\"payload-\"),\n ),\n globals: slugsOf(payload.config?.globals ?? payload.globals?.config).filter(\n (slug) => slug !== THEME_SLUG,\n ),\n };\n}\n\nfunction slugsOf(value: Slugged[] | Record<string, unknown> | undefined): string[] {\n if (Array.isArray(value)) {\n return value.map((item) => item?.slug).filter((slug): slug is string => Boolean(slug));\n }\n if (value && typeof value === \"object\") return Object.keys(value);\n return [];\n}\n\nasync function readGlobal(\n payload: ColorUsagePayload,\n slug: string,\n): Promise<Record<string, unknown> | ThemeDoc | null | undefined> {\n try {\n return await payload.findGlobal({ slug, draft: true, depth: 0, overrideAccess: true });\n } catch {\n // A named slug that is not registered must not fail Colors Delete.\n return null;\n }\n}\n\nasync function* eachCollectionDoc(\n payload: ColorUsagePayload,\n collection: string,\n): AsyncGenerator<Record<string, unknown>> {\n let page = 1;\n for (;;) {\n let result: FindResult;\n try {\n result = await payload.find({\n collection,\n draft: true,\n depth: 0,\n limit: 100,\n page,\n overrideAccess: true,\n });\n } catch {\n return;\n }\n for (const doc of result.docs) yield doc;\n const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);\n if (page >= totalPages || result.docs.length === 0) break;\n page += 1;\n }\n}\n\nfunction idOf(doc: Record<string, unknown>): string | number | undefined {\n const id = doc.id;\n return typeof id === \"string\" || typeof id === \"number\" ? id : undefined;\n}\n","import type { Access, Endpoint, PayloadRequest } from \"payload\";\n\nimport {\n COLOR_USAGES_PATH,\n findColorUsages,\n replacementKeys,\n rewriteColorUsages,\n type ColorUsagePayload,\n type ColorUsagesOption,\n} from \"./color-usages\";\n\nexport { COLOR_USAGES_PATH };\n\nexport function colorUsageEndpoints(\n access: { update: Access },\n scopes: ColorUsagesOption | undefined,\n): Endpoint[] {\n return [\n {\n path: COLOR_USAGES_PATH,\n method: \"get\",\n handler: async (req) => {\n const denied = await denyUnlessUpdate(req, access.update);\n if (denied) return denied;\n const key = queryKey(req);\n if (!key) return Response.json({ error: \"key is required\" }, { status: 400 });\n const usages = await findColorUsages(req.payload as unknown as ColorUsagePayload, scopes, key);\n return Response.json({ usages });\n },\n },\n {\n path: COLOR_USAGES_PATH,\n method: \"post\",\n handler: async (req) => {\n const denied = await denyUnlessUpdate(req, access.update);\n if (denied) return denied;\n const body = (await readJson(req)) as { key?: unknown; replacement?: unknown } | null;\n const key = typeof body?.key === \"string\" ? body.key : \"\";\n const replacement = typeof body?.replacement === \"string\" ? body.replacement : \"\";\n if (!key || !replacement) {\n return Response.json({ error: \"key and replacement are required\" }, { status: 400 });\n }\n const live = await replacementKeys(req.payload as unknown as ColorUsagePayload, key);\n if (!live.includes(replacement)) {\n return Response.json(\n { error: \"Replacement must be a different live system or remaining custom key\" },\n { status: 400 },\n );\n }\n await rewriteColorUsages(req.payload as unknown as ColorUsagePayload, scopes, key, replacement);\n return Response.json({ ok: true });\n },\n },\n ];\n}\n\nasync function denyUnlessUpdate(req: PayloadRequest, update: Access): Promise<Response | null> {\n const allowed = await update({ req });\n if (allowed) return null;\n return Response.json({ error: \"Forbidden\" }, { status: 403 });\n}\n\nfunction queryKey(req: PayloadRequest): string {\n const fromQuery = req.query?.key;\n if (typeof fromQuery === \"string\") return fromQuery;\n if (Array.isArray(fromQuery) && typeof fromQuery[0] === \"string\") return fromQuery[0];\n if (req.url) {\n try {\n return new URL(req.url, \"http://local\").searchParams.get(\"key\") ?? \"\";\n } catch {\n return \"\";\n }\n }\n return \"\";\n}\n\nasync function readJson(req: PayloadRequest): Promise<unknown> {\n if (typeof req.json === \"function\") return req.json();\n return null;\n}\n","export const FEATURES_SLUG = \"features\";\n\nexport const FEATURE_GROUPS = [\"pages\", \"media\", \"theme\", \"users\"] as const;\n\nexport type FeatureGroupId = (typeof FEATURE_GROUPS)[number];\n\nexport const FEATURE_GROUP_LABELS: Record<FeatureGroupId, string> = {\n pages: \"Pages\",\n media: \"Media\",\n theme: \"Theme\",\n users: \"Users\",\n};\n\nexport const PACKAGE_FEATURE_SLUGS = [\n \"content\",\n \"publish\",\n \"media\",\n \"users\",\n \"roles\",\n] as const;\n\nexport type PackageFeatureSlug = (typeof PACKAGE_FEATURE_SLUGS)[number];\n\nexport interface PackageFeature {\n slug: PackageFeatureSlug;\n label: string;\n group: FeatureGroupId;\n defaultReleased: boolean;\n}\n\n/**\n * Package catalogue. Features itself is not a row — that screen is\n * Developer-only in code. Theme is not a row either: every site has the\n * Theme Global, and who may edit it is the Roles grant `theme`. Empty\n * Global falls back to these defaults.\n */\nexport const PACKAGE_FEATURES: readonly PackageFeature[] = [\n { slug: \"content\", label: \"Content\", group: \"pages\", defaultReleased: true },\n { slug: \"publish\", label: \"Publish\", group: \"pages\", defaultReleased: true },\n { slug: \"media\", label: \"Media\", group: \"media\", defaultReleased: true },\n { slug: \"users\", label: \"Users\", group: \"users\", defaultReleased: true },\n { slug: \"roles\", label: \"Roles\", group: \"users\", defaultReleased: true },\n];\n\n/** A site-only row. Other sites never see this slug. */\nexport interface FeatureExtra {\n slug: string;\n label: string;\n group?: FeatureGroupId;\n defaultReleased?: boolean;\n}\n\nexport interface FeatureRow {\n id?: string | null;\n slug: string;\n label?: string | null;\n group?: string | null;\n released: boolean;\n}\n\nexport interface FeaturesDoc {\n features?: FeatureRow[] | null;\n}\n\nexport function isFeatureGroupId(value: unknown): value is FeatureGroupId {\n return typeof value === \"string\" && (FEATURE_GROUPS as readonly string[]).includes(value);\n}\n\nexport function isPackageFeatureSlug(value: unknown): value is PackageFeatureSlug {\n return typeof value === \"string\" && (PACKAGE_FEATURE_SLUGS as readonly string[]).includes(value);\n}\n\nexport function isFeatureSlug(value: unknown): value is string {\n return typeof value === \"string\" && /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(value);\n}\n\n/** @deprecated Locks are gone; the release switch is the valve. */\nexport function isLockedFeature(_slug: string, _locked?: boolean | null): boolean {\n return false;\n}\n","/**\n * The Roles Global a site's generated types will describe. Optional and\n * nullable, no index signature: a generated Global is assignable to this,\n * never the reverse.\n */\n\nexport const ROLES = [\"developer\", \"admin\", \"designer\", \"author\"] as const;\n\nexport type Role = (typeof ROLES)[number];\n\nexport const ROLE_LABELS: Record<Role, string> = {\n developer: \"Developer\",\n admin: \"Admin\",\n designer: \"Designer\",\n author: \"Author\",\n};\n\n/** Capability aliases over feature grants. Brand is the Theme grant. */\nexport const CAPABILITIES = [\"content\", \"brand\", \"publish\", \"users\"] as const;\n\nexport type Capability = (typeof CAPABILITIES)[number];\n\n/** One Roles grant. Opens the Theme document and brand-assets. Not a Features row. */\nexport const THEME_FEATURE_SLUGS = [\"theme\"] as const;\n\n/**\n * Grants stored before Theme was one row. Reading any of them is the\n * Theme grant, so a Designer who already had Colors keeps Theme.\n */\nexport const LEGACY_THEME_FEATURE_SLUGS = [\n \"theme-colors\",\n \"theme-typography\",\n \"theme-appearance\",\n \"theme-identity\",\n \"brand-assets\",\n] as const;\n\nexport const CAPABILITY_FEATURES: Record<Capability, readonly string[]> = {\n content: [\"content\"],\n publish: [\"publish\"],\n users: [\"users\"],\n brand: THEME_FEATURE_SLUGS,\n};\n\nexport const DEFAULT_ROLE_GRANTS: Record<Role, readonly string[]> = {\n developer: [],\n admin: [\"content\", \"publish\", \"media\", \"users\", \"roles\"],\n designer: [\n \"content\",\n \"media\",\n ...THEME_FEATURE_SLUGS,\n \"users\",\n \"roles\",\n ],\n author: [\"content\", \"media\"],\n};\n\n/**\n * A site-defined row passed into `createRoles({ extras })`. The slug is the\n * stored key; the label is what Settings → Roles and Users show.\n */\nexport interface RoleExtra {\n role: string;\n label: string;\n grants?: readonly string[];\n}\n\nexport interface RoleRow {\n id?: string | null;\n role: string;\n label?: string | null;\n grants: string[];\n}\n\nexport interface RolesDoc {\n roles?: RoleRow[] | null;\n}\n\n/**\n * `req.user` as Payload hands it over. Structural so this module never\n * imports a site's generated `User`. `roles` is optional because a row\n * that predates the field must come back powerless.\n */\nexport type MaybeUser = {\n id?: string | number;\n roles?: readonly string[] | null;\n /** Feature slugs this login may use, stamped onto the JWT at read. */\n allowedFeatures?: readonly string[] | null;\n} | null | undefined;\n\nexport function isRole(value: unknown): value is Role {\n return typeof value === \"string\" && (ROLES as readonly string[]).includes(value);\n}\n\n/** Lowercase slug from a letters-and-spaces name: `designer`, `the-designer`. */\nexport function isRoleSlug(value: unknown): value is string {\n return typeof value === \"string\" && /^[a-z]+(-[a-z]+)*$/.test(value);\n}\n\n/** Display name: letters and single spaces only. `The Greatest Designer`. */\nexport function isRoleName(value: unknown): value is string {\n return typeof value === \"string\" && /^[A-Za-z]+(?: [A-Za-z]+)*$/.test(value.trim());\n}\n\n/** Strip digits and punctuation as the name is typed. Trailing space stays. */\nexport function sanitizeRoleNameInput(value: string): string {\n return value.replace(/[^A-Za-z ]/g, \"\").replace(/ {2,}/g, \" \");\n}\n\n/** Name → stored key. `The Greatest Designer` → `the-greatest-designer`. */\nexport function slugifyRoleName(value: unknown): string {\n if (typeof value !== \"string\") return \"\";\n return value\n .trim()\n .toLowerCase()\n .replace(/[^a-z]+/g, \"-\")\n .replace(/^-|-$/g, \"\");\n}\n\nexport function roleLabel(role: string, label?: string | null): string {\n const trimmed = typeof label === \"string\" ? label.trim() : \"\";\n if (trimmed) return trimmed;\n return isRole(role) ? ROLE_LABELS[role] : role;\n}\n\nexport function defaultGrantsForRole(role: string, extraGrants?: readonly string[]): string[] {\n if (isRole(role)) return [...DEFAULT_ROLE_GRANTS[role]];\n return extraGrants ? [...extraGrants] : [];\n}\n","import {\n FEATURE_GROUP_LABELS,\n isFeatureGroupId,\n isFeatureSlug,\n PACKAGE_FEATURES,\n type FeatureExtra,\n type FeatureGroupId,\n type FeatureRow,\n type PackageFeature,\n} from \"./types\";\nimport { LEGACY_THEME_FEATURE_SLUGS } from \"../roles/types\";\n\nexport const MISSING_PACKAGE_FEATURES_MESSAGE =\n \"Features must include Content, Publish, Media, Users, and Roles.\";\n\nexport interface FeatureCatalogueEntry {\n slug: string;\n label: string;\n group: FeatureGroupId;\n defaultReleased: boolean;\n}\n\nexport function featureCatalogue(extras: readonly FeatureExtra[] = []): FeatureCatalogueEntry[] {\n return [\n ...PACKAGE_FEATURES.map((feature) => ({ ...feature })),\n ...extras.map((extra) => ({\n slug: extra.slug,\n label: extra.label,\n group: extra.group ?? \"users\",\n defaultReleased: extra.defaultReleased ?? false,\n })),\n ];\n}\n\nexport function defaultFeaturesFieldValue(extras: readonly FeatureExtra[] = []): FeatureRow[] {\n return featureCatalogue(extras).map((feature) => ({\n id: feature.slug,\n slug: feature.slug,\n label: feature.label,\n group: feature.group,\n released: feature.defaultReleased,\n }));\n}\n\nexport function stampFeatureCatalogue(\n value: unknown,\n extras: readonly FeatureExtra[] = [],\n): FeatureRow[] {\n const bySlug = new Map(featureCatalogue(extras).map((feature) => [feature.slug, feature]));\n if (!Array.isArray(value)) return defaultFeaturesFieldValue(extras);\n return value.flatMap((item) => {\n if (!item || typeof item !== \"object\") return [];\n const slug = \"slug\" in item && typeof item.slug === \"string\" ? item.slug : \"\";\n const feature = bySlug.get(slug);\n if (!feature) return [];\n return [\n {\n id: feature.slug,\n slug: feature.slug,\n label: feature.label,\n group: feature.group,\n released: Boolean(\"released\" in item && item.released),\n },\n ];\n });\n}\n\nexport function parseFeaturesMatrix(\n value: unknown,\n): { ok: true; rows: FeatureRow[] } | { ok: false; message: string } {\n if (!Array.isArray(value) || value.length === 0) {\n return { ok: false, message: MISSING_PACKAGE_FEATURES_MESSAGE };\n }\n\n const rows: FeatureRow[] = [];\n const seen = new Set<string>();\n\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n const slug = \"slug\" in item ? item.slug : undefined;\n if (!isFeatureSlug(slug) || seen.has(slug)) continue;\n seen.add(slug);\n const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);\n const label =\n \"label\" in item && typeof item.label === \"string\"\n ? item.label\n : (pack?.label ?? slug);\n const group =\n \"group\" in item && isFeatureGroupId(item.group) ? item.group : (pack?.group ?? \"users\");\n rows.push({\n id: slug,\n slug,\n label,\n group,\n released: Boolean(\"released\" in item && item.released),\n });\n }\n\n if (PACKAGE_FEATURES.some((feature) => !seen.has(feature.slug))) {\n return { ok: false, message: MISSING_PACKAGE_FEATURES_MESSAGE };\n }\n return { ok: true, rows };\n}\n\nexport function validateFeaturesMatrix(\n value: unknown,\n extras: readonly FeatureExtra[] = [],\n): true | string {\n const parsed = parseFeaturesMatrix(value);\n if (!parsed.ok) return parsed.message;\n const allowed = new Set(featureCatalogue(extras).map((feature) => feature.slug));\n const legacy = new Set<string>(LEGACY_THEME_FEATURE_SLUGS);\n // Retired Theme rows stay valid until beforeChange drops them. The admin\n // form calls validate without field hooks, so rejecting them blocks Save.\n if (parsed.rows.some((row) => !allowed.has(row.slug) && !legacy.has(row.slug))) {\n return MISSING_PACKAGE_FEATURES_MESSAGE;\n }\n return true;\n}\n\nexport function featureGroupLabel(group: string): string {\n return isFeatureGroupId(group) ? FEATURE_GROUP_LABELS[group] : group;\n}\n\nexport function packageFeatureLabel(slug: string, extras: readonly FeatureExtra[] = []): string {\n if (slug === \"theme\") return \"Theme\";\n const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);\n if (pack) return pack.label;\n const extra = extras.find((feature) => feature.slug === slug);\n return extra?.label ?? slug;\n}\n\nexport function isGroupOnlySlug(slug: string): boolean {\n return isFeatureGroupId(slug) && !PACKAGE_FEATURES.some((feature) => feature.slug === slug);\n}\n\nexport type { PackageFeature };\n","import { packageFeatureLabel } from \"../features/matrix\";\nimport { isFeatureSlug } from \"../features/types\";\nimport {\n CAPABILITY_FEATURES,\n defaultGrantsForRole,\n isRole,\n isRoleName,\n isRoleSlug,\n LEGACY_THEME_FEATURE_SLUGS,\n ROLE_LABELS,\n roleLabel,\n ROLES,\n slugifyRoleName,\n type Capability,\n type RoleExtra,\n type RoleRow,\n} from \"./types\";\n\nexport const ROLES_SLUG = \"roles\";\n\nexport const ROLES_GLOBAL_DESCRIPTION = \"Who may do what. Drag to change rank.\";\n\nexport const ROLES_FIELD_DESCRIPTION =\n \"Drag to change rank. Ticks are features released on Features, plus Theme. Developer has the whole catalogue.\"\n\n/**\n * Default rank and grants. Developer is implicit (empty grants). The\n * Theme grant defaults to Designer.\n */\nexport const DEFAULT_ROLE_MATRIX: readonly RoleRow[] = ROLES.map((role) => ({\n role,\n grants: defaultGrantsForRole(role),\n}));\n\nexport const DEVELOPER_DESCRIPTION =\n \"Everything, including features not released for assignment.\";\n\nexport const LAST_USERS_TICK_MESSAGE =\n \"Keep Users granted on at least one of Admin or Developer.\";\n\nexport const MISSING_SEED_ROLES_MESSAGE = \"Roles must include Developer.\";\n\nexport const DUPLICATE_ROLE_SLUG_MESSAGE = \"Each role needs a unique slug.\";\n\nexport const DUPLICATE_ROLE_NAME_MESSAGE = \"Each role needs a unique name.\";\n\nexport const INVALID_ROLE_NAME_MESSAGE = \"Use letters and spaces only.\";\n\nconst LEGACY_THEME_GRANTS = new Set<string>(LEGACY_THEME_FEATURE_SLUGS);\n\nfunction uniqueSlugs(values: readonly unknown[]): string[] {\n const slugs: string[] = [];\n for (const value of values) {\n if (typeof value === \"string\" && isFeatureSlug(value) && !slugs.includes(value)) slugs.push(value);\n }\n return slugs;\n}\n\n/** One Theme grant. A stored Colors or brand-assets tick is that grant. */\nfunction collapseThemeGrant(slugs: readonly string[]): string[] {\n let theme = false;\n const next: string[] = [];\n for (const slug of slugs) {\n if (slug === \"theme\" || LEGACY_THEME_GRANTS.has(slug)) {\n theme = true;\n continue;\n }\n next.push(slug);\n }\n if (theme) next.push(\"theme\");\n return next;\n}\n\n/** Read stored grants, or rebuild them from the old capability ticks. */\nexport function grantsFromStoredRole(item: object): string[] {\n if (\"grants\" in item && Array.isArray(item.grants)) return collapseThemeGrant(uniqueSlugs(item.grants));\n const grants: string[] = [];\n if (\"content\" in item && item.content) {\n grants.push(\"content\", \"media\");\n }\n if (\"publish\" in item && item.publish) grants.push(\"publish\");\n if (\"users\" in item && item.users) grants.push(\"users\", \"roles\");\n if (\"brand\" in item && item.brand) grants.push(\"theme\");\n return collapseThemeGrant(uniqueSlugs(grants));\n}\n\nexport function seedRoleRows(extras: readonly RoleExtra[] = []): RoleRow[] {\n return [\n ...DEFAULT_ROLE_MATRIX.map((row) => ({\n ...row,\n grants: [...row.grants],\n label: isRole(row.role) ? ROLE_LABELS[row.role] : row.role,\n })),\n ...extras.map((extra) => ({\n role: extra.role,\n label: extra.label,\n grants: extra.grants ? [...extra.grants] : [],\n })),\n ];\n}\n\nexport function defaultRolesFieldValue(extras: readonly RoleExtra[] = []): RoleRow[] {\n return seedRoleRows(extras).map((row) => ({ id: row.role, ...row }));\n}\n\nfunction readRoleRow(item: object): RoleRow | { error: string } {\n const role = \"role\" in item ? item.role : undefined;\n if (typeof role !== \"string\" || role.trim() === \"\") return { error: DUPLICATE_ROLE_SLUG_MESSAGE };\n if (!isRoleSlug(role)) return { error: DUPLICATE_ROLE_SLUG_MESSAGE };\n const label = \"label\" in item && typeof item.label === \"string\" ? item.label : undefined;\n return {\n id: role,\n role,\n label: roleLabel(role, label),\n grants: grantsFromStoredRole(item),\n };\n}\n\nexport function parseRolesMatrix(\n value: unknown,\n): { ok: true; rows: RoleRow[] } | { ok: false; message: string } {\n if (!Array.isArray(value)) {\n return { ok: false, message: MISSING_SEED_ROLES_MESSAGE };\n }\n\n const rows: RoleRow[] = [];\n const seen = new Set<string>();\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n // An Add Role row starts with no slug. Skip it so form-state can\n // build the fields; the slug field still refuses an empty save.\n const role = \"role\" in item ? item.role : undefined;\n if (typeof role !== \"string\" || role.trim() === \"\") continue;\n const parsed = readRoleRow(item);\n if (\"error\" in parsed) return { ok: false, message: parsed.error };\n if (seen.has(parsed.role)) return { ok: false, message: DUPLICATE_ROLE_SLUG_MESSAGE };\n seen.add(parsed.role);\n rows.push(parsed);\n }\n\n if (!seen.has(\"developer\")) {\n return { ok: false, message: MISSING_SEED_ROLES_MESSAGE };\n }\n return { ok: true, rows };\n}\n\nexport function roleHasGrant(row: RoleRow, slug: string): boolean {\n if (row.role === \"developer\") return true;\n return row.grants.includes(slug);\n}\n\nexport function roleHasCapability(row: RoleRow, capability: Capability): boolean {\n if (row.role === \"developer\") return true;\n return CAPABILITY_FEATURES[capability].some((slug) => row.grants.includes(slug));\n}\n\n/**\n * Mint a slug from the name only when the row has none yet. An existing\n * key — seed or custom — stays put so a rename cannot orphan users.\n */\nexport function applyRoleSlugsFromNames(value: unknown): unknown {\n if (!Array.isArray(value)) return value;\n return value.map((item) => {\n if (!item || typeof item !== \"object\") return item;\n const row = item as RoleRow;\n if (isRoleSlug(row.role)) return item;\n const slug = slugifyRoleName(row.label);\n return isRoleSlug(slug) ? { ...row, role: slug } : item;\n });\n}\n\nfunction hasDuplicateRoleNames(value: unknown): boolean {\n if (!Array.isArray(value)) return false;\n const seen = new Set<string>();\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n const role = \"role\" in item && typeof item.role === \"string\" ? item.role : \"\";\n const raw = \"label\" in item && typeof item.label === \"string\" ? item.label : \"\";\n const name = raw.trim() || (isRole(role) ? ROLE_LABELS[role] : \"\");\n if (!name) continue;\n const key = name.toLowerCase();\n if (seen.has(key)) return true;\n seen.add(key);\n }\n return false;\n}\n\nfunction hasInvalidRoleName(value: unknown): boolean {\n if (!Array.isArray(value)) return false;\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n const label = \"label\" in item && typeof item.label === \"string\" ? item.label.trim() : \"\";\n if (!label) continue;\n if (!isRoleName(label)) return true;\n }\n return false;\n}\n\nexport function validateRolesMatrix(value: unknown): true | string {\n if (hasDuplicateRoleNames(value)) return DUPLICATE_ROLE_NAME_MESSAGE;\n if (hasInvalidRoleName(value)) return INVALID_ROLE_NAME_MESSAGE;\n const parsed = parseRolesMatrix(applyRoleSlugsFromNames(value));\n if (!parsed.ok) return parsed.message;\n return true;\n}\n\n/**\n * Developer is exclusive. Admin does not swallow Designer: both store.\n * Unknown slugs (dropped catalogue keys such as `approver`) fall away unless\n * they appear on the matrix.\n */\nexport function normalizeStoredRoles(\n value: unknown,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): string[] {\n if (!Array.isArray(value)) return [];\n const allowed = new Set(matrix.map((row) => row.role));\n const roles = [...new Set(value.filter((entry): entry is string => typeof entry === \"string\" && allowed.has(entry)))];\n if (roles.includes(\"developer\")) return [\"developer\"];\n return roles;\n}\n\nexport function roleSelectOptions(matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX) {\n return matrix.map((row) => ({ label: roleLabel(row.role, row.label), value: row.role }));\n}\n\n/** Grant copy only. Developer names the unreleased catalogue; nothing about MCP or seed. */\nexport function roleDescription(role: string, matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX): string {\n if (role === \"developer\") return DEVELOPER_DESCRIPTION;\n const row = matrix.find((entry) => entry.role === role);\n if (!row) return \"No capabilities\";\n const ticks = row.grants.map((slug) => packageFeatureLabel(slug));\n return ticks.join(\", \") || \"No capabilities\";\n}\n\n/**\n * Seed grants and package labels come back; extra rows stay as they are.\n */\nexport function resetRolesMatrix(current: unknown): RoleRow[] {\n const extras: RoleRow[] = [];\n if (Array.isArray(current)) {\n for (const item of current) {\n if (!item || typeof item !== \"object\") continue;\n const parsed = readRoleRow(item);\n if (\"error\" in parsed || isRole(parsed.role)) continue;\n extras.push(parsed);\n }\n }\n return [...defaultRolesFieldValue(), ...extras];\n}\n","import type { Access, PayloadRequest } from \"payload\";\n\nimport { DEFAULT_ROLE_MATRIX, parseRolesMatrix, roleHasCapability, roleHasGrant, ROLES_SLUG, seedRoleRows } from \"./matrix\";\nimport { type Capability, type MaybeUser, type RoleExtra, type RoleRow } from \"./types\";\n\nexport type { MaybeUser } from \"./types\";\n\ntype AccessArgs = {\n req: {\n user?: MaybeUser;\n payload?: Pick<NonNullable<PayloadRequest[\"payload\"]>, \"findGlobal\">;\n };\n};\n\ntype CapabilityPredicate = {\n (user: MaybeUser, matrix?: readonly RoleRow[]): boolean;\n (args: AccessArgs): boolean | Promise<boolean>;\n};\n\nfunction isAccessArgs(value: unknown): value is AccessArgs {\n return typeof value === \"object\" && value !== null && \"req\" in value;\n}\n\nexport function storedRoles(user: MaybeUser): readonly string[] {\n return Array.isArray(user?.roles) ? user.roles : [];\n}\n\nexport function hasRole(user: MaybeUser, role: string): boolean {\n return storedRoles(user).includes(role);\n}\n\n/** Not a tick. True only when `developer` is stored on the row. */\nexport function isDeveloper(user: MaybeUser): boolean {\n return hasRole(user, \"developer\");\n}\n\nexport function hasCapability(\n user: MaybeUser,\n capability: Capability,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (isDeveloper(user)) return true;\n return storedRoles(user).some((role) => {\n const row = matrix.find((entry) => entry.role === role);\n return row ? roleHasCapability(row, capability) : false;\n });\n}\n\nexport function hasGrant(\n user: MaybeUser,\n slug: string,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (isDeveloper(user)) return true;\n return storedRoles(user).some((role) => {\n const row = matrix.find((entry) => entry.role === role);\n return row ? roleHasGrant(row, slug) : false;\n });\n}\n\n/**\n * Reads the saved Roles Global, falling back to the seed when the row is\n * empty, missing, or unreadable. Always override-access so a Designer\n * evaluating Theme does not have to read Settings → Roles.\n */\nexport async function getRolesMatrix(\n req: AccessArgs[\"req\"] = {},\n extras: readonly RoleExtra[] = [],\n): Promise<RoleRow[]> {\n const fallback = seedRoleRows(extras);\n const findGlobal = req.payload?.findGlobal;\n if (typeof findGlobal !== \"function\") return fallback;\n try {\n const doc = await findGlobal({\n slug: ROLES_SLUG,\n overrideAccess: true,\n req: req as PayloadRequest,\n });\n const parsed = parseRolesMatrix(doc && typeof doc === \"object\" && \"roles\" in doc ? doc.roles : undefined);\n return parsed.ok ? parsed.rows : fallback;\n } catch {\n return fallback;\n }\n}\n\nfunction capabilityPredicate(capability: Capability): CapabilityPredicate {\n function predicate(\n userOrArgs: MaybeUser | AccessArgs,\n matrix?: readonly RoleRow[],\n ): boolean | Promise<boolean> {\n if (isAccessArgs(userOrArgs)) {\n const user = userOrArgs.req.user as MaybeUser;\n if (matrix) return hasCapability(user, capability, matrix);\n return getRolesMatrix(userOrArgs.req).then((rows) => hasCapability(user, capability, rows));\n }\n return hasCapability(userOrArgs, capability, matrix ?? DEFAULT_ROLE_MATRIX);\n }\n return predicate as CapabilityPredicate;\n}\n\nexport const canManageContent = capabilityPredicate(\"content\");\nexport const canManageBrand = capabilityPredicate(\"brand\");\nexport const canPublish = capabilityPredicate(\"publish\");\n\n/** Users grant on any held role (Developer is implicit). */\nexport const isAdmin = capabilityPredicate(\"users\");\n\n/** This role id currently has the Users grant, or is Developer. */\nexport function isPrivilegedRole(\n role: unknown,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (typeof role !== \"string\") return false;\n if (role === \"developer\") return true;\n const row = matrix.find((entry) => entry.role === role);\n return row ? roleHasGrant(row, \"users\") : false;\n}\n\nexport function isAuthenticated(user: MaybeUser): boolean;\nexport function isAuthenticated(args: AccessArgs): boolean;\nexport function isAuthenticated(userOrArgs: MaybeUser | AccessArgs): boolean {\n if (isAccessArgs(userOrArgs)) return Boolean(userOrArgs.req.user);\n return Boolean(userOrArgs);\n}\n\nexport const isAdminOrSelf: Access = async ({ req }) => {\n if (!req.user) return false;\n if (await isAdmin({ req })) return true;\n return { id: { equals: req.user.id } };\n};\n\nexport const authenticatedOrPublished: Access = ({ req: { user } }) => {\n if (isAuthenticated(user as MaybeUser)) return true;\n return { _status: { equals: \"published\" } };\n};\n\n/**\n * API tab condition. Code-locked to the `developer` slug — not a Features\n * row and not a Role tick a client can grant.\n */\nexport function isDeveloperTab({ req }: AccessArgs): boolean {\n return isDeveloper(req.user as MaybeUser);\n}\n\n/** Access for chrome globals (Features, Better Editor settings). */\nexport function developerOnlyAccess(): { read: Access; update: Access } {\n return {\n read: ({ req }) => isDeveloper(req.user as MaybeUser),\n update: ({ req }) => isDeveloper(req.user as MaybeUser),\n };\n}\n\n/** `admin.hidden`: hide unless the login is Developer. */\nexport function hideUnlessDeveloper({ user }: { user?: MaybeUser }): boolean {\n return !isDeveloper(user);\n}\n","import type { PayloadRequest } from \"payload\";\n\nimport { getRolesMatrix, hasGrant, isDeveloper, type MaybeUser } from \"../roles/access\";\nimport { DEFAULT_ROLE_MATRIX } from \"../roles/matrix\";\nimport type { RoleRow } from \"../roles/types\";\nimport { LEGACY_THEME_FEATURE_SLUGS } from \"../roles/types\";\nimport { defaultFeaturesFieldValue, isGroupOnlySlug, parseFeaturesMatrix } from \"./matrix\";\nimport { FEATURE_GROUPS, FEATURES_SLUG, type FeatureRow } from \"./types\";\n\ntype AccessArgs = {\n req: {\n user?: MaybeUser;\n payload?: Pick<NonNullable<PayloadRequest[\"payload\"]>, \"findGlobal\">;\n };\n};\n\ntype FeaturePredicate = {\n (user: MaybeUser, features?: readonly FeatureRow[] | null, roles?: readonly RoleRow[]): boolean;\n (args: AccessArgs): boolean | Promise<boolean>;\n};\n\nfunction isAccessArgs(value: unknown): value is AccessArgs {\n return typeof value === \"object\" && value !== null && \"req\" in value;\n}\n\nfunction grantedOnReleased(\n user: MaybeUser,\n slug: string,\n row: FeatureRow,\n matrix: readonly RoleRow[],\n): boolean {\n if (!row.released) return false;\n return hasGrant(user, slug, matrix);\n}\n\n/**\n * True when the feature is released and a held role is granted it.\n * Developer is always allowed. An empty Global falls back to catalogue\n * defaults. A group slug (`pages`) is true when any child is.\n * `theme` is the Roles grant: Features cannot release or withhold it.\n */\nexport function hasFeature(\n user: MaybeUser,\n slug: string,\n features: readonly FeatureRow[] | null = null,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (isDeveloper(user)) return true;\n if (!user) return false;\n // Retired slugs (`brand-assets`, `theme-colors`, …) are the Theme grant.\n // Sites that still pass canUseFeature(\"brand-assets\") keep Designer access.\n if (slug === \"theme\" || (LEGACY_THEME_FEATURE_SLUGS as readonly string[]).includes(slug)) {\n return hasGrant(user, \"theme\", matrix);\n }\n const rows = features && features.length > 0 ? features : defaultFeaturesFieldValue();\n const leaf = rows.find((entry) => entry.slug === slug);\n if (leaf) return grantedOnReleased(user, slug, leaf, matrix);\n if (!isGroupOnlySlug(slug)) return false;\n return rows.some((entry) => entry.group === slug && grantedOnReleased(user, entry.slug, entry, matrix));\n}\n\n/**\n * Reads the saved Features Global. `null` means empty or unreadable — callers\n * fall back to catalogue defaults. Always override-access.\n */\nexport async function getFeaturesMatrix(req: AccessArgs[\"req\"] = {}): Promise<FeatureRow[] | null> {\n const findGlobal = req.payload?.findGlobal;\n if (typeof findGlobal !== \"function\") return null;\n try {\n const doc = await findGlobal({\n slug: FEATURES_SLUG,\n overrideAccess: true,\n req: req as PayloadRequest,\n });\n const parsed = parseFeaturesMatrix(\n doc && typeof doc === \"object\" && \"features\" in doc ? doc.features : undefined,\n );\n return parsed.ok ? parsed.rows : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Access / nav helper for one catalogue slug. Sync against a passed grid;\n * async when given `req` so it can read both Globals.\n */\nexport function canUseFeature(slug: string): FeaturePredicate {\n function predicate(\n userOrArgs: MaybeUser | AccessArgs,\n features?: readonly FeatureRow[] | null,\n roles?: readonly RoleRow[],\n ): boolean | Promise<boolean> {\n if (isAccessArgs(userOrArgs)) {\n const user = userOrArgs.req.user as MaybeUser;\n if (features !== undefined) return hasFeature(user, slug, features, roles ?? DEFAULT_ROLE_MATRIX);\n return Promise.all([getFeaturesMatrix(userOrArgs.req), getRolesMatrix(userOrArgs.req)]).then(\n ([grid, matrix]) => hasFeature(user, slug, grid, matrix),\n );\n }\n return hasFeature(userOrArgs, slug, features ?? null, roles ?? DEFAULT_ROLE_MATRIX);\n }\n return predicate as FeaturePredicate;\n}\n\n/**\n * Feature slugs (and group slugs) this login may use. Written onto the\n * user at afterRead so `admin.hidden({ user })` can follow the saved\n * Features and Roles Globals without a `req`.\n */\nexport async function allowedFeaturesForUser(\n user: MaybeUser,\n req: AccessArgs[\"req\"] = {},\n): Promise<string[]> {\n const [features, roles] = await Promise.all([getFeaturesMatrix(req), getRolesMatrix(req)]);\n const rows = features && features.length > 0 ? features : defaultFeaturesFieldValue();\n const slugs = [...rows.map((row) => row.slug), ...FEATURE_GROUPS];\n return slugs.filter((slug) => hasFeature(user, slug, features, roles));\n}\n\nfunction userHasAllowedFeature(user: MaybeUser, slug: string): boolean {\n if (isDeveloper(user)) return true;\n const allowed = user?.allowedFeatures;\n if (!Array.isArray(allowed)) return false;\n return allowed.includes(slug);\n}\n\n/** `admin.hidden`: hide when the login cannot use the feature. */\nexport function hideUnlessFeature(slug: string) {\n return (args: { user?: MaybeUser; req?: AccessArgs[\"req\"] }) => {\n const user = args.user ?? null;\n if (isDeveloper(user)) return false;\n if (user && Array.isArray(user.allowedFeatures)) {\n return !userHasAllowedFeature(user, slug);\n }\n if (args.req) {\n const result = canUseFeature(slug)({ req: { ...args.req, user } });\n if (result instanceof Promise) return result.then((ok) => !ok);\n return !result;\n }\n return !canUseFeature(slug)(user);\n };\n}\n","import { catalog, type FontEntry } from \"@bison-lab/fonts\";\nimport { DESTRUCTIVE_SCALE_HEX, presetHints, SHADE_STEPS, SUCCESS_SCALE_HEX } from \"@bison-lab/tokens\";\nimport type { Access, Field, GlobalConfig, SelectField } from \"payload\";\n\nimport {\n SAME_AS_BODY,\n THEME_APPEARANCE_FIELD,\n THEME_COLOR_SCALE_FIELD,\n THEME_FONT_FIELD,\n THEME_GREY_SCALE_FIELD,\n THEME_LIBRARY_FIELD,\n THEME_PAIRING_FIELD,\n THEME_DOCUMENT_CONTROLS,\n THEME_SECTION_HEADING,\n headingSelectValue,\n} from \"./fields\";\nimport { APPEARANCE_CHOICES } from \"./appearance-labels\";\nimport { themeConfigFromDoc, validateSourceIncluded, validateThemeHex } from \"./map\";\nimport { colorUsageEndpoints } from \"./color-usage-endpoints\";\nimport { READABILITY_TARGET } from \"./readability\";\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { THEME_SLUG, type CreateThemeOptions, type ThemeDoc } from \"./types\";\n\nconst publicThemeRead: Access = () => true;\n\nfunction resolveAccess(options: CreateThemeOptions): { read: Access; update: Access } {\n return {\n read: options.access?.read ?? publicThemeRead,\n update: options.access?.update ?? canUseFeature(\"theme\"),\n };\n}\n\nfunction requireDestructive(options: CreateThemeOptions): string {\n return options.destructive ?? options.seed.brandDestructive ?? DESTRUCTIVE_SCALE_HEX;\n}\n\nfunction namedSelect<K extends string>(\n name: string,\n label: string,\n choices: Record<K, { label: string; hint: string }>,\n defaultValue: K,\n field?: string,\n): SelectField {\n return {\n name,\n type: \"select\",\n label,\n required: true,\n defaultValue,\n options: (Object.entries(choices) as [K, { label: string; hint: string }][]).map(\n ([value, { label: optionLabel, hint }]) => ({\n label: `${optionLabel} — ${hint}`,\n value,\n }),\n ),\n ...(field ? { admin: { components: { Field: field } } } : {}),\n };\n}\n\nconst STEP_OPTIONS = SHADE_STEPS.map((step) => ({ label: String(step), value: String(step) }));\n\nfunction colorScaleFields(hexDefault?: string): Field[] {\n const hidden = { hidden: true } as const;\n return [\n {\n name: \"hex\",\n type: \"text\",\n label: \"Hex\",\n required: true,\n ...(hexDefault ? { defaultValue: hexDefault } : {}),\n validate: validateThemeHex,\n admin: hidden,\n },\n {\n name: \"sourceStep\",\n type: \"select\",\n label: \"Source step\",\n required: true,\n defaultValue: \"500\",\n options: STEP_OPTIONS,\n admin: hidden,\n },\n {\n name: \"scale\",\n type: \"json\",\n label: \"Scale\",\n admin: hidden,\n },\n {\n name: \"stale\",\n type: \"checkbox\",\n label: \"Stale\",\n defaultValue: false,\n admin: hidden,\n },\n {\n name: \"include\",\n type: \"select\",\n label: \"Include\",\n required: true,\n defaultValue: \"all\",\n options: [\n { label: \"Include all\", value: \"all\" },\n { label: \"Source only\", value: \"source\" },\n { label: \"Custom\", value: \"custom\" },\n ],\n admin: hidden,\n },\n {\n name: \"includedSteps\",\n type: \"select\",\n label: \"Included steps\",\n hasMany: true,\n options: STEP_OPTIONS,\n validate: validateSourceIncluded,\n admin: hidden,\n },\n ];\n}\n\nfunction systemColorGroup(name: string, label: string, hexDefault: string): Field {\n return {\n name,\n type: \"group\",\n label,\n fields: colorScaleFields(hexDefault),\n admin: { components: { Field: THEME_COLOR_SCALE_FIELD }, hideGutter: true },\n };\n}\n\nfunction fontField(\n name: string,\n label: string,\n defaultValue: string,\n fonts: readonly FontEntry[],\n fontsBaseUrl: string,\n sameAsBody: boolean,\n): SelectField {\n const options = fonts.map((font) => ({ label: font.family, value: font.id }));\n return {\n name,\n type: \"select\",\n label,\n required: !sameAsBody,\n defaultValue,\n options: sameAsBody ? [{ label: \"Same as body\", value: SAME_AS_BODY }, ...options] : options,\n admin: {\n components: { Field: THEME_FONT_FIELD },\n custom: { fontsBaseUrl, ids: fonts.map((font) => font.id), sameAsBody },\n },\n };\n}\n\nfunction colorsFields(seed: CreateThemeOptions[\"seed\"], destructive: string): Field[] {\n return [\n {\n name: \"colors\",\n type: \"group\",\n label: false,\n admin: { hideGutter: true, width: \"100%\" },\n fields: [\n {\n name: \"brand\",\n type: \"group\",\n label: false,\n admin: { hideGutter: true, width: \"100%\" },\n fields: [\n {\n name: \"themeColorsHeading\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_SECTION_HEADING },\n custom: {\n title: \"Brand colors\",\n hint: \"These colors define the visual identity of the site. Adjust them freely to match the brand.\",\n },\n },\n },\n systemColorGroup(\"primary\", \"Primary\", seed.brandPrimary),\n systemColorGroup(\"secondary\", \"Secondary\", seed.brandSecondary),\n systemColorGroup(\"accent\", \"Accent\", seed.brandAccent),\n systemColorGroup(\"highlight\", \"Highlight\", seed.brandHighlight),\n {\n name: \"libraryPlacement\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_LIBRARY_FIELD },\n custom: { dataPath: \"colors.library\" },\n },\n },\n {\n name: \"greyPlacement\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_GREY_SCALE_FIELD },\n custom: { dataPath: \"colors.greyScale\" },\n },\n },\n {\n name: \"statusColorsHeading\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_SECTION_HEADING },\n custom: {\n title: \"Status colors\",\n hint: \"These colors communicate meaning across the site. You can adjust them to fit your brand, but we'll help keep them recognizable as success and error states.\",\n },\n },\n },\n systemColorGroup(\"success\", \"Success\", seed.brandSuccess || SUCCESS_SCALE_HEX),\n systemColorGroup(\"destructive\", \"Destructive\", destructive),\n ],\n },\n {\n ...namedSelect(\"greyScale\", \"Gray family\", presetHints.greyScale, seed.greyScale, THEME_GREY_SCALE_FIELD),\n admin: { hidden: true, components: { Field: THEME_GREY_SCALE_FIELD } },\n },\n {\n name: \"library\",\n type: \"array\",\n label: \"Additional colors\",\n labels: { singular: \"Color\", plural: \"Colors\" },\n fields: [\n { name: \"key\", type: \"text\", label: \"Key\", required: true, admin: { hidden: true } },\n { name: \"label\", type: \"text\", label: \"Name\", required: true, admin: { hidden: true } },\n ...colorScaleFields(),\n ],\n admin: { hidden: true, components: { Field: THEME_LIBRARY_FIELD }, width: \"100%\" },\n },\n ],\n },\n ];\n}\n\nfunction typographyFields(\n seed: CreateThemeOptions[\"seed\"],\n fonts: readonly FontEntry[],\n fontsBaseUrl: string,\n): Field[] {\n return [\n {\n name: \"typography\",\n type: \"group\",\n label: \"Typography\",\n fields: [\n fontField(\n \"heading\",\n \"Heading font\",\n headingSelectValue(seed.fontHeading),\n fonts,\n fontsBaseUrl,\n true,\n ),\n fontField(\"body\", \"Body font\", seed.fontBody, fonts, fontsBaseUrl, false),\n {\n name: \"pairing\",\n type: \"ui\",\n admin: { components: { Field: THEME_PAIRING_FIELD }, custom: { fontsBaseUrl } },\n },\n ],\n },\n ];\n}\n\nfunction appearanceFields(seed: CreateThemeOptions[\"seed\"]): Field[] {\n return [\n {\n name: \"appearance\",\n type: \"group\",\n label: \"Appearance\",\n fields: [\n namedSelect(\"defaultTheme\", \"Default theme\", APPEARANCE_CHOICES.defaultTheme, seed.defaultTheme),\n namedSelect(\"radius\", \"Corner style\", APPEARANCE_CHOICES.radius, seed.radius),\n namedSelect(\"shadow\", \"Depth\", APPEARANCE_CHOICES.shadow, seed.shadow),\n namedSelect(\"motion\", \"Motion\", APPEARANCE_CHOICES.motion, seed.motion),\n namedSelect(\"density\", \"Spacing\", APPEARANCE_CHOICES.density, seed.density),\n ],\n admin: { components: { Field: THEME_APPEARANCE_FIELD } },\n },\n ];\n}\n\nfunction identityFields(collection: string): Field[] {\n return [\n {\n name: \"logo\",\n type: \"upload\",\n relationTo: collection,\n label: \"Logo\",\n admin: {\n description: \"The full wordmark used in the header and footer.\",\n },\n },\n {\n name: \"favicon\",\n type: \"upload\",\n relationTo: collection,\n label: \"Favicon\",\n admin: {\n description: \"The small icon in the browser tab. PNG or SVG.\",\n },\n },\n {\n name: \"logoMark\",\n type: \"upload\",\n relationTo: collection,\n label: \"Mobile menu logo\",\n admin: {\n description:\n \"Optional. Used when the full logo is too wide for the mobile menu — typically the mark.\",\n },\n },\n ];\n}\n\n/**\n * One Theme Global. Colors, Typography, Appearance, and Identity are\n * tabs on that document. Save writes the whole form — Payload hydrates\n * every tab from the live row, so an untouched tab does not revert.\n * Locking is off. No draft mode, no preview pane.\n */\nexport function createTheme(options: CreateThemeOptions): GlobalConfig[] {\n const access = resolveAccess(options);\n const destructive = requireDestructive(options);\n const {\n seed,\n fonts = catalog,\n fontsBaseUrl = \"/fonts\",\n contrastTarget = READABILITY_TARGET,\n logo,\n identity,\n onPublish,\n colorUsages,\n } = options;\n\n const adminCustom = { contrastTarget, fontsBaseUrl, identityFallback: identity?.fallback };\n const colorFields = colorsFields(seed, destructive);\n const typeFields = typographyFields(seed, fonts, fontsBaseUrl);\n const lookFields = appearanceFields(seed);\n const markFields = logo ? identityFields(logo.collection) : [];\n\n return [\n {\n slug: THEME_SLUG,\n label: \"Theme\",\n lockDocuments: false,\n admin: {\n group: \"Theme\",\n hidden: hideUnlessFeature(\"theme\") as (args: { user: unknown }) => boolean,\n hideAPIURL: true,\n custom: adminCustom,\n components: {\n elements: { beforeDocumentControls: [THEME_DOCUMENT_CONTROLS] },\n },\n },\n access: {\n read: access.read,\n update: access.update,\n },\n fields: [\n {\n type: \"tabs\",\n tabs: [\n { label: \"Colors\", fields: colorFields },\n { label: \"Typography\", fields: typeFields },\n { label: \"Appearance\", fields: lookFields },\n ...(logo ? [{ label: \"Identity\" as const, fields: markFields }] : []),\n ],\n },\n ],\n endpoints: colorUsageEndpoints(access, colorUsages),\n hooks: {\n afterChange: [\n async ({ doc }) => {\n if (!onPublish) return;\n const themeDoc = doc as ThemeDoc;\n await onPublish(themeConfigFromDoc(themeDoc, seed), themeDoc);\n },\n ],\n },\n },\n ];\n}\n","const DANGEROUS_TAGS = [\"script\", \"foreignObject\", \"iframe\", \"embed\", \"object\"] as const;\n\n/**\n * Strips the SVG features a lockup does not need and an attacker would\n * use: script, foreignObject, iframe/embed/object, event handlers,\n * javascript: / data:text/html URLs, and xml-stylesheet. Internal `#`\n * refs and ordinary drawing elements stay.\n */\nexport function sanitizeSvg(source: string): string {\n if (!/<svg[\\s>]/i.test(source)) {\n throw new Error(\"Not an SVG\");\n }\n\n let out = source.replace(/<\\?xml-stylesheet[\\s\\S]*?\\?>/gi, \"\");\n\n for (const tag of DANGEROUS_TAGS) {\n out = out.replace(new RegExp(`<${tag}\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/${tag}\\\\s*>`, \"gi\"), \"\");\n out = out.replace(new RegExp(`<${tag}\\\\b[^>]*\\\\/>`, \"gi\"), \"\");\n }\n\n out = out.replace(/\\s+on[a-z][a-z0-9-]*\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/gi, \"\");\n out = out.replace(\n /((?:href|src|xlink:href)\\s*=\\s*)([\"'])\\s*(?:javascript:|data:text\\/html)[^\"']*\\2/gi,\n \"$1$2$2\",\n );\n\n return out;\n}\n\nexport function isSvgUpload(file: { mimetype?: string; name?: string; data?: Buffer }): boolean {\n if (file.mimetype === \"image/svg+xml\") return true;\n if (typeof file.name === \"string\" && file.name.toLowerCase().endsWith(\".svg\")) return true;\n return false;\n}\n","import type { Access, CollectionConfig } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { isSvgUpload, sanitizeSvg } from \"./sanitize\";\n\nexport const BRAND_ASSETS_SLUG = \"brand-assets\";\n\n/** SVG preferred; PNG allowed. ICO is for the favicon slot. */\nexport const BRAND_ASSETS_MIME_TYPES = [\n \"image/svg+xml\",\n \"image/png\",\n \"image/x-icon\",\n \"image/vnd.microsoft.icon\",\n] as const;\n\nexport interface CreateBrandAssetsOptions {\n /**\n * Same shape as `createTheme`. `read` defaults to public so the live site\n * can load the file; pass a stricter function to tighten it. `update`\n * defaults to `canUseFeature(\"theme\")` — the Theme grant — and covers\n * create, update, delete, and version history.\n */\n access?: { read?: Access; update?: Access };\n /** Default `brand-assets`. Pass the same slug to `createTheme({ logo })`. */\n slug?: string;\n}\n\nconst publicBrandRead: Access = () => true;\n\nfunction resolveAccess(options: CreateBrandAssetsOptions): { read: Access; update: Access } {\n return {\n read: options.access?.read ?? publicBrandRead,\n update: options.access?.update ?? canUseFeature(\"theme\"),\n };\n}\n\n/**\n * Locked cupboard for lockup and mark. Not ordinary Media — only a brand\n * manager writes it. Theme's `logo` / `logoMark` point here when the site\n * passes this slug as `logo.collection`.\n */\nexport function createBrandAssets(options: CreateBrandAssetsOptions = {}): CollectionConfig {\n const access = resolveAccess(options);\n const slug = options.slug ?? BRAND_ASSETS_SLUG;\n\n return {\n slug,\n labels: { singular: \"Brand asset\", plural: \"Brand assets\" },\n admin: {\n group: \"Settings\",\n useAsTitle: \"label\",\n hidden: hideUnlessFeature(\"theme\") as (args: { user: unknown }) => boolean,\n description: \"Logo, favicon, and mobile-menu mark. SVG preferred; PNG and ICO allowed.\",\n },\n upload: {\n mimeTypes: [...BRAND_ASSETS_MIME_TYPES],\n crop: false,\n focalPoint: false,\n },\n versions: true,\n access: {\n read: access.read,\n create: access.update,\n update: access.update,\n delete: access.update,\n readVersions: access.update,\n },\n fields: [\n { name: \"label\", type: \"text\", label: \"Label\" },\n { name: \"notes\", type: \"textarea\", label: \"Usage notes\" },\n { name: \"alt\", type: \"text\", label: \"Alt text\", required: true },\n ],\n hooks: {\n beforeOperation: [\n ({ req, operation }) => {\n if (operation !== \"create\" && operation !== \"update\") return;\n const file = req.file;\n if (!file || !isSvgUpload(file)) return;\n file.data = Buffer.from(sanitizeSvg(file.data.toString(\"utf8\")), \"utf8\");\n },\n ],\n },\n };\n}\n","import type { ThemeConfig } from \"@bison-lab/tokens\";\n\nimport { docFromConfig } from \"./map\";\nimport { THEME_SLUG } from \"./types\";\nimport type { ThemeDoc } from \"./types\";\n\nexport interface SeedThemePayload {\n updateGlobal: (args: {\n slug: string;\n data: ThemeDoc;\n draft?: boolean;\n }) => Promise<unknown>;\n}\n\n/**\n * Writes a published Theme from the seed. For a site's migration `up()`,\n * so the row exists on deploy and renders what `bison-theme.css` rendered.\n */\nexport async function seedTheme(payload: SeedThemePayload, seed: ThemeConfig): Promise<unknown> {\n return payload.updateGlobal({\n slug: THEME_SLUG,\n data: docFromConfig(seed),\n draft: false,\n });\n}\n","import { THEME_SLUG, type ThemeColorDoc, type ThemeDoc } from \"./types\";\n\nexport const THEME_CHILDREN = [\"colors\", \"typography\", \"appearance\", \"identity\"] as const;\n\nexport type ThemeChild = (typeof THEME_CHILDREN)[number];\n\n/**\n * Publishing a child writes that slice only. Other responsibilities stay\n * as they already are on the stored document. Unsaved form state on a\n * different child never goes live. A first save (no stored row) still\n * writes only the named child; `getPublishedTheme` fills the rest from\n * the seed.\n */\nexport function publishThemeChild(stored: ThemeDoc, incoming: ThemeDoc, child: ThemeChild): ThemeDoc {\n if (child === \"colors\") return { ...stored, colors: incoming.colors };\n if (child === \"typography\") return { ...stored, typography: incoming.typography };\n if (child === \"appearance\") return { ...stored, appearance: incoming.appearance };\n return { ...stored, logo: incoming.logo, favicon: incoming.favicon, logoMark: incoming.logoMark };\n}\n\nexport function isThemeChild(value: unknown): value is ThemeChild {\n return typeof value === \"string\" && (THEME_CHILDREN as readonly string[]).includes(value);\n}\n\nexport function sliceFromTheme(theme: ThemeDoc, child: ThemeChild): ThemeDoc {\n if (child === \"colors\") return { colors: theme.colors };\n if (child === \"typography\") return { typography: theme.typography };\n if (child === \"appearance\") return { appearance: theme.appearance };\n return { logo: theme.logo, favicon: theme.favicon, logoMark: theme.logoMark };\n}\n\nfunction colorHex(color: ThemeColorDoc | string | null | undefined): string | undefined {\n if (typeof color === \"string\") return color;\n return color?.hex ?? undefined;\n}\n\n/**\n * A Theme page is a real Global. Hydrate from the store only when this\n * page has never been saved — otherwise afterRead would overwrite the form.\n */\nexport function hasThemeSlice(doc: ThemeDoc | null | undefined, child: ThemeChild): boolean {\n if (!doc) return false;\n if (child === \"colors\") return Boolean(colorHex(doc.colors?.brand?.primary));\n if (child === \"typography\") return Boolean(doc.typography?.body);\n if (child === \"appearance\") return Boolean(doc.appearance?.radius);\n return Boolean(doc.logo || doc.favicon || doc.logoMark);\n}\n\nexport interface ThemeStorePayload {\n findGlobal: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n }) => Promise<ThemeDoc | null | undefined>;\n updateGlobal: (args: { slug: string; data: ThemeDoc; draft?: boolean }) => Promise<unknown>;\n}\n\n/**\n * Save on a Theme page writes that slice onto the hidden `theme` row.\n * Other children stay as stored.\n */\nexport async function persistThemeChild(\n payload: ThemeStorePayload,\n incoming: ThemeDoc,\n child: ThemeChild,\n): Promise<ThemeDoc> {\n const stored =\n (await payload.findGlobal({\n slug: THEME_SLUG,\n draft: false,\n overrideAccess: true,\n })) ?? {};\n const next = publishThemeChild(stored, incoming, child);\n await payload.updateGlobal({ slug: THEME_SLUG, data: next, draft: false });\n return next;\n}\n","/**\n * Import-map keys and helpers for the shared document header.\n * `documentTitleActions()` injects one admin provider so every\n * document shares the title-row lift. One-list Globals pass\n * `documentCreateNew` so Create New sits in that same slot.\n */\n\nexport const DOCUMENT_TITLE_ACTIONS = \"@bison-lab/payload-core/admin#DocumentTitleActions\";\nexport const DOCUMENT_CREATE_NEW = \"@bison-lab/payload-core/admin#DocumentCreateNew\";\n\nexport function documentCreateNew(path: string) {\n return { path: DOCUMENT_CREATE_NEW, clientProps: { path } };\n}\n","export const ROLES_MATRIX_FIELD = \"@bison-lab/payload-core/admin#RolesMatrixField\";\nexport const ROLES_ROW_LABEL = \"@bison-lab/payload-core/admin#RolesRowLabel\";\nexport const ROLE_SLUG_FIELD = \"@bison-lab/payload-core/admin#RoleSlugField\";\nexport const ROLE_NAME_FIELD = \"@bison-lab/payload-core/admin#RoleNameField\";\nexport const ROLES_FIELD = \"@bison-lab/payload-core/admin#RolesField\";\nexport const ROLES_GRANTS_FIELD = \"@bison-lab/payload-core/admin#RolesGrantsField\";\n","import type { ArrayField, GlobalConfig, TextFieldSingleValidation } from \"payload\";\n\nimport { documentCreateNew } from \"../admin/document-controls\";\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { isAdmin } from \"./access\";\nimport { ROLE_NAME_FIELD, ROLES_GRANTS_FIELD, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL } from \"./fields\";\nimport {\n applyRoleSlugsFromNames,\n defaultRolesFieldValue,\n DUPLICATE_ROLE_SLUG_MESSAGE,\n grantsFromStoredRole,\n INVALID_ROLE_NAME_MESSAGE,\n ROLES_FIELD_DESCRIPTION,\n ROLES_GLOBAL_DESCRIPTION,\n ROLES_SLUG,\n validateRolesMatrix,\n} from \"./matrix\";\nimport { isRoleName, isRoleSlug, type RoleExtra } from \"./types\";\n\nexport interface CreateRolesOptions {\n /**\n * Extra catalogue rows after the first-run defaults. Each is a slug, a\n * display label, and default grants. A site that passes nothing still\n * gets Developer / Admin / Designer / Author; an Admin may later remove\n * every row except Developer.\n */\n extras?: readonly RoleExtra[];\n}\n\nconst roleSlugValidate: TextFieldSingleValidation = (value) => {\n // Empty is fine while Create New is in progress; the name fills it on save.\n if (typeof value !== \"string\" || value === \"\") return true;\n return isRoleSlug(value) || DUPLICATE_ROLE_SLUG_MESSAGE;\n};\n\nconst roleNameValidate: TextFieldSingleValidation = (value) => {\n if (typeof value !== \"string\" || value.trim() === \"\") return true;\n return isRoleName(value) || INVALID_ROLE_NAME_MESSAGE;\n};\n\n/**\n * Settings → Roles. Rank is the array order (Payload's drag handle).\n * Ticks are released catalogue rows. Developer is implicit and shown\n * only to a Developer, with every catalogue tick locked on.\n */\nexport function createRoles({ extras = [] }: CreateRolesOptions = {}): GlobalConfig {\n const rolesField: ArrayField = {\n name: \"roles\",\n type: \"array\",\n label: \"Roles\",\n labels: { singular: \"Role\", plural: \"Roles\" },\n minRows: 1,\n required: true,\n defaultValue: defaultRolesFieldValue(extras),\n validate: validateRolesMatrix,\n hooks: {\n beforeChange: [({ value }) => applyRoleSlugsFromNames(value)],\n },\n admin: {\n components: { Field: ROLES_MATRIX_FIELD, RowLabel: ROLES_ROW_LABEL },\n description: ROLES_FIELD_DESCRIPTION,\n initCollapsed: false,\n },\n fields: [\n {\n name: \"role\",\n type: \"text\",\n label: \"Slug\",\n validate: roleSlugValidate,\n admin: { hidden: true },\n },\n {\n name: \"label\",\n type: \"text\",\n label: \"Name\",\n required: true,\n validate: roleNameValidate,\n admin: { components: { Field: ROLE_NAME_FIELD } },\n },\n {\n name: \"grants\",\n type: \"json\",\n label: \"Grants\",\n defaultValue: [],\n hooks: {\n beforeChange: [\n ({ value }) => (Array.isArray(value) ? grantsFromStoredRole({ grants: value }) : value),\n ],\n },\n admin: {\n components: { Field: ROLES_GRANTS_FIELD },\n },\n },\n ],\n };\n\n return {\n slug: ROLES_SLUG,\n label: \"Roles\",\n admin: {\n group: \"Settings\",\n hidden: hideUnlessFeature(\"roles\") as (args: { user: unknown }) => boolean,\n description: ROLES_GLOBAL_DESCRIPTION,\n components: {\n elements: {\n beforeDocumentControls: [documentCreateNew(\"roles\")],\n },\n },\n },\n access: {\n read: (args) => canUseFeature(\"roles\")(args),\n update: (args) => isAdmin(args),\n },\n fields: [rolesField],\n };\n}\n","import { defaultRolesFieldValue, ROLES_SLUG } from \"./matrix\";\nimport type { RoleExtra, RolesDoc } from \"./types\";\n\nexport interface SeedRolesPayload {\n updateGlobal: (args: { slug: string; data: RolesDoc }) => Promise<unknown>;\n}\n\n/**\n * Writes the default matrix (Developer, Admin, Designer, Author plus any\n * site extras). For a site's migration `up()`. Never writes a user row —\n * seeding `developer` on a person stays a site concern.\n */\nexport async function seedRoles(\n payload: SeedRolesPayload,\n extras: readonly RoleExtra[] = [],\n): Promise<unknown> {\n return payload.updateGlobal({\n slug: ROLES_SLUG,\n data: { roles: defaultRolesFieldValue(extras) },\n });\n}\n","export const BLOCK_LIBRARY_SLUG = \"block-library\";\n\nexport const BLOCK_LIBRARY_CATEGORIES = [\n { id: \"hero\", label: \"Hero\" },\n { id: \"feature\", label: \"Feature\" },\n { id: \"process\", label: \"Process\" },\n { id: \"faq\", label: \"FAQ\" },\n { id: \"testimonials\", label: \"Testimonials\" },\n { id: \"stats\", label: \"Stats\" },\n { id: \"content\", label: \"Content\" },\n { id: \"contact\", label: \"Contact\" },\n { id: \"cta\", label: \"CTA\" },\n { id: \"navigation\", label: \"Navigation\" },\n] as const;\n\nexport type BlockLibraryCategoryId = (typeof BLOCK_LIBRARY_CATEGORIES)[number][\"id\"];\n\nexport type BlockLibraryKind = \"hero\" | \"section\" | \"navbar\";\n\n/**\n * Package catalogue. `megaMenu` and `navLink` are header item blocks, not\n * cards. Navigation's card is `floatingNav`. CTA is a category for a site\n * extra; the package ships no CTA slug. Draft-strip is BIS-131. The preview\n * route is SPI-53.\n */\nexport const PACKAGE_BLOCK_SLUGS = [\n \"hero\",\n \"heroSweep\",\n \"heroCompact\",\n \"showcasePanels\",\n \"processSteps\",\n \"faqColumns\",\n \"testimonialMasonry\",\n \"statsBand\",\n \"richText\",\n \"nap\",\n \"floatingNav\",\n] as const;\n\nexport type PackageBlockSlug = (typeof PACKAGE_BLOCK_SLUGS)[number];\n\nexport interface BlockLibraryEntry {\n slug: string;\n label: string;\n category: string;\n /** Defaults from the category: hero, navbar for navigation, otherwise section. */\n kind?: BlockLibraryKind;\n supportsMega?: boolean;\n sample?: unknown;\n}\n\nexport interface BlockLibraryRow {\n id: string;\n slug: string;\n label: string;\n category: string;\n enabled: boolean;\n kind: BlockLibraryKind;\n}\n\nexport interface BlockLibraryHolder {\n title?: string | null;\n slug?: string | null;\n}\n","import type { BlockLibraryEntry, BlockLibraryHolder, BlockLibraryKind, BlockLibraryRow } from \"./types\";\nimport { PACKAGE_BLOCK_SLUGS } from \"./types\";\n\nconst NOT_CATALOGUE = new Set([\"megaMenu\", \"navLink\"]);\n\nconst PACKAGE_BLOCKS: readonly BlockLibraryEntry[] = [\n { slug: \"hero\", label: \"Hero\", category: \"hero\", kind: \"hero\" },\n { slug: \"heroSweep\", label: \"Sweep hero\", category: \"hero\", kind: \"hero\" },\n { slug: \"heroCompact\", label: \"Compact hero\", category: \"hero\", kind: \"hero\" },\n { slug: \"showcasePanels\", label: \"Showcase panels\", category: \"feature\", kind: \"section\" },\n { slug: \"processSteps\", label: \"Process steps\", category: \"process\", kind: \"section\" },\n { slug: \"faqColumns\", label: \"FAQ\", category: \"faq\", kind: \"section\" },\n { slug: \"testimonialMasonry\", label: \"Testimonials\", category: \"testimonials\", kind: \"section\" },\n { slug: \"statsBand\", label: \"Stats\", category: \"stats\", kind: \"section\" },\n { slug: \"richText\", label: \"Rich text\", category: \"content\", kind: \"section\" },\n { slug: \"nap\", label: \"Contact\", category: \"contact\", kind: \"section\" },\n { slug: \"floatingNav\", label: \"Floating navbar\", category: \"navigation\", kind: \"navbar\", supportsMega: true },\n];\n\nexport interface BlockLibraryOptions {\n blocks?: readonly BlockLibraryEntry[];\n previewPath: (slug: string) => string;\n}\n\nexport interface BlockLibraryCheck {\n originals?: readonly BlockLibraryRow[];\n holders?: readonly BlockLibraryHolder[];\n pages?: unknown[];\n}\n\nexport function blockLibraryCatalogue(extras: readonly BlockLibraryEntry[] = []): BlockLibraryEntry[] {\n const extra = extras.filter((entry) => !NOT_CATALOGUE.has(entry.slug));\n return [...PACKAGE_BLOCKS.map((entry) => ({ ...entry })), ...extra];\n}\n\nexport function defaultBlockLibraryValue(options: BlockLibraryOptions): BlockLibraryRow[] {\n return blockLibraryCatalogue(options.blocks).map((entry) => toRow(entry, true));\n}\n\nfunction toRow(entry: BlockLibraryEntry, enabled = true): BlockLibraryRow {\n const kind = entry.kind ?? (entry.category === \"hero\" ? \"hero\" : entry.category === \"navigation\" ? \"navbar\" : \"section\");\n return {\n id: entry.slug,\n slug: entry.slug,\n label: entry.label,\n category: entry.category,\n enabled,\n kind,\n };\n}\n\nexport function stampBlockLibrary(value: unknown, options: BlockLibraryOptions): BlockLibraryRow[] {\n const catalogue = blockLibraryCatalogue(options.blocks);\n const incoming = new Map<string, boolean>();\n if (Array.isArray(value)) {\n for (const item of value) {\n if (!item || typeof item !== \"object\" || !(\"slug\" in item)) continue;\n const slug = item.slug;\n if (typeof slug !== \"string\" || NOT_CATALOGUE.has(slug)) continue;\n if (!catalogue.some((entry) => entry.slug === slug)) continue;\n if (\"enabled\" in item && typeof item.enabled === \"boolean\") incoming.set(slug, item.enabled);\n }\n }\n return catalogue.map((entry) => toRow(entry, incoming.get(entry.slug) ?? true));\n}\n\nfunction enabledOf(rows: readonly BlockLibraryRow[], kind: BlockLibraryKind): number {\n return rows.filter((row) => row.kind === kind && row.enabled).length;\n}\n\nfunction holderLabel(holder: BlockLibraryHolder): string {\n const title = holder.title?.trim() || \"Untitled\";\n const slug = holder.slug?.trim();\n return slug ? `${title} (${slug})` : title;\n}\n\n/**\n * Refuses a disable. Does not write to `pages` — draft-strip is BIS-131.\n */\nexport async function validateBlockLibrary(\n value: unknown,\n options: BlockLibraryOptions,\n check: BlockLibraryCheck = {},\n): Promise<true | string> {\n const next = stampBlockLibrary(value, options);\n const previous = check.originals ?? defaultBlockLibraryValue(options);\n const turningOff = next.filter((row) => {\n const before = previous.find((entry) => entry.slug === row.slug);\n return before?.enabled !== false && row.enabled === false;\n });\n if (turningOff.length === 0) return true;\n\n if (turningOff.some((row) => row.kind === \"hero\") && enabledOf(next, \"hero\") === 0) {\n return \"Cannot disable the last hero.\";\n }\n if (turningOff.some((row) => row.kind === \"navbar\") && enabledOf(next, \"navbar\") === 0) {\n return \"Cannot disable the last navbar.\";\n }\n\n const holders = check.holders ?? [];\n if (holders.length > 0) {\n const names = holders.map(holderLabel).join(\", \");\n const slugs = turningOff.map((row) => row.label).join(\", \");\n return `Cannot disable ${slugs}. Still used on: ${names}.`;\n }\n\n return true;\n}\n\nexport function packageBlockSlugs(): readonly string[] {\n return PACKAGE_BLOCK_SLUGS;\n}\n","export const BLOCK_LIBRARY_FIELD = \"@bison-lab/payload-core/admin#BlockLibraryField\";\n","import type { BlockLibraryHolder } from \"./types\";\nimport { BLOCK_LIBRARY_SLUG } from \"./types\";\n\ntype FindResult = { docs: Record<string, unknown>[]; totalPages?: number };\n\nexport interface BlockLibraryPayload {\n config?: {\n collections?: { slug?: string }[];\n globals?: { slug?: string }[];\n };\n find: (args: {\n collection: string;\n draft?: boolean;\n depth?: number;\n limit?: number;\n page?: number;\n overrideAccess?: boolean;\n }) => Promise<FindResult>;\n findGlobal?: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n }) => Promise<Record<string, unknown> | null>;\n}\n\nfunction slugsOf(value: { slug?: string }[] | undefined): string[] {\n return (value ?? []).map((item) => item.slug).filter((slug): slug is string => Boolean(slug));\n}\n\nfunction holdsSlug(value: unknown, slug: string): boolean {\n if (!value || typeof value !== \"object\") return false;\n if (Array.isArray(value)) return value.some((item) => holdsSlug(item, slug));\n const record = value as Record<string, unknown>;\n if (record.blockType === slug) return true;\n return Object.values(record).some((child) => holdsSlug(child, slug));\n}\n\nfunction asHolder(doc: Record<string, unknown>): BlockLibraryHolder {\n return {\n title: typeof doc.title === \"string\" ? doc.title : null,\n slug: typeof doc.slug === \"string\" ? doc.slug : null,\n };\n}\n\n/**\n * Published and draft documents whose blocks still use `slug`.\n * Reads only. Draft-strip is BIS-131.\n */\nexport async function documentsHoldingBlock(\n payload: BlockLibraryPayload,\n slug: string,\n): Promise<BlockLibraryHolder[]> {\n const collections = slugsOf(payload.config?.collections).filter(\n (name) => !name.startsWith(\"payload-\") && name !== BLOCK_LIBRARY_SLUG,\n );\n const globals = slugsOf(payload.config?.globals).filter((name) => name !== BLOCK_LIBRARY_SLUG);\n const seen = new Set<string>();\n const holders: BlockLibraryHolder[] = [];\n\n const keep = (doc: Record<string, unknown>) => {\n if (!holdsSlug(doc, slug)) return;\n const id = String(doc.id ?? doc.slug ?? holders.length);\n if (seen.has(id)) return;\n seen.add(id);\n holders.push(asHolder(doc));\n };\n\n for (const collection of collections) {\n for (const draft of [false, true]) {\n let page = 1;\n for (;;) {\n let result: FindResult;\n try {\n result = await payload.find({\n collection,\n draft,\n depth: 0,\n limit: 100,\n page,\n overrideAccess: true,\n });\n } catch {\n break;\n }\n for (const doc of result.docs) keep(doc);\n const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);\n if (page >= totalPages || result.docs.length === 0) break;\n page += 1;\n }\n }\n }\n\n if (payload.findGlobal) {\n for (const global of globals) {\n for (const draft of [false, true]) {\n try {\n const doc = await payload.findGlobal({ slug: global, draft, depth: 0, overrideAccess: true });\n if (doc) keep(doc);\n } catch {\n // An unregistered slug must not block Save.\n }\n }\n }\n }\n\n return holders;\n}\n","import type { ArrayField, GlobalConfig } from \"payload\";\n\nimport { isAdmin, isAuthenticated } from \"../roles/access\";\nimport { blockLibraryCatalogue, defaultBlockLibraryValue, stampBlockLibrary, validateBlockLibrary, type BlockLibraryOptions } from \"./catalogue\";\nimport { BLOCK_LIBRARY_FIELD } from \"./fields\";\nimport { documentsHoldingBlock } from \"./holders\";\nimport { BLOCK_LIBRARY_SLUG, type BlockLibraryEntry } from \"./types\";\n\nexport interface CreateBlockLibraryOptions extends BlockLibraryOptions {\n /**\n * Who may change availability. Defaults to Admin. Not a Theme-style opt-in.\n */\n access?: {\n read?: GlobalConfig[\"access\"] extends infer A ? A extends { read?: infer R } ? R : never : never;\n update?: GlobalConfig[\"access\"] extends infer A ? A extends { update?: infer U } ? U : never : never;\n };\n /** Site extras, appended after the package catalogue, each with a category. */\n blocks?: readonly BlockLibraryEntry[];\n}\n\n/**\n * Settings → Block library. One card per installed option. Off is editorial\n * availability. The preview route that fills each island is SPI-53.\n */\nexport function createBlockLibrary({\n access,\n blocks = [],\n previewPath,\n}: CreateBlockLibraryOptions): GlobalConfig {\n const options = { blocks, previewPath };\n const catalogue = blockLibraryCatalogue(blocks);\n const previews = Object.fromEntries(catalogue.map((entry) => [entry.slug, previewPath(entry.slug)]));\n const blocksField: ArrayField = {\n name: \"blocks\",\n type: \"array\",\n label: \"Blocks\",\n minRows: catalogue.length,\n maxRows: catalogue.length,\n required: true,\n defaultValue: defaultBlockLibraryValue(options),\n validate: (value, args) => {\n const original = args?.siblingData ?? args?.previousValue;\n const originals = Array.isArray(original) ? stampBlockLibrary(original, options) : undefined;\n return validateBlockLibrary(value, options, { originals });\n },\n hooks: {\n beforeChange: [\n async ({ value, req, originalDoc }) => {\n const stamped = stampBlockLibrary(value, options);\n const stored =\n originalDoc && typeof originalDoc === \"object\" && \"blocks\" in originalDoc\n ? originalDoc.blocks\n : undefined;\n const originals = stampBlockLibrary(stored, options);\n const turningOff = stamped.filter((row) => {\n const before = originals.find((entry) => entry.slug === row.slug);\n return before?.enabled !== false && row.enabled === false;\n });\n for (const row of turningOff) {\n const holders = req?.payload\n ? await documentsHoldingBlock(req.payload as never, row.slug)\n : [];\n const message = await validateBlockLibrary(stamped, options, { originals, holders });\n if (message !== true) throw new Error(message);\n }\n return stamped;\n },\n ],\n },\n admin: {\n components: { Field: BLOCK_LIBRARY_FIELD },\n custom: { previews, rows: defaultBlockLibraryValue(options) },\n },\n fields: [\n { name: \"slug\", type: \"text\", required: true, admin: { readOnly: true } },\n { name: \"label\", type: \"text\", required: true, admin: { readOnly: true } },\n { name: \"category\", type: \"text\", required: true, admin: { readOnly: true } },\n { name: \"enabled\", type: \"checkbox\", admin: { hidden: true } },\n { name: \"kind\", type: \"text\", admin: { hidden: true } },\n ],\n };\n\n return {\n slug: BLOCK_LIBRARY_SLUG,\n label: \"Block library\",\n admin: {\n group: \"Settings\",\n description: \"Which blocks editors may place. An island shows the sample under the published theme.\",\n },\n access: {\n read: access?.read ?? isAuthenticated,\n update: access?.update ?? isAdmin,\n },\n fields: [blocksField],\n };\n}\n","export const FEATURES_MATRIX_FIELD = \"@bison-lab/payload-core/admin#FeaturesMatrixField\";\n","import type { ArrayField, GlobalConfig } from \"payload\";\n\nimport { developerOnlyAccess, hideUnlessDeveloper } from \"../roles/access\";\nimport { FEATURES_MATRIX_FIELD } from \"./fields\";\nimport { defaultFeaturesFieldValue, featureCatalogue, stampFeatureCatalogue, validateFeaturesMatrix } from \"./matrix\";\nimport { FEATURES_SLUG, type FeatureExtra } from \"./types\";\n\nexport interface CreateFeaturesOptions {\n /**\n * Site-only rows after the package catalogue. A second `createFeatures()`\n * without these extras never includes them.\n */\n extras?: readonly FeatureExtra[];\n}\n\n/**\n * Settings → Features. One release switch per catalogue row. Off hides\n * the tick on Roles; Developer still has the feature. This screen is\n * not itself a row.\n */\nexport function createFeatures({ extras = [] }: CreateFeaturesOptions = {}): GlobalConfig {\n const catalogue = featureCatalogue(extras);\n const featuresField: ArrayField = {\n name: \"features\",\n type: \"array\",\n label: \"Features\",\n labels: { singular: \"Feature\", plural: \"Features\" },\n minRows: catalogue.length,\n maxRows: catalogue.length,\n required: true,\n defaultValue: defaultFeaturesFieldValue(extras),\n validate: (value) => validateFeaturesMatrix(value, extras),\n hooks: {\n beforeValidate: [\n ({ value }) => (Array.isArray(value) ? stampFeatureCatalogue(value, extras) : value),\n ],\n beforeChange: [\n ({ value }) => (Array.isArray(value) ? stampFeatureCatalogue(value, extras) : value),\n ],\n },\n admin: {\n components: { Field: FEATURES_MATRIX_FIELD },\n description:\n \"Release a feature so it can be assigned on Roles. Off keeps it Developer-only.\",\n initCollapsed: false,\n },\n fields: [\n { name: \"slug\", type: \"text\", label: \"Slug\", required: true, admin: { readOnly: true } },\n { name: \"label\", type: \"text\", label: \"Name\", required: true, admin: { readOnly: true } },\n { name: \"group\", type: \"text\", label: \"Group\", admin: { hidden: true } },\n { name: \"released\", type: \"checkbox\", label: \"Released\", admin: { hidden: true } },\n ],\n };\n\n return {\n slug: FEATURES_SLUG,\n label: \"Features\",\n admin: {\n group: \"Settings\",\n hidden: hideUnlessDeveloper,\n description: \"Which features other people may be granted on Roles.\",\n },\n access: developerOnlyAccess(),\n fields: [featuresField],\n };\n}\n","import { defaultFeaturesFieldValue } from \"./matrix\";\nimport { FEATURES_SLUG, type FeatureExtra, type FeaturesDoc } from \"./types\";\n\nexport interface SeedFeaturesPayload {\n updateGlobal: (args: { slug: string; data: FeaturesDoc }) => Promise<unknown>;\n}\n\n/**\n * Writes the default switchboard (package rows plus any site extras).\n * For a site's migration `up()`.\n */\nexport async function seedFeatures(\n payload: SeedFeaturesPayload,\n extras: readonly FeatureExtra[] = [],\n): Promise<unknown> {\n return payload.updateGlobal({\n slug: FEATURES_SLUG,\n data: { features: defaultFeaturesFieldValue(extras) },\n });\n}\n","/**\n * The home page is the row whose `pageKey` is `/`. That key is the identifier.\n * The stored slug is an internal token so an unaddressed draft can keep an\n * empty slug without colliding with home. Editors see `/`, never the token.\n */\nexport const ROOT_PAGE_KEY = \"/\";\n\nexport const ROOT_PAGE_SLUG = \"__root__\";\n\nexport const REQUIRED_PAGE_CELL =\n \"@bison-lab/payload-core/admin#RequiredPageCell\";\n\nexport const REQUIRED_PAGE_FIELD =\n \"@bison-lab/payload-core/admin#RequiredPageField\";\n\nexport const PAGE_SLUG_CELL = \"@bison-lab/payload-core/admin#PageSlugCell\";\n\nexport const REQUIRED_PAGE_DELETE_MESSAGE =\n \"This page is required by the site and cannot be deleted.\";\n\nexport const REQUIRED_PAGE_UNPUBLISH_MESSAGE =\n \"This page is required by the site and cannot be unpublished.\";\n\nexport function isRootPageKey(value: unknown): value is typeof ROOT_PAGE_KEY {\n return value === ROOT_PAGE_KEY;\n}\n\nexport function isRequiredPageKey(\n value: unknown,\n requiredKeys: readonly string[],\n): boolean {\n return typeof value === \"string\" && requiredKeys.includes(value);\n}\n\n/** `/` is always required. Extras are site keys, not paths, and cannot be the root token. */\nexport function requiredPageKeys(extra: readonly string[] = []): string[] {\n const keys = [ROOT_PAGE_KEY];\n for (const key of extra) {\n if (key === ROOT_PAGE_KEY || key === ROOT_PAGE_SLUG || key.trim() === \"\") {\n throw new Error(\n `createPages requiredKeys cannot include ${JSON.stringify(key)}. The home page is always \"/\".`,\n );\n }\n if (!keys.includes(key)) keys.push(key);\n }\n return keys;\n}\n","import type {\n CheckboxField,\n CollectionBeforeChangeHook,\n CollectionSlug,\n Field,\n FieldAccess,\n PayloadRequest,\n TextField,\n TextFieldSingleValidation,\n Where,\n} from \"payload\";\nimport { ValidationError, validations } from \"payload\";\n\nimport { isRootPageKey, PAGE_SLUG_CELL, ROOT_PAGE_SLUG } from \"../collections/root-page-key\";\n\nexport const SLUG_FIELD = \"@bison-lab/payload-core/admin#SlugField\";\n\nexport const PAGE_TITLE_CELL = \"@bison-lab/payload-core/admin#PageTitleCell\";\n\n/** Sentinel the Parent control writes while the editor is naming a new folder. */\nexport const NEW_FOLDER_PARENT = \"__new__\";\n\nexport const EXISTING_PARENT_MESSAGE = \"That folder is already in the list. Pick it from the list.\";\n\nexport const SLUG_UNLOCK_WARNING =\n \"This page is live. Changing the address will send visitors from the old URL to the new one.\";\n\nexport interface SlugFieldOptions {\n /** The collection the field sits on — what the duplicate check searches. */\n collection: CollectionSlug;\n /**\n * True when a slug belongs to something the CMS does not own: a path the app\n * already serves from code, or one reserved for the framework. Which paths\n * those are is knowable only to the site, so it arrives as an option.\n */\n isReserved: (slug: string) => boolean;\n /**\n * Standing folder roots the site owns in code (`patients`, `providers`).\n * They appear on Parent even when no CMS page lives under them.\n */\n folderRoots?: string[];\n}\n\ninterface SlugCheckArgs extends SlugFieldOptions {\n id: number | string | undefined;\n pageKey?: unknown;\n req: PayloadRequest | undefined;\n}\n\nfunction pageKeyFrom(...sources: Array<{ pageKey?: unknown } | null | undefined>): unknown {\n for (const source of sources) {\n if (typeof source?.pageKey === \"string\" && source.pageKey) return source.pageKey;\n }\n return undefined;\n}\n\nasync function allSlugs({ collection, id, req }: SlugCheckArgs): Promise<string[]> {\n if (typeof req?.payload?.find !== \"function\") return [];\n\n const where: Where = {};\n if (id !== undefined) where.id = { not_equals: id };\n\n const query = {\n collection,\n depth: 0,\n limit: 500,\n overrideAccess: true,\n pagination: false,\n req,\n where,\n };\n\n const [live, drafts] = await Promise.all([\n req.payload.find(query),\n req.payload.find({ ...query, draft: true }),\n ]);\n\n return [...live.docs, ...drafts.docs].flatMap((doc) =>\n typeof doc.slug === \"string\" && doc.slug ? [doc.slug] : [],\n );\n}\n\nasync function existingParents(\n prefix: string,\n args: SlugCheckArgs,\n): Promise<boolean> {\n const roots = new Set((args.folderRoots ?? []).map(normalizeSlug).filter(Boolean));\n if (roots.has(prefix)) return true;\n\n const slugs = await allSlugs(args);\n if (slugs.includes(prefix)) return true;\n return inferredFolders(slugs).includes(prefix);\n}\n\nfunction slugifySegment(segment: string): string {\n return segment\n .normalize(\"NFKD\")\n .replace(/\\p{M}/gu, \"\")\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n}\n\n/**\n * A stored slug from whatever was typed: NFKD, hyphenated, slash segments\n * kept, so `Café / About Us` becomes `cafe/about-us`.\n */\nexport function normalizeSlug(value: string): string {\n return value.split(\"/\").map(slugifySegment).filter(Boolean).join(\"/\");\n}\n\n/** The folder prefix Parent stores. `__new__` resolves through `newFolder`. */\nexport function parentPrefix(parent: string | null | undefined, newFolder?: string | null): string {\n if (parent === NEW_FOLDER_PARENT) return normalizeSlug(newFolder ?? \"\");\n return typeof parent === \"string\" ? normalizeSlug(parent) : \"\";\n}\n\n/** Last segment of a stored slug — the title leaf once a folder is set. */\nexport function slugLeaf(slug: string): string {\n const parts = normalizeSlug(slug).split(\"/\");\n return parts[parts.length - 1] ?? \"\";\n}\n\n/**\n * Address from a parent prefix and a title (or an existing leaf). Title-follow\n * uses this so a folder is not wiped when the title changes.\n */\nexport function composeSlug(\n parent: string | null | undefined,\n title: string,\n newFolder?: string | null,\n): string {\n const prefix = parentPrefix(parent, newFolder);\n const leaf = slugifySegment(title);\n return prefix ? `${prefix}/${leaf}` : leaf;\n}\n\n/** Prefixes that exist only because a child slug lives under them. */\nexport function inferredFolders(slugs: string[]): string[] {\n const folders = new Set<string>();\n for (const slug of slugs) {\n const parts = normalizeSlug(slug).split(\"/\");\n for (let i = 1; i < parts.length; i += 1) {\n folders.add(parts.slice(0, i).join(\"/\"));\n }\n }\n return [...folders].sort();\n}\n\n/** Slash count after the first segment — how far to indent a list row. */\nexport function slugDepth(slug: string): number {\n const normalized = normalizeSlug(slug);\n if (!normalized) return 0;\n return normalized.split(\"/\").length - 1;\n}\n\nfunction resolvePrefix(\n ...sources: Array<{ parent?: unknown; newFolder?: unknown } | undefined>\n): { parent: string | undefined; newFolder: string | undefined } {\n let parent: string | undefined;\n let newFolder: string | undefined;\n for (const source of sources) {\n if (parent === undefined && typeof source?.parent === \"string\") parent = source.parent;\n if (newFolder === undefined && typeof source?.newFolder === \"string\") newFolder = source.newFolder;\n }\n return { parent, newFolder };\n}\n\nfunction isLockedDoc(doc: { slugLocked?: unknown; publishedSlug?: unknown } | undefined): boolean {\n return Boolean(doc?.slugLocked || doc?.publishedSlug);\n}\n\nfunction isUnlocking(data: { slugUnlock?: unknown } | undefined): boolean {\n return Boolean(data?.slugUnlock);\n}\n\nasync function slugProblem(\n slug: string,\n { collection, id, isReserved, pageKey, req }: SlugCheckArgs,\n): Promise<string | undefined> {\n if (!slug) return undefined;\n\n if (slug === ROOT_PAGE_SLUG && !isRootPageKey(pageKey)) {\n return \"That address is reserved for the home page. Please choose a different address.\";\n }\n\n if (isReserved(slug)) {\n return `\"/${slug}\" is a built-in page on this site, so a page here cannot use it. Please choose a different address.`;\n }\n\n if (typeof req?.payload?.find !== \"function\") return undefined;\n\n const where: Where = { slug: { equals: slug } };\n if (id !== undefined) {\n where.id = { not_equals: id };\n }\n\n const query = {\n collection,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n where,\n };\n\n const live = await req.payload.find(query);\n const taken =\n live.docs.length > 0 || (await req.payload.find({ ...query, draft: true })).docs.length > 0;\n\n return taken ? `Another page is already using \"/${slug}\". Please choose a different address.` : undefined;\n}\n\nconst slugUpdateAccess =\n (collection: CollectionSlug): FieldAccess =>\n async ({ doc, id, req, siblingData }) => {\n if (isRootPageKey(pageKeyFrom(doc, siblingData))) return false;\n if (isUnlocking(siblingData)) return true;\n if (isLockedDoc(doc)) return false;\n if (id === undefined || typeof req?.payload?.findByID !== \"function\") return true;\n try {\n const published = await req.payload.findByID({\n collection,\n id,\n depth: 0,\n draft: false,\n overrideAccess: true,\n req,\n });\n return published?._status !== \"published\";\n } catch {\n return true;\n }\n };\n\n/**\n * Locks the slug on first publish and remembers the live path so a later\n * change can write a redirect. Unlock is a one-save flag and is cleared here.\n */\nexport const lockSlugOnPublish: CollectionBeforeChangeHook = ({ data }) => {\n if (!data) return data;\n data.slugUnlock = false;\n if (data._status === \"published\") {\n data.slugLocked = true;\n if (typeof data.slug === \"string\") data.publishedSlug = data.slug;\n }\n return data;\n};\n\nfunction hiddenCheckbox(name: string, label: string): CheckboxField {\n return {\n name,\n type: \"checkbox\",\n label,\n defaultValue: false,\n admin: { hidden: true },\n };\n}\n\n/**\n * The path a document is published at, normalised on the way in. Unique\n * across the collection. Follows `title` until first publish, then locks.\n * `validate` is the message under the field; `beforeChange` is the enforcement\n * on a draft save, where Payload skips field validation.\n */\nexport function slugField({ collection, isReserved, folderRoots = [] }: SlugFieldOptions): Field[] {\n const validate: TextFieldSingleValidation = async (value, options) => {\n try {\n const builtIn = await validations.text(value, options);\n if (builtIn !== true) return builtIn;\n } catch {\n // form-state without a request still runs the reserved / duplicate checks\n }\n\n const problem = await slugProblem(typeof value === \"string\" ? value : \"\", {\n collection,\n id: options.id,\n isReserved,\n pageKey: pageKeyFrom(options.data, options.siblingData),\n req: options.req,\n });\n return problem ?? true;\n };\n\n const slug: TextField = {\n name: \"slug\",\n type: \"text\",\n required: true,\n unique: true,\n access: { update: slugUpdateAccess(collection) },\n admin: {\n description: 'Path under the site root, no leading slash: \"about-us\" or \"patients/stories\".',\n components: { Field: SLUG_FIELD, Cell: PAGE_SLUG_CELL },\n custom: { folderRoots },\n },\n hooks: {\n beforeValidate: [\n ({ data, originalDoc, siblingData, value }) => {\n if (isRootPageKey(pageKeyFrom(data, siblingData, originalDoc))) return ROOT_PAGE_SLUG;\n const title = typeof data?.title === \"string\" ? data.title : \"\";\n const { parent, newFolder } = resolvePrefix(siblingData, data, originalDoc);\n if (!isLockedDoc(originalDoc) && !isUnlocking(data) && !isUnlocking(siblingData) && title) {\n return composeSlug(parent, title, newFolder);\n }\n if ((isUnlocking(data) || isUnlocking(siblingData)) && (parent !== undefined || newFolder)) {\n const leaf =\n typeof value === \"string\" && value ? slugLeaf(value) : title ? slugifySegment(title) : \"\";\n return composeSlug(parent, leaf, newFolder);\n }\n return typeof value === \"string\" ? normalizeSlug(value) : value;\n },\n ],\n beforeChange: [\n async ({ data, originalDoc, req, siblingData, value }) => {\n if (isRootPageKey(pageKeyFrom(data, siblingData, originalDoc))) return ROOT_PAGE_SLUG;\n if (typeof value !== \"string\") return value;\n\n const problem = await slugProblem(value, {\n collection,\n id: originalDoc?.id ?? data?.id,\n isReserved,\n pageKey: pageKeyFrom(data, siblingData, originalDoc),\n req,\n });\n if (problem) {\n throw new ValidationError(\n { collection, errors: [{ message: problem, path: \"slug\" }], req },\n req?.t,\n );\n }\n return value;\n },\n ],\n },\n validate,\n };\n\n const parent: TextField = {\n name: \"parent\",\n type: \"text\",\n defaultValue: \"\",\n access: { update: slugUpdateAccess(collection) },\n admin: { hidden: true },\n hooks: {\n beforeValidate: [\n ({ data, originalDoc, siblingData, value }) => {\n const { newFolder } = resolvePrefix(siblingData, data, originalDoc);\n if (value === NEW_FOLDER_PARENT) return parentPrefix(NEW_FOLDER_PARENT, newFolder);\n return typeof value === \"string\" ? normalizeSlug(value) : \"\";\n },\n ],\n },\n validate: async (value, options) => {\n const { newFolder } = resolvePrefix(options.siblingData, options.data);\n if (value !== NEW_FOLDER_PARENT && !newFolder) return true;\n\n const prefix = parentPrefix(NEW_FOLDER_PARENT, newFolder);\n if (!prefix) return true;\n\n const taken = await existingParents(prefix, {\n collection,\n folderRoots,\n id: options.id,\n isReserved,\n req: options.req,\n });\n return taken ? EXISTING_PARENT_MESSAGE : true;\n },\n };\n\n const newFolder: TextField = {\n name: \"newFolder\",\n type: \"text\",\n admin: { hidden: true },\n access: { update: slugUpdateAccess(collection) },\n };\n\n return [\n parent,\n newFolder,\n slug,\n hiddenCheckbox(\"slugLocked\", \"Slug locked\"),\n hiddenCheckbox(\"slugUnlock\", \"Unlock slug\"),\n {\n name: \"publishedSlug\",\n type: \"text\",\n label: \"Published slug\",\n admin: { hidden: true },\n },\n ];\n}\n","import {\n APIError,\n type Access,\n type CollectionBeforeChangeHook,\n type CollectionBeforeDeleteHook,\n type Payload,\n type Where,\n} from \"payload\";\n\nimport {\n isRequiredPageKey,\n isRootPageKey,\n REQUIRED_PAGE_DELETE_MESSAGE,\n REQUIRED_PAGE_UNPUBLISH_MESSAGE,\n ROOT_PAGE_KEY,\n ROOT_PAGE_SLUG,\n} from \"./root-page-key\";\n\nfunction isDraftVersionWrite(\n req: { query?: Record<string, unknown> } | undefined,\n): boolean {\n const draft = req?.query?.draft;\n return draft === \"true\" || draft === true;\n}\n\n/**\n * Keeps a required key once set, and pins the home row to `/`: empty parent,\n * the internal slug, locked, with no unlock.\n */\nexport const keepRequiredPage: CollectionBeforeChangeHook = ({\n data,\n originalDoc,\n operation,\n}) => {\n if (!data) return data;\n if (\n operation === \"update\" &&\n typeof originalDoc?.pageKey === \"string\" &&\n originalDoc.pageKey\n ) {\n data.pageKey = originalDoc.pageKey;\n }\n if (isRootPageKey(data.pageKey) || isRootPageKey(originalDoc?.pageKey)) {\n data.pageKey = ROOT_PAGE_KEY;\n data.slug = ROOT_PAGE_SLUG;\n data.parent = \"\";\n data.slugLocked = true;\n data.slugUnlock = false;\n }\n return data;\n};\n\nexport function refuseRequiredUnpublish(\n requiredKeys: readonly string[],\n): CollectionBeforeChangeHook {\n return ({ data, originalDoc, req }) => {\n if (!data) return data;\n if (!isRequiredPageKey(originalDoc?.pageKey, requiredKeys)) return data;\n if (data._status !== \"draft\") return data;\n if (originalDoc?._status !== \"published\") return data;\n if (isDraftVersionWrite(req)) return data;\n throw new APIError(REQUIRED_PAGE_UNPUBLISH_MESSAGE, 400);\n };\n}\n\nexport function refuseRequiredPageDelete(\n requiredKeys: readonly string[],\n): CollectionBeforeDeleteHook {\n return async ({ id, req }) => {\n const doc = await req.payload.findByID({\n collection: \"pages\",\n id,\n depth: 0,\n overrideAccess: true,\n });\n if (isRequiredPageKey(doc.pageKey, requiredKeys)) {\n throw new APIError(REQUIRED_PAGE_DELETE_MESSAGE, 400);\n }\n };\n}\n\nexport function withRequiredPageDeleteLock(\n base: Access | undefined,\n requiredKeys: readonly string[],\n): Access {\n return async (args) => {\n const allowed =\n typeof base === \"function\" ? await base(args) : (base ?? true);\n if (allowed === false) return false;\n if (args.id != null) {\n try {\n const doc = await args.req.payload.findByID({\n collection: \"pages\",\n id: args.id,\n depth: 0,\n overrideAccess: true,\n });\n if (isRequiredPageKey(doc.pageKey, requiredKeys)) return false;\n } catch {\n // Missing id: let the delete operation report that itself.\n }\n }\n const keyedOut: Where = {\n or: [\n { pageKey: { exists: false } },\n { pageKey: { not_in: [...requiredKeys] } },\n ],\n };\n if (allowed === true) return keyedOut;\n return { and: [allowed, keyedOut] };\n };\n}\n\n/**\n * Creates the home page when it is missing. Safe to call from `onInit`.\n * Identity fields win over `data`: `pageKey` is `/`, the stored slug is the\n * internal token, and the row is published. Pass the hero and a section —\n * publish still requires both. The document title defaults to \"Home\"; that\n * word is the title, not the identifier.\n */\nexport async function ensureRootPage(\n payload: Payload,\n data: Record<string, unknown> = {},\n): Promise<unknown> {\n const found = await payload.find({\n collection: \"pages\",\n where: { pageKey: { equals: ROOT_PAGE_KEY } },\n overrideAccess: true,\n depth: 0,\n limit: 1,\n pagination: false,\n });\n if (found.docs[0]) return found.docs[0];\n\n return payload.create({\n collection: \"pages\",\n overrideAccess: true,\n data: {\n title: \"Home\",\n ...data,\n slug: ROOT_PAGE_SLUG,\n parent: \"\",\n pageKey: ROOT_PAGE_KEY,\n slugLocked: true,\n slugUnlock: false,\n _status: \"published\",\n },\n });\n}\n","import type { Access, Block, CollectionBeforeValidateHook, CollectionConfig } from \"payload\";\nimport { ValidationError } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { lockSlugOnPublish, PAGE_TITLE_CELL, slugField } from \"../fields/slug\";\nimport { authenticatedOrPublished, canPublish, isAdmin, isAuthenticated } from \"../roles/access\";\nimport {\n keepRequiredPage,\n refuseRequiredPageDelete,\n refuseRequiredUnpublish,\n withRequiredPageDeleteLock,\n} from \"./root-page\";\nimport {\n isRootPageKey,\n REQUIRED_PAGE_CELL,\n REQUIRED_PAGE_FIELD,\n requiredPageKeys,\n ROOT_PAGE_KEY,\n} from \"./root-page-key\";\n\n/** Standing copy on the Layout field — same job as the hero description. */\nexport const LAYOUT_DESCRIPTION =\n \"Every page needs at least one section below the hero. A page cannot be published without one.\";\n\n/** Field error when Publish is clicked with an empty body. */\nexport const LAYOUT_REQUIRED_MESSAGE =\n \"Add at least one section. A page cannot be published without one.\";\n\n/**\n * Toast label for that error. Payload's envelope is always\n * \"The following field is invalid: {label}\", so the label has to name the fix.\n */\nexport const LAYOUT_REQUIRED_LABEL = \"Layout — add a section\";\n\nfunction layoutRows(\n data: { layout?: unknown } | undefined,\n originalDoc: { layout?: unknown } | undefined,\n): unknown[] {\n if (data && \"layout\" in data && data.layout !== undefined) {\n return Array.isArray(data.layout) ? data.layout : [];\n }\n return Array.isArray(originalDoc?.layout) ? originalDoc.layout : [];\n}\n\n/**\n * Drafts may be empty. Publish with no section is refused here so the toast\n * names the fix — Payload's built-in minRows toast only says \"Content → Layout\".\n */\nexport const requireLayoutOnPublish: CollectionBeforeValidateHook = ({ collection, data, originalDoc, req }) => {\n if (!data || data._status !== \"published\") return data;\n if (layoutRows(data, originalDoc as { layout?: unknown } | undefined).length >= 1) return data;\n throw new ValidationError(\n {\n collection: typeof collection?.slug === \"string\" ? collection.slug : \"pages\",\n errors: [{ label: LAYOUT_REQUIRED_LABEL, message: LAYOUT_REQUIRED_MESSAGE, path: \"layout\" }],\n req,\n },\n req?.t,\n );\n};\n\n/**\n * Content to create or save a draft; Publish to publish or edit a live\n * page. Without Publish, update is constrained to `_status: draft`.\n */\nconst pagesUpdate: Access = async (args) => {\n const canEdit = await Promise.resolve(canUseFeature(\"content\")(args));\n if (!canEdit) return false;\n if (await Promise.resolve(canPublish(args))) return true;\n return { _status: { equals: \"draft\" } };\n};\n\nexport interface PagesOptions {\n /**\n * What a page may open with. One row, so this is the site's hero variants,\n * not a list a page picks several from.\n */\n heroBlocks: Block[];\n /** The sections a page body can be built out of. */\n layoutBlocks: Block[];\n /**\n * True when a slug is not the CMS's to hand out — a path the app already\n * serves from code, or one the framework reserves.\n */\n isReservedSlug: (slug: string) => boolean;\n /**\n * Public path of a page from its stored slug — the site's own route helper.\n * Drives the page preview overlay's iframe.\n */\n previewPath: (slug: string) => string;\n /**\n * Component path for Payload's native Preview button, as a key into the\n * site's committed `importMap.js`. Omit it for Payload's own button.\n */\n previewButton?: string;\n /**\n * Standing folder roots (`patients`, `providers`). Shown on Parent even\n * when no CMS page lives under them. Often the same paths `isReservedSlug`\n * refuses as leaf pages.\n */\n folderRoots?: string[];\n /**\n * Other pages that cannot be deleted or unpublished, besides the home page.\n * Keys, not paths (`find-a-doctor`). Home is always required and is not\n * listed here: its key is `/`.\n */\n requiredKeys?: readonly string[];\n}\n\n/**\n * CMS-managed pages: one required hero, then a reorderable body of sections.\n * The CMS owns copy and the order of sections; what a section looks like is\n * code-owned, which is why the blocks are an argument.\n */\nexport function createPages({\n folderRoots,\n heroBlocks,\n isReservedSlug,\n layoutBlocks,\n previewPath,\n previewButton,\n requiredKeys: extraRequiredKeys,\n}: PagesOptions): CollectionConfig {\n const [defaultHero] = heroBlocks;\n if (!defaultHero) throw new Error(\"createPages needs at least one hero block\");\n const keys = requiredPageKeys(extraRequiredKeys);\n\n return {\n slug: \"pages\",\n defaultSort: \"slug\",\n admin: {\n useAsTitle: \"title\",\n group: \"Content\",\n defaultColumns: [\"title\", \"pageKey\", \"slug\", \"_status\", \"updatedAt\"],\n hidden: hideUnlessFeature(\"content\") as (args: { user: unknown }) => boolean,\n // Home is previewed as `/`. An empty slug is still \"no address yet\".\n preview: (doc) =>\n previewPath(isRootPageKey(doc?.pageKey) ? ROOT_PAGE_KEY : typeof doc?.slug === \"string\" ? doc.slug : \"\"),\n ...(previewButton ? { components: { edit: { PreviewButton: previewButton } } } : {}),\n },\n access: {\n read: authenticatedOrPublished,\n readVersions: isAuthenticated,\n create: canUseFeature(\"content\"),\n update: pagesUpdate,\n delete: withRequiredPageDeleteLock(isAdmin, keys),\n },\n versions: {\n drafts: { autosave: { interval: 375 } },\n maxPerDoc: 50,\n },\n hooks: {\n beforeValidate: [requireLayoutOnPublish],\n beforeChange: [keepRequiredPage, lockSlugOnPublish, refuseRequiredUnpublish(keys)],\n beforeDelete: [refuseRequiredPageDelete(keys)],\n },\n fields: [\n {\n name: \"title\",\n type: \"text\",\n required: true,\n admin: { components: { Cell: PAGE_TITLE_CELL } },\n },\n {\n name: \"pageKey\",\n type: \"text\",\n label: \"Required\",\n unique: true,\n index: true,\n access: {\n create: () => false,\n update: () => false,\n },\n admin: {\n disableListFilter: true,\n components: { Field: REQUIRED_PAGE_FIELD, Cell: REQUIRED_PAGE_CELL },\n },\n },\n ...slugField({ collection: \"pages\", folderRoots, isReserved: isReservedSlug }),\n {\n name: \"hero\",\n type: \"blocks\",\n required: true,\n minRows: 1,\n maxRows: 1,\n blocks: heroBlocks,\n defaultValue: [{ blockType: defaultHero.slug }],\n admin: {\n description: \"Every page opens with one hero. A page cannot be published without one.\",\n },\n },\n {\n name: \"layout\",\n type: \"blocks\",\n required: true,\n minRows: 1,\n blocks: layoutBlocks,\n labels: { singular: \"Section\", plural: \"Sections\" },\n admin: {\n description: LAYOUT_DESCRIPTION,\n },\n },\n ],\n };\n}\n","import type {\n CollectionConfig,\n PayloadRequest,\n SelectFieldManyValidation,\n TextField,\n TextFieldSingleValidation,\n Where,\n} from \"payload\";\nimport { APIError } from \"payload\";\nimport { select, text } from \"payload/shared\";\n\nimport { allowedFeaturesForUser, canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { getRolesMatrix, isAdmin, isAdminOrSelf, isPrivilegedRole } from \"../roles/access\";\nimport { ROLES_FIELD } from \"../roles/fields\";\nimport { normalizeStoredRoles, roleSelectOptions, seedRoleRows } from \"../roles/matrix\";\nimport type { RoleExtra, RoleRow } from \"../roles/types\";\n\nconst nameValidate: TextFieldSingleValidation = (value, options) => {\n if (options.operation === \"update\" && value === \"\" && options.previousValue === \"\") return true;\n return text(value, options);\n};\n\nfunction nameField(name: \"firstName\" | \"lastName\"): TextField {\n return { name, type: \"text\", required: true, validate: nameValidate };\n}\n\n/** Refuses the save that would remove Users from the only privileged user. */\nexport const LAST_ADMIN_DEMOTE_MESSAGE = \"Make another user an admin before removing it from this one.\";\n/** Refuses the delete that would remove the only privileged user. */\nexport const LAST_ADMIN_DELETE_MESSAGE = \"Make another user an admin before deleting this one.\";\n\ninterface TransactionalAdapter {\n execute?: (args: { db?: unknown; raw?: string }) => Promise<unknown>;\n sessions?: Record<string, { db: unknown } | undefined>;\n}\n\nconst LAST_ADMIN_LOCK = \"select pg_advisory_xact_lock(hashtext('users:last-admin'))\";\n\nasync function lockLastAdminDecision(req: PayloadRequest): Promise<void> {\n const { execute, sessions } = req.payload.db as unknown as TransactionalAdapter;\n const id = req.transactionID;\n const session = typeof id === \"string\" || typeof id === \"number\" ? sessions?.[id] : undefined;\n if (!session || typeof execute !== \"function\") return;\n await execute({ db: session.db, raw: LAST_ADMIN_LOCK });\n}\n\nfunction privilegedRoles(matrix: readonly RoleRow[]): string[] {\n return matrix.filter((row) => isPrivilegedRole(row.role, matrix)).map((row) => row.role);\n}\n\nfunction holdsPrivilegedRole(roles: unknown, matrix: readonly RoleRow[]): boolean {\n return Array.isArray(roles) && roles.some((role) => isPrivilegedRole(role, matrix));\n}\n\nfunction privilegedWhere(matrix: readonly RoleRow[]): Where {\n const roles = privilegedRoles(matrix);\n if (roles.length === 0) return { id: { equals: \"__none__\" } };\n return { or: roles.map((role) => ({ roles: { contains: role } })) };\n}\n\nasync function adminCount(req: PayloadRequest, excluding?: number | string): Promise<number> {\n await lockLastAdminDecision(req);\n const matrix = await getRolesMatrix(req);\n const holdsPrivileged = privilegedWhere(matrix);\n const { totalDocs } = await req.payload.count({\n collection: \"users\",\n overrideAccess: true,\n req,\n where:\n excluding === undefined\n ? holdsPrivileged\n : { and: [holdsPrivileged, { id: { not_equals: excluding } }] },\n });\n return totalDocs;\n}\n\nfunction rolesValidate(extras: readonly RoleExtra[]): SelectFieldManyValidation {\n return async (value, options) => {\n const matrix = await getRolesMatrix(options.req, extras);\n const builtIn = select(value, { ...options, options: roleSelectOptions(matrix) });\n if (builtIn !== true) return builtIn;\n if (options.operation !== \"update\" || options.id === undefined) return true;\n if (holdsPrivilegedRole(value, matrix) || !holdsPrivilegedRole(options.previousValue, matrix)) {\n return true;\n }\n return (await adminCount(options.req, options.id)) > 0 ? true : LAST_ADMIN_DEMOTE_MESSAGE;\n };\n}\n\nexport interface UsersOptions {\n /**\n * Whether the auth cookie is marked Secure. Passed in rather than read from\n * the environment here: which env var means \"served over HTTPS\" is the\n * host's business, not the CMS's.\n */\n secureCookies: boolean;\n /**\n * Component path for the roles field, as a key into the site's committed\n * `importMap.js`. Defaults to the package checklist. A value nothing\n * resolves renders the field as nothing.\n */\n rolesField?: string;\n /**\n * Same extras passed to `createRoles`. Offered on Users when the Global\n * is empty; a saved Global (including Admin-added rows) wins.\n */\n extras?: readonly RoleExtra[];\n}\n\nexport function createUsers({ secureCookies, rolesField, extras = [] }: UsersOptions): CollectionConfig {\n const fallback = seedRoleRows(extras);\n return {\n slug: \"users\",\n auth: {\n maxLoginAttempts: 5,\n lockTime: 10 * 60 * 1000,\n tokenExpiration: 2 * 60 * 60,\n cookies: {\n sameSite: \"Lax\",\n secure: secureCookies,\n },\n },\n admin: {\n group: \"Settings\",\n useAsTitle: \"email\",\n defaultColumns: [\"email\", \"firstName\", \"lastName\", \"roles\"],\n hidden: hideUnlessFeature(\"users\") as (args: { user: unknown }) => boolean,\n },\n access: {\n create: isAdmin,\n delete: isAdmin,\n unlock: isAdmin,\n read: async (args) => {\n if (await Promise.resolve(canUseFeature(\"users\")(args))) return true;\n return isAdminOrSelf(args);\n },\n update: isAdminOrSelf,\n },\n hooks: {\n beforeDelete: [\n async ({ id, req }) => {\n const doomed = await req.payload.findByID({\n collection: \"users\",\n id,\n depth: 0,\n disableErrors: true,\n overrideAccess: true,\n req,\n });\n const matrix = await getRolesMatrix(req, extras);\n if (!isAdmin(doomed, matrix) || (await adminCount(req, id)) > 0) return;\n throw new APIError(LAST_ADMIN_DELETE_MESSAGE, 400);\n },\n ],\n afterOperation: [\n async (arg) => {\n const { operation, req } = arg;\n const touchesRoles =\n (operation === \"update\" || operation === \"updateByID\") &&\n arg.args.data?.roles !== undefined;\n const deletes = operation === \"delete\" || operation === \"deleteByID\";\n if ((touchesRoles || deletes) && (await adminCount(req)) === 0) {\n throw new APIError(deletes ? LAST_ADMIN_DELETE_MESSAGE : LAST_ADMIN_DEMOTE_MESSAGE, 400);\n }\n return arg.result;\n },\n ],\n },\n fields: [\n {\n type: \"row\",\n fields: [nameField(\"firstName\"), nameField(\"lastName\")],\n },\n {\n name: \"roles\",\n type: \"select\",\n hasMany: true,\n required: true,\n saveToJWT: true,\n // Seed plus site extras. filterOptions replaces this with the saved\n // Global (labels and Admin-added slugs) when that row is readable.\n options: roleSelectOptions(fallback),\n admin: {\n components: { Field: rolesField ?? ROLES_FIELD },\n description: \"One person can hold several, e.g. Author + Designer.\",\n },\n access: {\n update: isAdmin,\n },\n validate: rolesValidate(extras),\n hooks: {\n beforeValidate: [\n async ({ value, req }) => {\n if (!Array.isArray(value)) return value;\n return normalizeStoredRoles(value, await getRolesMatrix(req, extras));\n },\n ],\n },\n },\n {\n name: \"allowedFeatures\",\n type: \"json\",\n admin: { hidden: true, readOnly: true },\n access: { update: () => false },\n saveToJWT: true,\n hooks: {\n afterRead: [\n async ({ siblingData, data, req }) =>\n allowedFeaturesForUser(\n {\n id: (siblingData?.id ?? data?.id) as string | number | undefined,\n roles: (siblingData?.roles ?? data?.roles) as readonly string[] | undefined,\n },\n req ?? {},\n ),\n ],\n },\n },\n ],\n };\n}\n","/** The name the editor just chose, or the stored filename on an existing row. */\nexport function filenameFromUpload(file: unknown, filename: unknown): string {\n if (typeof File !== \"undefined\" && file instanceof File) return file.name;\n if (typeof filename === \"string\") return filename;\n return \"\";\n}\n\n/** Alt text from an upload filename: drop the extension, hyphenate the rest. */\nexport function altFromFilename(filename: unknown): string {\n if (typeof filename !== \"string\") return \"\";\n return filename\n .trim()\n .replace(/\\.[a-z0-9]{1,5}$/i, \"\")\n .replace(/[_\\s]+/g, \"-\");\n}\n\n/**\n * Fill while Alt is empty or still the last auto value. Stop once the editor\n * types something else.\n */\nexport function shouldFillMediaAlt(existing: unknown, generated: string, lastAuto: string): boolean {\n if (!generated) return false;\n const current = typeof existing === \"string\" ? existing.trim() : \"\";\n if (current === generated) return false;\n if (!current) return true;\n return current === lastAuto;\n}\n\nexport function fillBlankAltFromFilename<T extends { alt?: unknown; filename?: unknown }>(data: T): T {\n if (data.alt != null && data.alt !== \"\") return data;\n const generated = altFromFilename(data.filename);\n if (generated) data.alt = generated;\n return data;\n}\n","/** Import-map strings and route paths shared by createMedia and admin views. */\nexport const MEDIA_LIST = \"@bison-lab/payload-core/admin#MediaListView\";\nexport const MEDIA_ALT_AUTOFILL = \"@bison-lab/payload-core/admin#MediaAltAutofill\";\nexport const MEDIA_IN_USE_PATH = \"/in-use\";\n","/**\n * Where a media id is referenced. Walks live field config — upload /\n * relationship paths whose relationTo includes media — plus Lexical\n * `upload` nodes. Does not guess from key names.\n */\n\nexport type MediaInUseScopes = true | { collections?: string[]; globals?: string[] };\n\nexport interface MediaInUsePayload {\n find: (args: {\n collection: string;\n draft?: boolean;\n depth?: number;\n limit?: number;\n page?: number;\n overrideAccess?: boolean;\n where?: Record<string, unknown>;\n }) => Promise<{ docs: Record<string, unknown>[]; totalPages?: number }>;\n findGlobal: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n }) => Promise<Record<string, unknown> | null | undefined>;\n collections?: Record<string, { config?: CollectionShape }>;\n globals?: { config?: GlobalShape[] };\n config?: {\n collections?: CollectionShape[];\n globals?: GlobalShape[];\n };\n}\n\ntype CollectionShape = {\n slug?: string;\n fields?: FieldLike[];\n versions?: unknown;\n};\n\ntype GlobalShape = {\n slug?: string;\n fields?: FieldLike[];\n};\n\ntype FieldLike = {\n type?: string;\n name?: string;\n relationTo?: string | string[];\n fields?: FieldLike[];\n tabs?: { fields?: FieldLike[] }[];\n blocks?: { slug?: string; fields?: FieldLike[] }[];\n};\n\nconst MEDIA = \"media\";\n\nexport async function findMediaInUse(\n payload: MediaInUsePayload,\n scopes: MediaInUseScopes,\n): Promise<Set<string>> {\n const { collections, globals } = resolveScopes(payload, scopes);\n const ids = new Set<string>();\n const errors: string[] = [];\n for (const slug of collections) {\n const config = collectionOf(payload, slug);\n const publishedOnly = collectionHasDrafts(config);\n try {\n for await (const doc of eachCollectionDoc(payload, slug, publishedOnly)) {\n collectFromFields(config?.fields ?? [], doc, ids);\n }\n } catch {\n errors.push(slug);\n }\n }\n for (const slug of globals) {\n const config = globalOf(payload, slug);\n try {\n const doc = await readGlobal(payload, slug);\n if (!doc) continue;\n collectFromFields(config?.fields ?? [], doc, ids);\n } catch {\n errors.push(slug);\n }\n }\n if (errors.length > 0) {\n throw new Error(`Media in-use scan failed for: ${errors.join(\", \")}`);\n }\n return ids;\n}\n\nexport function resolveScopes(\n payload: MediaInUsePayload,\n scopes: MediaInUseScopes,\n): { collections: string[]; globals: string[] } {\n if (scopes === true) {\n return {\n collections: slugsOf(payload.config?.collections ?? payload.collections).filter(\n (slug) => !slug.startsWith(\"payload-\") && slug !== MEDIA,\n ),\n globals: slugsOf(payload.config?.globals ?? payload.globals?.config),\n };\n }\n return {\n collections: (scopes.collections ?? []).filter((slug) => slug !== MEDIA),\n globals: scopes.globals ?? [],\n };\n}\n\nfunction collectionOf(payload: MediaInUsePayload, slug: string): CollectionShape | undefined {\n const live = payload.collections?.[slug]?.config;\n if (live) return live;\n return payload.config?.collections?.find((entry) => entry.slug === slug);\n}\n\nfunction globalOf(payload: MediaInUsePayload, slug: string): GlobalShape | undefined {\n return (\n payload.config?.globals?.find((entry) => entry.slug === slug) ??\n payload.globals?.config?.find((entry) => entry.slug === slug)\n );\n}\n\nfunction collectionHasDrafts(config: CollectionShape | undefined): boolean {\n const versions = config?.versions;\n if (!versions || typeof versions !== \"object\") return false;\n return Boolean((versions as { drafts?: unknown }).drafts);\n}\n\nfunction slugsOf(value: { slug?: string }[] | Record<string, unknown> | undefined): string[] {\n if (Array.isArray(value)) {\n return value.map((item) => item?.slug).filter((slug): slug is string => Boolean(slug));\n }\n if (value && typeof value === \"object\") return Object.keys(value);\n return [];\n}\n\nasync function readGlobal(\n payload: MediaInUsePayload,\n slug: string,\n): Promise<Record<string, unknown> | null | undefined> {\n return payload.findGlobal({ slug, depth: 0, overrideAccess: true });\n}\n\nasync function* eachCollectionDoc(\n payload: MediaInUsePayload,\n collection: string,\n publishedOnly: boolean,\n): AsyncGenerator<Record<string, unknown>> {\n let page = 1;\n for (;;) {\n let result: { docs: Record<string, unknown>[]; totalPages?: number };\n result = await payload.find({\n collection,\n depth: 0,\n limit: 100,\n page,\n overrideAccess: true,\n ...(publishedOnly ? { where: { _status: { equals: \"published\" } } } : {}),\n });\n for (const doc of result.docs) yield doc;\n const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);\n if (page >= totalPages || result.docs.length === 0) break;\n page += 1;\n }\n}\n\nfunction collectFromFields(fields: FieldLike[], doc: unknown, ids: Set<string>): void {\n for (const field of fields) {\n if (!field) continue;\n if (field.type === \"tabs\") {\n for (const tab of field.tabs ?? []) collectFromFields(tab.fields ?? [], doc, ids);\n continue;\n }\n if (field.type === \"row\" || field.type === \"collapsible\") {\n collectFromFields(field.fields ?? [], doc, ids);\n continue;\n }\n if (field.type === \"group\") {\n collectFromFields(field.fields ?? [], field.name ? get(doc, field.name) : doc, ids);\n continue;\n }\n if (field.type === \"array\" && field.name) {\n const rows = get(doc, field.name);\n if (Array.isArray(rows)) {\n for (const row of rows) collectFromFields(field.fields ?? [], row, ids);\n }\n continue;\n }\n if (field.type === \"blocks\" && field.name) {\n const rows = get(doc, field.name);\n if (Array.isArray(rows)) {\n for (const row of rows) {\n if (!row || typeof row !== \"object\") continue;\n const type = (row as { blockType?: string }).blockType;\n const block = field.blocks?.find((entry) => entry.slug === type);\n if (block) collectFromFields(block.fields ?? [], row, ids);\n }\n }\n continue;\n }\n if (\n (field.type === \"upload\" || field.type === \"relationship\") &&\n field.name &&\n relationToMedia(field.relationTo)\n ) {\n collectMediaIds(get(doc, field.name), ids);\n continue;\n }\n if (field.type === \"richText\" && field.name) {\n collectLexicalUploads(get(doc, field.name), ids);\n }\n }\n}\n\nfunction relationToMedia(relationTo: string | string[] | undefined): boolean {\n if (relationTo === MEDIA) return true;\n return Array.isArray(relationTo) && relationTo.includes(MEDIA);\n}\n\nfunction collectMediaIds(value: unknown, ids: Set<string>): void {\n if (value == null) return;\n if (typeof value === \"number\" || typeof value === \"string\") {\n ids.add(String(value));\n return;\n }\n if (Array.isArray(value)) {\n for (const item of value) collectMediaIds(item, ids);\n return;\n }\n if (typeof value === \"object\") {\n const obj = value as { relationTo?: string; value?: unknown; id?: unknown };\n if (obj.relationTo && obj.relationTo !== MEDIA) return;\n collectMediaIds(obj.value ?? obj.id, ids);\n }\n}\n\nfunction collectLexicalUploads(node: unknown, ids: Set<string>): void {\n if (!node || typeof node !== \"object\") return;\n const obj = node as {\n type?: string;\n relationTo?: string;\n value?: unknown;\n children?: unknown[];\n root?: unknown;\n };\n if (obj.type === \"upload\" && (obj.relationTo == null || obj.relationTo === MEDIA)) {\n collectMediaIds(obj.value, ids);\n }\n if (obj.root) collectLexicalUploads(obj.root, ids);\n if (Array.isArray(obj.children)) {\n for (const child of obj.children) collectLexicalUploads(child, ids);\n }\n}\n\nfunction get(doc: unknown, name: string): unknown {\n if (!doc || typeof doc !== \"object\") return undefined;\n return (doc as Record<string, unknown>)[name];\n}\n","import type { CollectionConfig, Endpoint, ImageSize, PayloadRequest } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { isAdmin } from \"../roles/access\";\nimport { SHARE_IMAGE_SIZE } from \"../seo/share-image\";\nimport { altFromFilename, fillBlankAltFromFilename } from \"./media-alt\";\nimport { MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST } from \"./media-constants\";\nimport { findMediaInUse, type MediaInUsePayload, type MediaInUseScopes } from \"./media-in-use\";\n\nexport { altFromFilename, fillBlankAltFromFilename } from \"./media-alt\";\nexport { MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST } from \"./media-constants\";\n\nexport type MediaInUseOption = MediaInUseScopes | false;\n\nexport interface MediaOptions {\n /** Where uploads land, relative to the app root. */\n staticDir?: string;\n mimeTypes?: string[];\n /**\n * Renditions sharp cuts on upload, each served at its own URL under\n * `sizes.<name>` on the document. Omit to get the share card (1200×630)\n * with list/filter/group hides. A site that passes its own list owns\n * those flags on each size.\n */\n imageSizes?: ImageSize[];\n /**\n * `true` walks every registered collection and global at request time\n * (Payload internals and media itself skipped). A slug list narrows.\n * `false` hides the column and skips the scan.\n */\n inUse?: MediaInUseOption;\n}\n\nconst DEFAULT_RESIZE = {\n width: 2560,\n height: 2560,\n fit: \"inside\" as const,\n withoutEnlargement: true,\n};\n\nfunction defaultShareSizes(): ImageSize[] {\n return [\n {\n ...SHARE_IMAGE_SIZE,\n admin: {\n disableGroupBy: true,\n disableListColumn: true,\n disableListFilter: true,\n },\n },\n ];\n}\n\n/**\n * Client uploads write the original before Sharp resizes `req.file`.\n * Drop the flag so the resized buffer overwrites that object. Disk\n * uploads have no flag; this is a no-op.\n */\nexport function replaceClientOriginalWithResizedFile(req: { file?: object }): void {\n if (req.file && \"clientUploadContext\" in req.file) {\n delete (req.file as { clientUploadContext?: unknown }).clientUploadContext;\n }\n}\n\n/**\n * Uploads, readable by anyone: the public site serves these files. Writing is\n * an editorial action, deleting is not — removing an asset a live page\n * references breaks that page.\n */\nexport function createMedia({\n staticDir = \"media\",\n mimeTypes = [\"image/*\"],\n imageSizes,\n inUse = true,\n}: MediaOptions = {}): CollectionConfig {\n return {\n slug: \"media\",\n admin: {\n hidden: hideUnlessFeature(\"media\") as (args: { user: unknown }) => boolean,\n useAsTitle: \"filename\",\n defaultColumns: [\"filename\", \"alt\", \"updatedAt\", \"createdAt\"],\n listSearchableFields: [\"filename\", \"alt\"],\n pagination: { defaultLimit: 10 },\n custom: { mediaInUse: inUse !== false },\n components: {\n views: {\n list: { Component: MEDIA_LIST },\n },\n },\n },\n access: {\n read: () => true,\n create: canUseFeature(\"media\"),\n update: canUseFeature(\"media\"),\n delete: isAdmin,\n },\n upload: {\n staticDir,\n mimeTypes,\n imageSizes: imageSizes ?? defaultShareSizes(),\n resizeOptions: DEFAULT_RESIZE,\n },\n hooks: {\n beforeValidate: [({ data }) => (data ? fillBlankAltFromFilename(data) : data)],\n beforeChange: [\n ({ data, req }) => {\n replaceClientOriginalWithResizedFile(req);\n return data;\n },\n ],\n },\n endpoints: inUse === false ? [] : [inUseEndpoint(inUse)],\n fields: [\n {\n name: \"alt\",\n type: \"text\",\n required: true,\n admin: {\n components: {\n afterInput: [MEDIA_ALT_AUTOFILL],\n },\n },\n },\n ],\n };\n}\n\nfunction inUseEndpoint(scopes: MediaInUseScopes): Endpoint {\n return {\n path: MEDIA_IN_USE_PATH,\n method: \"get\",\n handler: async (req: PayloadRequest) => {\n if (!req.user) return Response.json({ error: \"Unauthorized\" }, { status: 401 });\n try {\n const ids = [...await findMediaInUse(req.payload as unknown as MediaInUsePayload, scopes)];\n return Response.json({ ids });\n } catch (error) {\n const message = error instanceof Error ? error.message : \"Media in-use scan failed\";\n return Response.json({ error: message }, { status: 503 });\n }\n },\n };\n}\n","import type { Access, CollectionConfig } from \"payload\";\n\nexport interface CreateTaxonomyOptions {\n slug: string;\n labels: { singular: string; plural: string };\n /**\n * Required, no default — same shape as `createBrandAssets`. `update`\n * covers create, delete, and versions.\n */\n access: { read: Access; update: Access };\n /** Default true — terms are managed from the FAQ Library list. */\n hidden?: boolean;\n}\n\nfunction requireAccess(options: CreateTaxonomyOptions): CreateTaxonomyOptions[\"access\"] {\n const read = options.access?.read;\n const update = options.access?.update;\n if (!read || !update) {\n throw new Error(\n \"createTaxonomy requires access.read and access.update. Pass canUseFeature(\\\"questions\\\") as update when Topics are edited from the FAQ Library.\",\n );\n }\n return { read, update };\n}\n\n/**\n * Name-only terms collection. Topics (and later news or blog) share the\n * same documents. Hidden from the left nav by default; add and delete for\n * `manage: true` facets happen on the FAQ Library list.\n */\nexport function createTaxonomy(options: CreateTaxonomyOptions): CollectionConfig {\n const access = requireAccess(options);\n const hidden = options.hidden ?? true;\n\n return {\n slug: options.slug,\n labels: options.labels,\n admin: {\n useAsTitle: \"name\",\n hidden,\n },\n versions: true,\n access: {\n read: access.read,\n create: access.update,\n update: access.update,\n delete: access.update,\n readVersions: access.update,\n },\n fields: [{ name: \"name\", type: \"text\", required: true, label: \"Name\" }],\n };\n}\n","/** Import-map string. A site runs `payload generate:importmap`. */\nexport const QUESTIONS_LIST = \"@bison-lab/payload-core/admin#QuestionsList\";\n","import type { CollectionBeforeChangeHook } from \"payload\";\n\n/**\n * Plain text inside a Lexical document (or a leftover string). Empty\n * when there are no text nodes, or only whitespace — the same rule the\n * kit dialog uses to refuse an empty answer.\n */\nexport function lexicalPlainText(value: unknown): string {\n if (value == null) return \"\";\n if (typeof value === \"string\") return value.replace(/\\s+/g, \" \").trim();\n return collect(value).replace(/\\s+/g, \" \").trim();\n}\n\nconst BLOCK_SIBLING = new Set([\"paragraph\", \"heading\", \"quote\", \"list\", \"listitem\"]);\n\nfunction isBlockSibling(node: unknown): boolean {\n if (!node || typeof node !== \"object\") return false;\n return BLOCK_SIBLING.has(String((node as { type?: unknown }).type));\n}\n\nfunction collect(node: unknown): string {\n if (typeof node === \"string\") return node;\n if (!node || typeof node !== \"object\") return \"\";\n const rec = node as { type?: unknown; text?: unknown; children?: unknown; root?: unknown };\n if (typeof rec.text === \"string\") return rec.text;\n if (rec.type === \"linebreak\") return \" \";\n if (rec.root) return collect(rec.root);\n if (!Array.isArray(rec.children)) return \"\";\n let out = \"\";\n for (const child of rec.children) {\n const piece = collect(child);\n if (!piece) continue;\n if (out && isBlockSibling(child)) out += \" \";\n out += piece;\n }\n return out;\n}\n\n/**\n * Copies `lexicalPlainText(answer)` onto hidden `answerText` so list search\n * queries a varchar, never the jsonb Lexical column.\n */\nexport const syncAnswerText: CollectionBeforeChangeHook = ({ data }) => {\n if (!data || !(\"answer\" in data)) return data;\n return { ...data, answerText: lexicalPlainText(data.answer) };\n};\n","export const QUESTIONS_SLUG = \"questions\";\nexport const QUESTIONS_FEATURE = \"questions\";\n\n/**\n * Theme family for chips on a linked facet. The list fetches this\n * Global and maps each row's label (and key, if present) to `family`\n * so a badge can set `data-look`. Term documents that already store\n * `family` or `look` win.\n */\nexport interface OrganizeByLook {\n /** Global slug whose rows carry a Theme family. */\n global: string;\n /** Array field on that Global. Default `areas`. */\n path?: string;\n /** Label field on each row, matched to the term name. Default `label`. */\n label?: string;\n /** Theme family field. Default `family`. */\n family?: string;\n}\n\nexport interface OrganizeByEntry {\n /** FAQ relationship field name. Must be a valid Payload field name. */\n name: string;\n /** Filters, table heading, and Manage column. */\n label: string;\n /** Terms collection slug. */\n collection: string;\n /**\n * When true, Manage organization can add and delete terms. Default\n * false — linked collections stay read-only here.\n */\n manage?: boolean;\n /** Optional Theme family source for this facet's chips. */\n look?: OrganizeByLook;\n}\n\nexport interface CreateQuestionsOptions {\n /**\n * Optional. Empty is valid: the list is question, answer, published,\n * used-on. Each entry writes one `hasMany` relationship.\n */\n organizeBy?: readonly OrganizeByEntry[];\n /** Default `questions`. */\n slug?: string;\n /** Default FAQ / FAQ Library. */\n labels?: { singular: string; plural: string };\n}\n","import type { CollectionConfig, Field } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { authenticatedOrPublished } from \"../roles/access\";\nimport { QUESTIONS_LIST } from \"./fields\";\nimport { syncAnswerText } from \"./lexical-text\";\nimport {\n QUESTIONS_FEATURE,\n QUESTIONS_SLUG,\n type CreateQuestionsOptions,\n type OrganizeByEntry,\n} from \"./types\";\n\nfunction organizeByFields(entries: readonly OrganizeByEntry[]): Field[] {\n return entries.map((entry) => ({\n name: entry.name,\n type: \"relationship\" as const,\n relationTo: entry.collection,\n hasMany: true,\n label: entry.label,\n }));\n}\n\n/**\n * One document per FAQ, drafts, a kit List that replaces Payload's stock\n * collection list. Answer is the default Lexical editor (`type: \"richText\"`,\n * no custom `editor`) — the same one the pages rich-text block uses\n * (SPI-104). Hidden `answerText` is the varchar search index, written by\n * `syncAnswerText`. Used-on stays 0 until BIS-127 stores block\n * relationships (BIS-125 is the consume mockup). Without those,\n * faqColumns and page consume still do not read these Lexical answers.\n */\nexport function createQuestions(options: CreateQuestionsOptions = {}): CollectionConfig {\n const organizeBy = options.organizeBy ?? [];\n const slug = options.slug ?? QUESTIONS_SLUG;\n const labels = options.labels ?? { singular: \"FAQ\", plural: \"FAQ Library\" };\n const hidden = hideUnlessFeature(QUESTIONS_FEATURE);\n const write = canUseFeature(QUESTIONS_FEATURE);\n\n return {\n slug,\n labels,\n admin: {\n group: \"Content\",\n useAsTitle: \"question\",\n hidden: hidden as (args: { user: unknown }) => boolean,\n listSearchableFields: [\"question\", \"answerText\"],\n custom: { organizeBy },\n components: {\n views: {\n list: {\n Component: {\n path: QUESTIONS_LIST,\n clientProps: { organizeBy },\n },\n },\n },\n },\n },\n access: {\n read: authenticatedOrPublished,\n create: write,\n update: write,\n delete: write,\n readVersions: write,\n },\n versions: {\n drafts: true,\n },\n hooks: {\n beforeChange: [syncAnswerText],\n },\n fields: [\n { name: \"question\", type: \"text\", required: true, label: \"Question\" },\n { name: \"answer\", type: \"richText\", required: true, label: \"Answer\" },\n {\n name: \"answerText\",\n type: \"text\",\n admin: { hidden: true, disableListColumn: true, disableListFilter: true },\n },\n ...organizeByFields(organizeBy),\n ],\n };\n}\n","import { redirectsPlugin } from \"@payloadcms/plugin-redirects\";\nimport type {\n CollectionAfterChangeHook,\n CollectionConfig,\n Payload,\n PayloadRequest,\n Plugin,\n Where,\n} from \"payload\";\n\nimport { ROOT_PAGE_SLUG } from \"../collections/root-page-key\";\nimport { canUseFeature } from \"../features/access\";\nimport { normalizeSlug } from \"../fields/slug\";\nimport { isAdmin } from \"../roles/access\";\n\nexport const REDIRECTS_SLUG = \"redirects\";\n\nexport function redirectPath(slug: string): string {\n if (slug === ROOT_PAGE_SLUG) return \"/\";\n const normalized = normalizeSlug(slug);\n return normalized ? `/${normalized}` : \"\";\n}\n\nexport async function recordPublishedSlugRedirect({\n fromSlug,\n payload,\n req,\n toSlug,\n}: {\n fromSlug: string;\n payload: Payload;\n req?: PayloadRequest;\n toSlug: string;\n}): Promise<void> {\n const from = redirectPath(fromSlug);\n const to = redirectPath(toSlug);\n if (!from || !to || from === to) return;\n\n const found = async (where: Where) =>\n payload.find({\n collection: REDIRECTS_SLUG,\n depth: 0,\n limit: 100,\n overrideAccess: true,\n pagination: false,\n req,\n where,\n });\n\n for (const doc of (await found({ from: { equals: to } })).docs) {\n await payload.delete({ collection: REDIRECTS_SLUG, id: doc.id, overrideAccess: true, req });\n }\n\n for (const doc of (await found({ \"to.url\": { equals: from } })).docs) {\n await payload.update({\n collection: REDIRECTS_SLUG,\n data: { to: { type: \"custom\", url: to } },\n id: doc.id,\n overrideAccess: true,\n req,\n });\n }\n\n const data = { from, to: { type: \"custom\" as const, url: to }, type: \"308\" };\n const existing = (await found({ from: { equals: from } })).docs[0];\n if (existing) {\n await payload.update({\n collection: REDIRECTS_SLUG,\n data,\n id: existing.id,\n overrideAccess: true,\n req,\n });\n return;\n }\n\n await payload.create({ collection: REDIRECTS_SLUG, data, overrideAccess: true, req });\n}\n\nexport const writePublishedSlugRedirect: CollectionAfterChangeHook = async ({\n doc,\n previousDoc,\n req,\n}) => {\n if (doc._status !== \"published\") return doc;\n const fromSlug = typeof previousDoc?.publishedSlug === \"string\" ? previousDoc.publishedSlug : \"\";\n const toSlug = typeof doc.slug === \"string\" ? doc.slug : \"\";\n await recordPublishedSlugRedirect({ fromSlug, payload: req.payload, req, toSlug });\n return doc;\n};\n\nfunction withPublishedSlugRedirect(collection: CollectionConfig): CollectionConfig {\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n afterChange: [...(collection.hooks?.afterChange ?? []), writePublishedSlugRedirect],\n },\n };\n}\n\n/**\n * `@payloadcms/plugin-redirects` scoped to `pages`, 308 only. A published\n * slug change writes the redirect and collapses chains. The plugin stores\n * rows; the site still has to serve them.\n */\nexport function createRedirects(): Plugin {\n const plugin = redirectsPlugin({\n collections: [\"pages\"],\n redirectTypeFieldOverride: {\n admin: { hidden: true },\n defaultValue: \"308\",\n },\n redirectTypes: [\"308\"],\n overrides: {\n access: {\n create: canUseFeature(\"content\"),\n delete: isAdmin,\n update: canUseFeature(\"content\"),\n },\n admin: { group: \"Content\" },\n },\n });\n\n return (config) => {\n const next = plugin(config);\n return {\n ...next,\n collections: next.collections?.map((collection) =>\n collection.slug === \"pages\" ? withPublishedSlugRedirect(collection) : collection,\n ),\n };\n };\n}\n","export const ADMIN_NAV = \"@bison-lab/payload-core/admin#AdminNav\";\nexport const ADMIN_NAV_ROW_LABEL = \"@bison-lab/payload-core/admin#AdminNavRowLabel\";\nexport const ADMIN_NAV_ITEM_ROW_LABEL = \"@bison-lab/payload-core/admin#AdminNavItemRowLabel\";\nexport const ADMIN_NAV_ENTITY_FIELD = \"@bison-lab/payload-core/admin#AdminNavEntityField\";\n","/**\n * Developer-owned admin sidebar. SPI-10 skins this with AppSidebarBlock;\n * this package ships the document and the default Nav. A consuming site\n * waits for SPI-97 after this and BIS-110 publish.\n */\n\nexport const ADMIN_NAV_SLUG = \"admin-nav\";\n\nexport type AdminNavEntityType = \"collection\" | \"global\";\n\nexport interface AdminNavItem {\n type: AdminNavEntityType;\n slug: string;\n label: string;\n}\n\nexport interface AdminNavGroup {\n label: string;\n items: AdminNavItem[];\n}\n\nexport interface AdminNavDoc {\n groups?: Array<{\n id?: string | null;\n label?: string | null;\n items?: Array<{\n id?: string | null;\n type?: string | null;\n slug?: string | null;\n }> | null;\n }> | null;\n}\n\nexport interface AdminNavVisibleEntities {\n collections?: readonly string[];\n globals?: readonly string[];\n}\n\nexport interface AdminNavEntityConfig {\n slug: string;\n admin?: { group?: unknown };\n label?: unknown;\n labels?: { plural?: unknown; singular?: unknown };\n}\n\nexport interface AdminNavConfig {\n collections?: readonly AdminNavEntityConfig[];\n globals?: readonly AdminNavEntityConfig[];\n}\n\nexport interface ResolveAdminNavArgs {\n config: AdminNavConfig;\n doc?: AdminNavDoc | null;\n visibleEntities?: AdminNavVisibleEntities;\n}\n","import type { TextFieldSingleValidation } from \"payload\";\n\nconst UNKNOWN_ENTITY_MESSAGE = \"Not in this site's config.\";\n\n/**\n * A Developer cannot invent a collection or global that is not registered.\n */\nexport const validateAdminNavSlug: TextFieldSingleValidation = (value, { req, siblingData }) => {\n if (typeof value !== \"string\" || value === \"\") return true;\n const type = siblingData && typeof siblingData === \"object\" && \"type\" in siblingData ? siblingData.type : null;\n const list =\n type === \"global\" ? req.payload?.config?.globals : type === \"collection\" ? req.payload?.config?.collections : [];\n const slugs = (list ?? []).map((entity) => entity.slug);\n return slugs.includes(value) || UNKNOWN_ENTITY_MESSAGE;\n};\n","import type { ArrayField, GlobalConfig } from \"payload\";\n\nimport { hideUnlessDeveloper, isAuthenticated, isDeveloper, type MaybeUser } from \"../roles/access\";\nimport { ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL } from \"./fields\";\nimport { ADMIN_NAV_SLUG } from \"./types\";\nimport { validateAdminNavSlug } from \"./validate\";\n\nconst groupsField: ArrayField = {\n name: \"groups\",\n type: \"array\",\n label: \"Groups\",\n labels: { singular: \"Group\", plural: \"Groups\" },\n admin: {\n components: { RowLabel: ADMIN_NAV_ROW_LABEL },\n description: \"Sidebar headers and the collections or globals under each. Drag to reorder. An empty header still shows.\",\n initCollapsed: false,\n },\n fields: [\n {\n name: \"label\",\n type: \"text\",\n label: \"Header\",\n },\n {\n name: \"items\",\n type: \"array\",\n label: \"Items\",\n labels: { singular: \"Item\", plural: \"Items\" },\n admin: { components: { RowLabel: ADMIN_NAV_ITEM_ROW_LABEL } },\n fields: [\n {\n type: \"row\",\n fields: [\n {\n name: \"type\",\n type: \"select\",\n label: \"Type\",\n required: true,\n defaultValue: \"collection\",\n options: [\n { label: \"Collection\", value: \"collection\" },\n { label: \"Global\", value: \"global\" },\n ],\n admin: { width: \"40%\" },\n },\n {\n name: \"slug\",\n type: \"text\",\n label: \"Slug\",\n required: true,\n validate: validateAdminNavSlug,\n admin: { width: \"60%\", components: { Field: ADMIN_NAV_ENTITY_FIELD } },\n },\n ],\n },\n ],\n },\n ],\n};\n\n/**\n * Settings → Admin nav. Developer chrome, not a Features row. Save writes\n * immediately. The package Nav reads this document. An empty row falls\n * back to Payload's first-seen walk; a saved row is the sidebar.\n */\nexport function createAdminNav(): GlobalConfig {\n return {\n slug: ADMIN_NAV_SLUG,\n label: \"Admin nav\",\n admin: {\n group: \"Settings\",\n hidden: hideUnlessDeveloper,\n description:\n \"Sidebar group headers and order. An empty document falls back to Payload's first-seen walk. Once you save, only the groups and items you listed appear — omitted collections and globals stay off the sidebar.\",\n },\n access: {\n read: isAuthenticated,\n update: ({ req }) => isDeveloper(req.user as MaybeUser),\n },\n fields: [groupsField],\n };\n}\n","import type { Config } from \"payload\";\nimport { definePlugin } from \"payload\";\n\nimport { ADMIN_NAV } from \"./fields\";\n\n/**\n * Sets `admin.components.Nav` to the package Nav. A consuming site must\n * not write its own Nav — SPI-10 is the later skin, and it reads\n * `resolveAdminNav` rather than a second layout source.\n */\nexport const adminNav = definePlugin({\n slug: \"admin-nav\",\n order: 1000,\n plugin: ({ config }): Config => ({\n ...config,\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n Nav: ADMIN_NAV,\n },\n },\n }),\n});\n","import type {\n AdminNavConfig,\n AdminNavDoc,\n AdminNavEntityConfig,\n AdminNavEntityType,\n AdminNavGroup,\n AdminNavItem,\n ResolveAdminNavArgs,\n} from \"./types\";\n\nfunction sidebarGroup(group: unknown): string | false {\n if (group === false) return false;\n if (typeof group === \"string\") return group;\n return \"\";\n}\n\nfunction asLabel(value: unknown, fallback: string): string {\n return typeof value === \"string\" && value ? value : fallback;\n}\n\nfunction entityLabel(entity: AdminNavEntityConfig, type: AdminNavEntityType): string {\n if (type === \"collection\") {\n return asLabel(entity.labels?.plural, asLabel(entity.labels?.singular, entity.slug));\n }\n return asLabel(entity.label, entity.slug);\n}\n\nfunction keyOf(type: AdminNavEntityType, slug: string): string {\n return `${type}:${slug}`;\n}\n\ninterface CatalogEntry {\n type: AdminNavEntityType;\n slug: string;\n label: string;\n group: string | false;\n}\n\nfunction catalog(config: AdminNavConfig): CatalogEntry[] {\n const collections = (config.collections ?? []).map((entity) => ({\n type: \"collection\" as const,\n slug: entity.slug,\n label: entityLabel(entity, \"collection\"),\n group: sidebarGroup(entity.admin?.group),\n }));\n const globals = (config.globals ?? []).map((entity) => ({\n type: \"global\" as const,\n slug: entity.slug,\n label: entityLabel(entity, \"global\"),\n group: sidebarGroup(entity.admin?.group),\n }));\n return [...collections, ...globals];\n}\n\nfunction defaultGroups(entities: readonly CatalogEntry[]): AdminNavGroup[] {\n const groups: AdminNavGroup[] = [];\n for (const entity of entities) {\n if (entity.group === false) continue;\n let group = groups.find((entry) => entry.label === entity.group);\n if (!group) {\n group = { label: entity.group, items: [] };\n groups.push(group);\n }\n group.items.push({ type: entity.type, slug: entity.slug, label: entity.label });\n }\n return groups;\n}\n\nfunction itemFromSaved(\n item: { type?: string | null; slug?: string | null },\n byKey: Map<string, CatalogEntry>,\n): AdminNavItem | null {\n const type = item.type === \"global\" || item.type === \"collection\" ? item.type : null;\n const slug = typeof item.slug === \"string\" ? item.slug : \"\";\n if (!type || !slug) return null;\n const entity = byKey.get(keyOf(type, slug));\n if (!entity || entity.group === false) return null;\n return { type, slug, label: entity.label };\n}\n\nfunction fromDocument(doc: AdminNavDoc, entities: readonly CatalogEntry[]): AdminNavGroup[] {\n const byKey = new Map(entities.map((entity) => [keyOf(entity.type, entity.slug), entity]));\n return (doc.groups ?? []).map((row) => ({\n label: typeof row.label === \"string\" ? row.label : \"\",\n items: (row.items ?? []).flatMap((item) => {\n const resolved = itemFromSaved(item ?? {}, byKey);\n return resolved ? [resolved] : [];\n }),\n }));\n}\n\n/**\n * Layout for the package Nav (and later SPI-10). Permissions are\n * `visibleEntities` — this function does not re-derive access.\n */\nexport function resolveAdminNav({ config, doc, visibleEntities }: ResolveAdminNavArgs): AdminNavGroup[] {\n const entities = catalog(config);\n const saved = Array.isArray(doc?.groups) ? doc.groups : [];\n let groups = saved.length === 0 ? defaultGroups(entities) : fromDocument({ groups: saved }, entities);\n\n if (visibleEntities) {\n const collections = new Set(visibleEntities.collections ?? []);\n const globals = new Set(visibleEntities.globals ?? []);\n groups = groups.map((group) => ({\n ...group,\n items: group.items.filter((item) =>\n item.type === \"collection\" ? collections.has(item.slug) : globals.has(item.slug),\n ),\n }));\n }\n\n return groups;\n}\n","import { Forbidden, type GlobalBeforeChangeHook, type GlobalConfig } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { canPublish, isAuthenticated } from \"../roles/access\";\nimport { FOOTER_COLUMNS_FIELD, footerFields } from \"./footer\";\nimport { linkField } from \"./link\";\nimport {\n NAVIGATION_DB_NAME,\n NAVIGATION_FEATURE,\n NAVIGATION_FOOTER_DB_NAME,\n NAVIGATION_FOOTER_SLUG,\n NAVIGATION_SLUG,\n type CreateNavigationOptions,\n} from \"./types\";\n\nconst refusePublishWithoutTick: GlobalBeforeChangeHook = async ({ data, req }) => {\n if (data._status !== \"published\") return data;\n if (!req.user) return data;\n if (await Promise.resolve(canPublish({ req } as never))) return data;\n throw new Forbidden();\n};\n\n/**\n * Header (`navigation` / `nav`) and Footer (`navigation-footer` / `navf`).\n * One Features tick (`navigation`). Independent Save / Publish / drafts —\n * a draft header does not publish the footer.\n *\n * Header opts into the admin workspace (`AdminWorkspace`). Bar stays in the\n * schema and is hidden; SPI-99 consumes `headerFromNavigation`. Payload's\n * left nav stays until BIS-90.\n */\nexport function createNavigation({\n blocks,\n preview,\n livePreview,\n previewButton,\n pagesCollection,\n footerCopyrightName,\n}: CreateNavigationOptions): [GlobalConfig, GlobalConfig] {\n if (blocks.length === 0) {\n throw new Error(\"createNavigation needs at least one header block\");\n }\n\n const hidden = hideUnlessFeature(NAVIGATION_FEATURE);\n const update = canUseFeature(NAVIGATION_FEATURE);\n const previewAdmin = {\n ...(preview ? { preview } : {}),\n ...(livePreview ? { livePreview } : {}),\n };\n\n const header: GlobalConfig = {\n slug: NAVIGATION_SLUG,\n dbName: NAVIGATION_DB_NAME,\n label: \"Header\",\n admin: {\n group: \"Navigation\",\n hidden: hidden as (args: { user: unknown }) => boolean,\n description: \"The public header. A draft never reaches the live site until you publish.\",\n ...previewAdmin,\n components: {\n ...(previewButton ? { elements: { PreviewButton: previewButton } } : {}),\n views: {\n edit: {\n default: {\n Component: \"@bison-lab/payload-blocks/admin#AdminWorkspace\",\n },\n },\n },\n },\n },\n access: {\n read: () => true,\n readVersions: isAuthenticated,\n update,\n },\n versions: {\n drafts: { autosave: { interval: 375 } },\n },\n hooks: {\n beforeChange: [refusePublishWithoutTick],\n },\n fields: [\n {\n name: \"header\",\n type: \"group\",\n label: false,\n admin: { hideGutter: true },\n fields: [\n {\n name: \"items\",\n type: \"blocks\",\n labels: { singular: \"Item\", plural: \"Items\" },\n blocks,\n admin: {\n components: {\n Field: \"@bison-lab/payload-blocks/admin#NavItemsField\",\n },\n },\n },\n linkField({\n name: \"cta\",\n label: \"Header button\",\n toggle: true,\n pagesCollection,\n admin: {\n hidden: true,\n },\n }),\n ],\n },\n {\n name: \"bar\",\n type: \"group\",\n label: false,\n admin: {\n hidden: true,\n },\n fields: [\n {\n name: \"hideOnScroll\",\n type: \"checkbox\",\n label: \"Hide on scroll\",\n defaultValue: true,\n admin: {\n description: \"Slide the bar away as the page scrolls down.\",\n },\n },\n {\n name: \"viewport\",\n type: \"checkbox\",\n label: \"Shared viewport\",\n defaultValue: false,\n admin: {\n description:\n \"Centre one animated panel under the bar. Off (the default) anchors each mega menu under its own trigger.\",\n },\n },\n {\n name: \"defaultMaxWidth\",\n type: \"select\",\n label: \"Default panel width\",\n defaultValue: \"standard\",\n options: [\n { label: \"Narrow\", value: \"narrow\" },\n { label: \"Standard\", value: \"standard\" },\n { label: \"Wide\", value: \"wide\" },\n ],\n admin: {\n description:\n \"Used when a mega menu does not set its own width. Per-panel widths still win.\",\n },\n },\n ],\n },\n ],\n };\n\n const footer: GlobalConfig = {\n slug: NAVIGATION_FOOTER_SLUG,\n dbName: NAVIGATION_FOOTER_DB_NAME,\n label: \"Footer\",\n admin: {\n group: \"Navigation\",\n hidden: hidden as (args: { user: unknown }) => boolean,\n description:\n \"The public footer. Columns, brand copy, and socials. A draft never reaches the live site until you publish.\",\n ...previewAdmin,\n custom: footerCopyrightName ? { footerCopyrightName } : undefined,\n components: {\n ...(previewButton ? { elements: { PreviewButton: previewButton } } : {}),\n views: {\n edit: {\n default: {\n Component: \"@bison-lab/payload-blocks/admin#AdminWorkspace\",\n },\n },\n },\n },\n },\n access: {\n read: () => true,\n readVersions: isAuthenticated,\n update,\n },\n versions: {\n drafts: { autosave: { interval: 375 } },\n },\n hooks: {\n beforeChange: [refusePublishWithoutTick],\n },\n fields: [\n {\n name: \"footer\",\n type: \"group\",\n label: false,\n admin: {\n hideGutter: true,\n components: {\n Field: FOOTER_COLUMNS_FIELD,\n },\n },\n fields: footerFields({ pagesCollection }),\n },\n ],\n };\n\n return [header, footer];\n}\n","import type { CollectionConfig, GlobalConfig } from \"payload\";\nimport { definePlugin } from \"payload\";\n\nimport { isDeveloperTab } from \"../roles/access\";\n\ntype Entity = CollectionConfig | GlobalConfig;\n\nfunction gateApiTab<T extends Entity>(entity: T): T {\n const components = entity.admin?.components;\n const edit = components?.views?.edit;\n const api = edit && \"api\" in edit ? edit.api : undefined;\n return {\n ...entity,\n admin: {\n ...entity.admin,\n components: {\n ...components,\n views: {\n ...components?.views,\n edit: {\n ...edit,\n api: { ...api, tab: { ...api?.tab, condition: isDeveloperTab } },\n },\n },\n },\n },\n };\n}\n\n/**\n * Gates the document API tab to Developer, config-wide. After plugins that\n * use `definePlugin` order (MCP is 10), so a collection those plugins\n * register is still covered.\n */\nexport const adminOnlyApiTab = definePlugin({\n slug: \"admin-only-api-tab\",\n order: 1000,\n plugin: ({ config }) => ({\n ...config,\n collections: config.collections?.map(gateApiTab),\n globals: config.globals?.map(gateApiTab),\n }),\n});\n","import type { Config } from \"payload\";\nimport { definePlugin } from \"payload\";\n\nimport { DOCUMENT_TITLE_ACTIONS } from \"../admin/document-controls\";\n\ntype AdminProviders = NonNullable<\n NonNullable<NonNullable<Config[\"admin\"]>[\"components\"]>[\"providers\"]\n>;\n\nfunction asList(value: AdminProviders | undefined): AdminProviders {\n if (!value) return [];\n return value;\n}\n\nfunction alreadyHasTitleActions(providers: AdminProviders): boolean {\n return providers.some((entry) => {\n if (typeof entry === \"string\") return entry === DOCUMENT_TITLE_ACTIONS;\n if (entry && typeof entry === \"object\" && \"path\" in entry) {\n return entry.path === DOCUMENT_TITLE_ACTIONS;\n }\n return false;\n });\n}\n\nfunction withTitleActions(config: Config): Config {\n const providers = asList(config.admin?.components?.providers);\n if (alreadyHasTitleActions(providers)) return config;\n return {\n ...config,\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n providers: [DOCUMENT_TITLE_ACTIONS, ...providers],\n },\n },\n };\n}\n\n/**\n * Puts every document's primary actions on the title row — the same\n * slot collection lists use for Create New — and hides the dead Edit\n * tab when it has no sibling. One admin provider so Roles, Theme,\n * Features, Account, and a site's own Globals cannot drift.\n */\nexport const documentTitleActions = definePlugin({\n slug: \"document-title-actions\",\n order: 1000,\n plugin: ({ config }) => withTitleActions(config),\n});\n"],"mappings":";;;;;;;;;;;;;;;AAOA,MAAa,eAA8B;CACzC,MAAM;CACN,MAAM;CACN,OAAO;CACP,cAAc;CACd,OAAO,EACL,aACE,qHACH;CACF;;;;ACfD,MAAa,qBAAqB;;;;;;;AAQlC,SAAgB,eAAe,MAAc,MAAA,KAAkC;CAC7E,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,QAAQ,UAAU,IAAK,QAAO;CAClC,MAAM,MAAM,QAAQ,MAAM,GAAG,IAAI;CACjC,MAAM,YAAY,IAAI,YAAY,IAAI;AACtC,QAAO,GAAG,YAAY,IAAI,IAAI,MAAM,GAAG,UAAU,GAAG,IAAI;;;;;;;;;;;;;;;;ACmD1D,SAAgB,UAAwC,EACtD,UACA,QACA,cACA,UACA,cAAc,CAAC,QAAQ,EACvB,oBAAoB,WACa;CACjC,MAAM,iBAAsC,EAAE,UA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ChD,MAAI,SAAS,OAAO,UAAU,YAAY,UAAU,MAClD,QAAO,MAAM,SAAS;AAExB,SAAO;GACP;;AAGJ,SAAS,iBAAiB,QAAwB;CAChD,MAAM,YAAY,OAAO,OAAO,OAAO,YAAY,UAAU;AAC7D,KAAI,uBAAuB,UAAU,CAAE,QAAO;AAC9C,QAAO;EACL,GAAG;EACH,OAAO;GACL,GAAG,OAAO;GACV,YAAY;IACV,GAAG,OAAO,OAAO;IACjB,WAAW,CAAC,wBAAwB,GAAG,UAAU;IAClD;GACF;EACF;;;;;;;;AASH,MAAa,uBAAuB,aAAa;CAC/C,MAAM;CACN,OAAO;CACP,SAAS,EAAE,aAAa,iBAAiB,OAAO;CACjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["payloadSeoPlugin","resolveScopes","eachCollectionDoc","readGlobal","slugsOf","isAccessArgs","resolveAccess","slugsOf","readGlobal","catalog"],"sources":["../src/seo/fields.ts","../src/seo/text.ts","../src/seo/plugin.ts","../src/theme/appearance-labels.ts","../src/theme/color-usages.ts","../src/theme/color-usage-endpoints.ts","../src/features/types.ts","../src/roles/types.ts","../src/features/matrix.ts","../src/roles/matrix.ts","../src/roles/access.ts","../src/features/access.ts","../src/theme/global.ts","../src/brand-assets/sanitize.ts","../src/brand-assets/collection.ts","../src/theme/seed.ts","../src/theme/publish.ts","../src/admin/document-controls.ts","../src/roles/fields.ts","../src/roles/global.ts","../src/roles/seed.ts","../src/block-library/types.ts","../src/block-library/catalogue.ts","../src/block-library/fields.ts","../src/block-library/holders.ts","../src/block-library/global.ts","../src/features/fields.ts","../src/features/global.ts","../src/features/seed.ts","../src/collections/root-page-key.ts","../src/fields/slug.ts","../src/collections/root-page.ts","../src/collections/pages.ts","../src/collections/users.ts","../src/collections/media-alt.ts","../src/collections/media-constants.ts","../src/collections/media-in-use.ts","../src/collections/media.ts","../src/taxonomy/collection.ts","../src/questions/fields.ts","../src/questions/lexical-text.ts","../src/questions/types.ts","../src/questions/collection.ts","../src/plugins/redirects.ts","../src/admin-nav/fields.ts","../src/admin-nav/types.ts","../src/admin-nav/validate.ts","../src/admin-nav/global.ts","../src/admin-nav/plugin.ts","../src/admin-nav/resolve.ts","../src/navigation/global.ts","../src/plugins/admin-only-api-tab.ts","../src/plugins/document-title-actions.ts","../src/admin/list-align-key.ts","../src/plugins/list-align.ts"],"sourcesContent":["import type { CheckboxField } from \"payload\";\n\n/**\n * The index switch, last in the SEO tab. Off by default: a page is public\n * unless an editor says otherwise. `pageMetadata` turns it into\n * `noindex, nofollow`; a site's sitemap should filter on it too.\n */\nexport const noIndexField: CheckboxField = {\n name: \"noIndex\",\n type: \"checkbox\",\n label: \"Hide this page from search engines\",\n defaultValue: false,\n admin: {\n description:\n \"Search engines will not list this page and the sitemap will leave it out. Anyone with the link can still open it.\",\n },\n};\n","/** The length a search result shows of a description before it is cut. */\nexport const DESCRIPTION_LENGTH = 155;\n\n/**\n * Prose cut to `max` characters at a word, with an ellipsis, so a generated\n * description does not end mid-syllable. Text that fits is returned trimmed\n * and whole. A first word longer than `max` is cut mid-word, since there is\n * no boundary to cut at.\n */\nexport function truncateAtWord(text: string, max = DESCRIPTION_LENGTH): string {\n const trimmed = text.trim();\n if (trimmed.length <= max) return trimmed;\n const cut = trimmed.slice(0, max);\n const lastSpace = cut.lastIndexOf(\" \");\n return `${lastSpace > 0 ? cut.slice(0, lastSpace) : cut}…`;\n}\n","import { seoPlugin as payloadSeoPlugin } from \"@payloadcms/plugin-seo\";\nimport type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n} from \"@payloadcms/plugin-seo/types\";\nimport type { CollectionSlug, Plugin, UploadCollectionSlug } from \"payload\";\n\nimport { noIndexField } from \"./fields\";\nimport { truncateAtWord } from \"./text\";\nimport { documentTitle } from \"./title\";\nimport type { MediaId } from \"./types\";\n\n/**\n * What the plugin reads off a document: its title, for the generated meta\n * title. The site's generated `Page` is assignable to this; the `urlFor`,\n * `describeFrom` and `imageFor` callbacks read the rest, typed as the site\n * chooses through `TDoc`.\n */\nexport interface SeoDoc {\n title?: string | null;\n}\n\nexport interface SeoPluginOptions<TDoc extends SeoDoc = SeoDoc> {\n /** Appended to every generated title: `<page title> | <siteName>`. */\n siteName: string;\n /**\n * The absolute public URL of a document from the form's data, for the\n * search-result preview and the Generate button beside it. `undefined`\n * when the document has no address yet (a slug not typed), which leaves\n * the preview empty rather than pointing at the home page.\n */\n urlFor: (doc: TDoc) => string | undefined;\n /**\n * Prose to cut a generated description from, the first plain-text field a\n * page always has near the top (a hero's body, say). Cut at a word near\n * 155 characters. Without it the Generate button fills in nothing.\n */\n describeFrom?: (doc: TDoc) => string | null | undefined;\n /**\n * An image already on the page, for the Meta Image Generate button, so an\n * editor need not upload a second copy of the hero picture. `firstImageIn`\n * walks block rows for one. The upload chooser stays, so any other media\n * row can still be picked.\n */\n imageFor?: (doc: TDoc) => MediaId | null | undefined;\n /** Collections that get the SEO tab. Default `['pages']`. */\n collections?: CollectionSlug[];\n /** The upload collection the meta image comes from. Default `'media'`. */\n uploadsCollection?: UploadCollectionSlug;\n}\n\n/**\n * `@payloadcms/plugin-seo` configured the Bison Lab way: an SEO tab beside a\n * Content tab (never below the block editor), holding the overview with its\n * character counts, meta title, description and image with Generate buttons,\n * the search-result preview, and the `noIndex` switch.\n *\n * Every string the tab generates comes from the options, so a site spells\n * its name and its URL scheme once. Pin `@payloadcms/plugin-seo` to the same\n * version as `payload` in the site; the plugin's admin components are\n * resolved from the site's import map, so run `payload generate:importmap`\n * after adding it.\n */\nexport function seoPlugin<TDoc extends SeoDoc = SeoDoc>({\n siteName,\n urlFor,\n describeFrom,\n imageFor,\n collections = [\"pages\"],\n uploadsCollection = \"media\",\n}: SeoPluginOptions<TDoc>): Plugin {\n const generateTitle: GenerateTitle<TDoc> = ({ doc }) =>\n doc?.title ? documentTitle(siteName, doc.title) : \"\";\n const generateDescription: GenerateDescription<TDoc> = ({ doc }) =>\n truncateAtWord(describeFrom?.(doc) ?? \"\");\n const generateURL: GenerateURL<TDoc> = ({ doc }) => urlFor(doc) ?? \"\";\n // Only when the site can name one: the button appears with the function.\n const generateImage: GenerateImage<TDoc> | undefined = imageFor\n ? ({ doc }) => imageFor(doc) ?? \"\"\n : undefined;\n\n return payloadSeoPlugin({\n collections,\n uploadsCollection,\n tabbedUI: true,\n generateTitle,\n generateDescription,\n generateURL,\n ...(generateImage ? { generateImage } : {}),\n fields: ({ defaultFields }) => [...defaultFields, noIndexField],\n });\n}\n\n/**\n * The first image among some block rows, as a media id, for `imageFor`. Each\n * row is checked for `field` holding either a bare id or a populated upload\n * document; rows without one are skipped. Pass the page's hero and layout\n * together (`[...doc.hero, ...doc.layout]`) to search in reading order.\n */\nexport function firstImageIn(\n blocks: unknown,\n field = \"image\",\n): MediaId | undefined {\n if (!Array.isArray(blocks)) return undefined;\n for (const block of blocks) {\n if (typeof block !== \"object\" || block === null) continue;\n const value = (block as Record<string, unknown>)[field];\n const id =\n typeof value === \"object\" && value !== null && \"id\" in value\n ? (value as { id: unknown }).id\n : value;\n if (typeof id === \"number\" || (typeof id === \"string\" && id !== \"\"))\n return id;\n }\n return undefined;\n}\n","/**\n * Named choices the Appearance child shows. Values stay the token presets;\n * labels match the mock workflow (Soft → pill, Gentle → minimal, Balanced\n * → default, Follow device → system). No rem, ms, or CSS variable tables.\n */\nexport const APPEARANCE_CHOICES = {\n defaultTheme: {\n light: { label: \"Light\", hint: \"Always opens in light mode\" },\n dark: { label: \"Dark\", hint: \"Always opens in dark mode\" },\n system: { label: \"Follow device\", hint: \"Matches the visitor’s system setting\" },\n },\n radius: {\n sharp: { label: \"Sharp\", hint: \"Crisp and structured\" },\n subtle: { label: \"Subtle\", hint: \"Clean with a little softness\" },\n rounded: { label: \"Rounded\", hint: \"Friendly and contemporary\" },\n pill: { label: \"Soft\", hint: \"Very rounded and expressive\" },\n },\n shadow: {\n flat: { label: \"Flat\", hint: \"Minimal visual depth\" },\n subtle: { label: \"Subtle\", hint: \"Light separation between surfaces\" },\n elevated: { label: \"Elevated\", hint: \"More noticeable layering and depth\" },\n },\n motion: {\n snappy: { label: \"Quick\", hint: \"Fast and responsive\" },\n smooth: { label: \"Smooth\", hint: \"Balanced and natural\" },\n minimal: { label: \"Gentle\", hint: \"Slower and more relaxed\" },\n },\n density: {\n compact: { label: \"Compact\", hint: \"Fits more content on screen\" },\n default: { label: \"Balanced\", hint: \"Comfortable for most sites\" },\n spacious: { label: \"Spacious\", hint: \"More breathing room and larger controls\" },\n },\n} as const;\n\nexport const APPEARANCE_FAMILY_COPY: Record<\n keyof typeof APPEARANCE_CHOICES,\n { title: string; hint: string }\n> = {\n defaultTheme: {\n title: \"Default theme\",\n hint: \"Choose how the public site opens for visitors.\",\n },\n radius: {\n title: \"Corner style\",\n hint: \"Controls the shape of buttons, inputs, cards, and panels across the site.\",\n },\n shadow: {\n title: \"Depth\",\n hint: \"Choose how much cards and floating elements stand out from the page.\",\n },\n motion: {\n title: \"Motion\",\n hint: \"Controls how quickly menus, cards, and interface transitions move.\",\n },\n density: {\n title: \"Spacing\",\n hint: \"Choose how compact or roomy forms, buttons, cards, and page sections feel.\",\n },\n};\n\nexport const FONT_ROLE_COPY = {\n heading: {\n label: \"Heading font\",\n hint: \"Used for page titles, section headings, and cards\",\n },\n body: {\n label: \"Body font\",\n hint: \"Used for paragraphs, navigation, forms, and buttons\",\n },\n} as const;\n\nexport const SYSTEM_COLOR_COPY: Record<\n \"primary\" | \"secondary\" | \"accent\" | \"highlight\" | \"success\" | \"destructive\",\n { label: string; hint: string; group: \"brand\" | \"status\" }\n> = {\n primary: { label: \"Primary\", hint: \"Primary actions and key links\", group: \"brand\" },\n secondary: { label: \"Secondary\", hint: \"Supporting accents and eyebrows\", group: \"brand\" },\n accent: { label: \"Accent\", hint: \"Dark brand surfaces\", group: \"brand\" },\n highlight: { label: \"Highlight\", hint: \"Promotional and emphasis fills\", group: \"brand\" },\n success: {\n label: \"Success\",\n hint: \"Success messages and confirmations\",\n group: \"status\",\n },\n destructive: {\n label: \"Destructive\",\n hint: \"Errors, dangerous actions, and destructive confirmations\",\n group: \"status\",\n },\n};\n","import { findColorTokens, rewriteColorTokens } from \"./color-tokens\";\nimport { pageEditorLooks } from \"./looks\";\nimport { THEME_SLUG, type ThemeDoc } from \"./types\";\n\n/** Theme-store REST path. LibraryField calls `/api/globals/theme` + this. */\nexport const COLOR_USAGES_PATH = \"/color-usages\";\n\nexport interface ColorUsagesList {\n collections?: string[];\n globals?: string[];\n}\n\n/**\n * `true` scans every registered collection and global at request time\n * (Payload internals and Theme itself are skipped). A list still names\n * slugs. Omit or pass empty: every additional color is unused.\n */\nexport type ColorUsagesOption = true | ColorUsagesList;\n\nexport interface ColorUsage {\n collection?: string;\n global?: string;\n id?: string | number;\n path: string;\n token: string;\n}\n\ntype FindResult = { docs: Record<string, unknown>[]; totalPages?: number; page?: number };\n\ntype Slugged = { slug?: string };\n\nexport interface ColorUsagePayload {\n find: (args: {\n collection: string;\n draft?: boolean;\n depth?: number;\n limit?: number;\n page?: number;\n overrideAccess?: boolean;\n }) => Promise<FindResult>;\n findGlobal: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n }) => Promise<Record<string, unknown> | ThemeDoc | null | undefined>;\n update: (args: {\n collection: string;\n id: string | number;\n data: Record<string, unknown>;\n draft?: boolean;\n overrideAccess?: boolean;\n }) => Promise<unknown>;\n updateGlobal: (args: {\n slug: string;\n data: Record<string, unknown>;\n draft?: boolean;\n overrideAccess?: boolean;\n }) => Promise<unknown>;\n collections?: Record<string, unknown>;\n globals?: { config?: Slugged[] };\n config?: {\n collections?: Slugged[];\n globals?: Slugged[];\n };\n}\n\n/**\n * Walk every current document in the resolved collections and globals\n * (drafts included). A color only on an unpublished page is still in use.\n */\nexport async function findColorUsages(\n payload: ColorUsagePayload,\n scopes: ColorUsagesOption | undefined,\n key: string,\n): Promise<ColorUsage[]> {\n const { collections, globals } = resolveScopes(payload, scopes);\n const usages: ColorUsage[] = [];\n for (const collection of collections) {\n for await (const doc of eachCollectionDoc(payload, collection)) {\n for (const hit of findColorTokens(doc, key)) {\n usages.push({ collection, id: idOf(doc), path: hit.path, token: hit.token });\n }\n }\n }\n for (const slug of globals) {\n const doc = await readGlobal(payload, slug);\n if (!doc) continue;\n for (const hit of findColorTokens(doc, key)) {\n usages.push({ global: slug, path: hit.path, token: hit.token });\n }\n }\n return usages;\n}\n\nexport async function rewriteColorUsages(\n payload: ColorUsagePayload,\n scopes: ColorUsagesOption | undefined,\n fromKey: string,\n toKey: string,\n): Promise<void> {\n const { collections, globals } = resolveScopes(payload, scopes);\n for (const collection of collections) {\n for await (const doc of eachCollectionDoc(payload, collection)) {\n if (findColorTokens(doc, fromKey).length === 0) continue;\n const { id: _id, ...data } = rewriteColorTokens(doc, fromKey, toKey);\n const id = idOf(doc);\n if (id == null) continue;\n await payload.update({\n collection,\n id,\n data,\n draft: true,\n overrideAccess: true,\n });\n }\n }\n for (const slug of globals) {\n const doc = await readGlobal(payload, slug);\n if (!doc || findColorTokens(doc, fromKey).length === 0) continue;\n await payload.updateGlobal({\n slug,\n data: rewriteColorTokens(doc, fromKey, toKey) as Record<string, unknown>,\n draft: true,\n overrideAccess: true,\n });\n }\n}\n\nexport async function replacementKeys(payload: ColorUsagePayload, except: string): Promise<string[]> {\n const doc = (await payload.findGlobal({\n slug: THEME_SLUG,\n depth: 0,\n overrideAccess: true,\n })) as ThemeDoc | null;\n return pageEditorLooks(doc)\n .map((look) => look.value)\n .filter((key) => key !== except);\n}\n\nexport function resolveScopes(\n payload: ColorUsagePayload,\n scopes: ColorUsagesOption | undefined,\n): ColorUsagesList & { collections: string[]; globals: string[] } {\n if (scopes === true) return registeredScopes(payload);\n return {\n collections: scopes?.collections ?? [],\n globals: scopes?.globals ?? [],\n };\n}\n\nfunction registeredScopes(payload: ColorUsagePayload): { collections: string[]; globals: string[] } {\n return {\n collections: slugsOf(payload.config?.collections ?? payload.collections).filter(\n (slug) => !slug.startsWith(\"payload-\"),\n ),\n globals: slugsOf(payload.config?.globals ?? payload.globals?.config).filter(\n (slug) => slug !== THEME_SLUG,\n ),\n };\n}\n\nfunction slugsOf(value: Slugged[] | Record<string, unknown> | undefined): string[] {\n if (Array.isArray(value)) {\n return value.map((item) => item?.slug).filter((slug): slug is string => Boolean(slug));\n }\n if (value && typeof value === \"object\") return Object.keys(value);\n return [];\n}\n\nasync function readGlobal(\n payload: ColorUsagePayload,\n slug: string,\n): Promise<Record<string, unknown> | ThemeDoc | null | undefined> {\n try {\n return await payload.findGlobal({ slug, draft: true, depth: 0, overrideAccess: true });\n } catch {\n // A named slug that is not registered must not fail Colors Delete.\n return null;\n }\n}\n\nasync function* eachCollectionDoc(\n payload: ColorUsagePayload,\n collection: string,\n): AsyncGenerator<Record<string, unknown>> {\n let page = 1;\n for (;;) {\n let result: FindResult;\n try {\n result = await payload.find({\n collection,\n draft: true,\n depth: 0,\n limit: 100,\n page,\n overrideAccess: true,\n });\n } catch {\n return;\n }\n for (const doc of result.docs) yield doc;\n const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);\n if (page >= totalPages || result.docs.length === 0) break;\n page += 1;\n }\n}\n\nfunction idOf(doc: Record<string, unknown>): string | number | undefined {\n const id = doc.id;\n return typeof id === \"string\" || typeof id === \"number\" ? id : undefined;\n}\n","import type { Access, Endpoint, PayloadRequest } from \"payload\";\n\nimport {\n COLOR_USAGES_PATH,\n findColorUsages,\n replacementKeys,\n rewriteColorUsages,\n type ColorUsagePayload,\n type ColorUsagesOption,\n} from \"./color-usages\";\n\nexport { COLOR_USAGES_PATH };\n\nexport function colorUsageEndpoints(\n access: { update: Access },\n scopes: ColorUsagesOption | undefined,\n): Endpoint[] {\n return [\n {\n path: COLOR_USAGES_PATH,\n method: \"get\",\n handler: async (req) => {\n const denied = await denyUnlessUpdate(req, access.update);\n if (denied) return denied;\n const key = queryKey(req);\n if (!key) return Response.json({ error: \"key is required\" }, { status: 400 });\n const usages = await findColorUsages(req.payload as unknown as ColorUsagePayload, scopes, key);\n return Response.json({ usages });\n },\n },\n {\n path: COLOR_USAGES_PATH,\n method: \"post\",\n handler: async (req) => {\n const denied = await denyUnlessUpdate(req, access.update);\n if (denied) return denied;\n const body = (await readJson(req)) as { key?: unknown; replacement?: unknown } | null;\n const key = typeof body?.key === \"string\" ? body.key : \"\";\n const replacement = typeof body?.replacement === \"string\" ? body.replacement : \"\";\n if (!key || !replacement) {\n return Response.json({ error: \"key and replacement are required\" }, { status: 400 });\n }\n const live = await replacementKeys(req.payload as unknown as ColorUsagePayload, key);\n if (!live.includes(replacement)) {\n return Response.json(\n { error: \"Replacement must be a different live system or remaining custom key\" },\n { status: 400 },\n );\n }\n await rewriteColorUsages(req.payload as unknown as ColorUsagePayload, scopes, key, replacement);\n return Response.json({ ok: true });\n },\n },\n ];\n}\n\nasync function denyUnlessUpdate(req: PayloadRequest, update: Access): Promise<Response | null> {\n const allowed = await update({ req });\n if (allowed) return null;\n return Response.json({ error: \"Forbidden\" }, { status: 403 });\n}\n\nfunction queryKey(req: PayloadRequest): string {\n const fromQuery = req.query?.key;\n if (typeof fromQuery === \"string\") return fromQuery;\n if (Array.isArray(fromQuery) && typeof fromQuery[0] === \"string\") return fromQuery[0];\n if (req.url) {\n try {\n return new URL(req.url, \"http://local\").searchParams.get(\"key\") ?? \"\";\n } catch {\n return \"\";\n }\n }\n return \"\";\n}\n\nasync function readJson(req: PayloadRequest): Promise<unknown> {\n if (typeof req.json === \"function\") return req.json();\n return null;\n}\n","export const FEATURES_SLUG = \"features\";\n\nexport const FEATURE_GROUPS = [\"pages\", \"media\", \"theme\", \"users\"] as const;\n\nexport type FeatureGroupId = (typeof FEATURE_GROUPS)[number];\n\nexport const FEATURE_GROUP_LABELS: Record<FeatureGroupId, string> = {\n pages: \"Pages\",\n media: \"Media\",\n theme: \"Theme\",\n users: \"Users\",\n};\n\nexport const PACKAGE_FEATURE_SLUGS = [\n \"content\",\n \"publish\",\n \"media\",\n \"users\",\n \"roles\",\n] as const;\n\nexport type PackageFeatureSlug = (typeof PACKAGE_FEATURE_SLUGS)[number];\n\nexport interface PackageFeature {\n slug: PackageFeatureSlug;\n label: string;\n group: FeatureGroupId;\n defaultReleased: boolean;\n}\n\n/**\n * Package catalogue. Features itself is not a row — that screen is\n * Developer-only in code. Theme is not a row either: every site has the\n * Theme Global, and who may edit it is the Roles grant `theme`. Empty\n * Global falls back to these defaults.\n */\nexport const PACKAGE_FEATURES: readonly PackageFeature[] = [\n { slug: \"content\", label: \"Content\", group: \"pages\", defaultReleased: true },\n { slug: \"publish\", label: \"Publish\", group: \"pages\", defaultReleased: true },\n { slug: \"media\", label: \"Media\", group: \"media\", defaultReleased: true },\n { slug: \"users\", label: \"Users\", group: \"users\", defaultReleased: true },\n { slug: \"roles\", label: \"Roles\", group: \"users\", defaultReleased: true },\n];\n\n/** A site-only row. Other sites never see this slug. */\nexport interface FeatureExtra {\n slug: string;\n label: string;\n group?: FeatureGroupId;\n defaultReleased?: boolean;\n}\n\nexport interface FeatureRow {\n id?: string | null;\n slug: string;\n label?: string | null;\n group?: string | null;\n released: boolean;\n}\n\nexport interface FeaturesDoc {\n features?: FeatureRow[] | null;\n}\n\nexport function isFeatureGroupId(value: unknown): value is FeatureGroupId {\n return typeof value === \"string\" && (FEATURE_GROUPS as readonly string[]).includes(value);\n}\n\nexport function isPackageFeatureSlug(value: unknown): value is PackageFeatureSlug {\n return typeof value === \"string\" && (PACKAGE_FEATURE_SLUGS as readonly string[]).includes(value);\n}\n\nexport function isFeatureSlug(value: unknown): value is string {\n return typeof value === \"string\" && /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(value);\n}\n\n/** @deprecated Locks are gone; the release switch is the valve. */\nexport function isLockedFeature(_slug: string, _locked?: boolean | null): boolean {\n return false;\n}\n","/**\n * The Roles Global a site's generated types will describe. Optional and\n * nullable, no index signature: a generated Global is assignable to this,\n * never the reverse.\n */\n\nexport const ROLES = [\"developer\", \"admin\", \"designer\", \"author\"] as const;\n\nexport type Role = (typeof ROLES)[number];\n\nexport const ROLE_LABELS: Record<Role, string> = {\n developer: \"Developer\",\n admin: \"Admin\",\n designer: \"Designer\",\n author: \"Author\",\n};\n\n/** Capability aliases over feature grants. Brand is the Theme grant. */\nexport const CAPABILITIES = [\"content\", \"brand\", \"publish\", \"users\"] as const;\n\nexport type Capability = (typeof CAPABILITIES)[number];\n\n/** One Roles grant. Opens the Theme document and brand-assets. Not a Features row. */\nexport const THEME_FEATURE_SLUGS = [\"theme\"] as const;\n\n/**\n * Grants stored before Theme was one row. Reading any of them is the\n * Theme grant, so a Designer who already had Colors keeps Theme.\n */\nexport const LEGACY_THEME_FEATURE_SLUGS = [\n \"theme-colors\",\n \"theme-typography\",\n \"theme-appearance\",\n \"theme-identity\",\n \"brand-assets\",\n] as const;\n\nexport const CAPABILITY_FEATURES: Record<Capability, readonly string[]> = {\n content: [\"content\"],\n publish: [\"publish\"],\n users: [\"users\"],\n brand: THEME_FEATURE_SLUGS,\n};\n\nexport const DEFAULT_ROLE_GRANTS: Record<Role, readonly string[]> = {\n developer: [],\n admin: [\"content\", \"publish\", \"media\", \"users\", \"roles\"],\n designer: [\n \"content\",\n \"media\",\n ...THEME_FEATURE_SLUGS,\n \"users\",\n \"roles\",\n ],\n author: [\"content\", \"media\"],\n};\n\n/**\n * A site-defined row passed into `createRoles({ extras })`. The slug is the\n * stored key; the label is what Settings → Roles and Users show.\n */\nexport interface RoleExtra {\n role: string;\n label: string;\n grants?: readonly string[];\n}\n\nexport interface RoleRow {\n id?: string | null;\n role: string;\n label?: string | null;\n grants: string[];\n}\n\nexport interface RolesDoc {\n roles?: RoleRow[] | null;\n}\n\n/**\n * `req.user` as Payload hands it over. Structural so this module never\n * imports a site's generated `User`. `roles` is optional because a row\n * that predates the field must come back powerless.\n */\nexport type MaybeUser = {\n id?: string | number;\n roles?: readonly string[] | null;\n /** Feature slugs this login may use, stamped onto the JWT at read. */\n allowedFeatures?: readonly string[] | null;\n} | null | undefined;\n\nexport function isRole(value: unknown): value is Role {\n return typeof value === \"string\" && (ROLES as readonly string[]).includes(value);\n}\n\n/** Lowercase slug from a letters-and-spaces name: `designer`, `the-designer`. */\nexport function isRoleSlug(value: unknown): value is string {\n return typeof value === \"string\" && /^[a-z]+(-[a-z]+)*$/.test(value);\n}\n\n/** Display name: letters and single spaces only. `The Greatest Designer`. */\nexport function isRoleName(value: unknown): value is string {\n return typeof value === \"string\" && /^[A-Za-z]+(?: [A-Za-z]+)*$/.test(value.trim());\n}\n\n/** Strip digits and punctuation as the name is typed. Trailing space stays. */\nexport function sanitizeRoleNameInput(value: string): string {\n return value.replace(/[^A-Za-z ]/g, \"\").replace(/ {2,}/g, \" \");\n}\n\n/** Name → stored key. `The Greatest Designer` → `the-greatest-designer`. */\nexport function slugifyRoleName(value: unknown): string {\n if (typeof value !== \"string\") return \"\";\n return value\n .trim()\n .toLowerCase()\n .replace(/[^a-z]+/g, \"-\")\n .replace(/^-|-$/g, \"\");\n}\n\nexport function roleLabel(role: string, label?: string | null): string {\n const trimmed = typeof label === \"string\" ? label.trim() : \"\";\n if (trimmed) return trimmed;\n return isRole(role) ? ROLE_LABELS[role] : role;\n}\n\nexport function defaultGrantsForRole(role: string, extraGrants?: readonly string[]): string[] {\n if (isRole(role)) return [...DEFAULT_ROLE_GRANTS[role]];\n return extraGrants ? [...extraGrants] : [];\n}\n","import {\n FEATURE_GROUP_LABELS,\n isFeatureGroupId,\n isFeatureSlug,\n PACKAGE_FEATURES,\n type FeatureExtra,\n type FeatureGroupId,\n type FeatureRow,\n type PackageFeature,\n} from \"./types\";\nimport { LEGACY_THEME_FEATURE_SLUGS } from \"../roles/types\";\n\nexport const MISSING_PACKAGE_FEATURES_MESSAGE =\n \"Features must include Content, Publish, Media, Users, and Roles.\";\n\nexport interface FeatureCatalogueEntry {\n slug: string;\n label: string;\n group: FeatureGroupId;\n defaultReleased: boolean;\n}\n\nexport function featureCatalogue(extras: readonly FeatureExtra[] = []): FeatureCatalogueEntry[] {\n return [\n ...PACKAGE_FEATURES.map((feature) => ({ ...feature })),\n ...extras.map((extra) => ({\n slug: extra.slug,\n label: extra.label,\n group: extra.group ?? \"users\",\n defaultReleased: extra.defaultReleased ?? false,\n })),\n ];\n}\n\nexport function defaultFeaturesFieldValue(extras: readonly FeatureExtra[] = []): FeatureRow[] {\n return featureCatalogue(extras).map((feature) => ({\n id: feature.slug,\n slug: feature.slug,\n label: feature.label,\n group: feature.group,\n released: feature.defaultReleased,\n }));\n}\n\nexport function stampFeatureCatalogue(\n value: unknown,\n extras: readonly FeatureExtra[] = [],\n): FeatureRow[] {\n const bySlug = new Map(featureCatalogue(extras).map((feature) => [feature.slug, feature]));\n if (!Array.isArray(value)) return defaultFeaturesFieldValue(extras);\n return value.flatMap((item) => {\n if (!item || typeof item !== \"object\") return [];\n const slug = \"slug\" in item && typeof item.slug === \"string\" ? item.slug : \"\";\n const feature = bySlug.get(slug);\n if (!feature) return [];\n return [\n {\n id: feature.slug,\n slug: feature.slug,\n label: feature.label,\n group: feature.group,\n released: Boolean(\"released\" in item && item.released),\n },\n ];\n });\n}\n\nexport function parseFeaturesMatrix(\n value: unknown,\n): { ok: true; rows: FeatureRow[] } | { ok: false; message: string } {\n if (!Array.isArray(value) || value.length === 0) {\n return { ok: false, message: MISSING_PACKAGE_FEATURES_MESSAGE };\n }\n\n const rows: FeatureRow[] = [];\n const seen = new Set<string>();\n\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n const slug = \"slug\" in item ? item.slug : undefined;\n if (!isFeatureSlug(slug) || seen.has(slug)) continue;\n seen.add(slug);\n const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);\n const label =\n \"label\" in item && typeof item.label === \"string\"\n ? item.label\n : (pack?.label ?? slug);\n const group =\n \"group\" in item && isFeatureGroupId(item.group) ? item.group : (pack?.group ?? \"users\");\n rows.push({\n id: slug,\n slug,\n label,\n group,\n released: Boolean(\"released\" in item && item.released),\n });\n }\n\n if (PACKAGE_FEATURES.some((feature) => !seen.has(feature.slug))) {\n return { ok: false, message: MISSING_PACKAGE_FEATURES_MESSAGE };\n }\n return { ok: true, rows };\n}\n\nexport function validateFeaturesMatrix(\n value: unknown,\n extras: readonly FeatureExtra[] = [],\n): true | string {\n const parsed = parseFeaturesMatrix(value);\n if (!parsed.ok) return parsed.message;\n const allowed = new Set(featureCatalogue(extras).map((feature) => feature.slug));\n const legacy = new Set<string>(LEGACY_THEME_FEATURE_SLUGS);\n // Retired Theme rows stay valid until beforeChange drops them. The admin\n // form calls validate without field hooks, so rejecting them blocks Save.\n if (parsed.rows.some((row) => !allowed.has(row.slug) && !legacy.has(row.slug))) {\n return MISSING_PACKAGE_FEATURES_MESSAGE;\n }\n return true;\n}\n\nexport function featureGroupLabel(group: string): string {\n return isFeatureGroupId(group) ? FEATURE_GROUP_LABELS[group] : group;\n}\n\nexport function packageFeatureLabel(slug: string, extras: readonly FeatureExtra[] = []): string {\n if (slug === \"theme\") return \"Theme\";\n const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);\n if (pack) return pack.label;\n const extra = extras.find((feature) => feature.slug === slug);\n return extra?.label ?? slug;\n}\n\nexport function isGroupOnlySlug(slug: string): boolean {\n return isFeatureGroupId(slug) && !PACKAGE_FEATURES.some((feature) => feature.slug === slug);\n}\n\nexport type { PackageFeature };\n","import { packageFeatureLabel } from \"../features/matrix\";\nimport { isFeatureSlug } from \"../features/types\";\nimport {\n CAPABILITY_FEATURES,\n defaultGrantsForRole,\n isRole,\n isRoleName,\n isRoleSlug,\n LEGACY_THEME_FEATURE_SLUGS,\n ROLE_LABELS,\n roleLabel,\n ROLES,\n slugifyRoleName,\n type Capability,\n type RoleExtra,\n type RoleRow,\n} from \"./types\";\n\nexport const ROLES_SLUG = \"roles\";\n\nexport const ROLES_GLOBAL_DESCRIPTION = \"Who may do what. Drag to change rank.\";\n\nexport const ROLES_FIELD_DESCRIPTION =\n \"Drag to change rank. Ticks are features released on Features, plus Theme. Developer has the whole catalogue.\"\n\n/**\n * Default rank and grants. Developer is implicit (empty grants). The\n * Theme grant defaults to Designer.\n */\nexport const DEFAULT_ROLE_MATRIX: readonly RoleRow[] = ROLES.map((role) => ({\n role,\n grants: defaultGrantsForRole(role),\n}));\n\nexport const DEVELOPER_DESCRIPTION =\n \"Everything, including features not released for assignment.\";\n\nexport const LAST_USERS_TICK_MESSAGE =\n \"Keep Users granted on at least one of Admin or Developer.\";\n\nexport const MISSING_SEED_ROLES_MESSAGE = \"Roles must include Developer.\";\n\nexport const DUPLICATE_ROLE_SLUG_MESSAGE = \"Each role needs a unique slug.\";\n\nexport const DUPLICATE_ROLE_NAME_MESSAGE = \"Each role needs a unique name.\";\n\nexport const INVALID_ROLE_NAME_MESSAGE = \"Use letters and spaces only.\";\n\nconst LEGACY_THEME_GRANTS = new Set<string>(LEGACY_THEME_FEATURE_SLUGS);\n\nfunction uniqueSlugs(values: readonly unknown[]): string[] {\n const slugs: string[] = [];\n for (const value of values) {\n if (typeof value === \"string\" && isFeatureSlug(value) && !slugs.includes(value)) slugs.push(value);\n }\n return slugs;\n}\n\n/** One Theme grant. A stored Colors or brand-assets tick is that grant. */\nfunction collapseThemeGrant(slugs: readonly string[]): string[] {\n let theme = false;\n const next: string[] = [];\n for (const slug of slugs) {\n if (slug === \"theme\" || LEGACY_THEME_GRANTS.has(slug)) {\n theme = true;\n continue;\n }\n next.push(slug);\n }\n if (theme) next.push(\"theme\");\n return next;\n}\n\n/** Read stored grants, or rebuild them from the old capability ticks. */\nexport function grantsFromStoredRole(item: object): string[] {\n if (\"grants\" in item && Array.isArray(item.grants)) return collapseThemeGrant(uniqueSlugs(item.grants));\n const grants: string[] = [];\n if (\"content\" in item && item.content) {\n grants.push(\"content\", \"media\");\n }\n if (\"publish\" in item && item.publish) grants.push(\"publish\");\n if (\"users\" in item && item.users) grants.push(\"users\", \"roles\");\n if (\"brand\" in item && item.brand) grants.push(\"theme\");\n return collapseThemeGrant(uniqueSlugs(grants));\n}\n\nexport function seedRoleRows(extras: readonly RoleExtra[] = []): RoleRow[] {\n return [\n ...DEFAULT_ROLE_MATRIX.map((row) => ({\n ...row,\n grants: [...row.grants],\n label: isRole(row.role) ? ROLE_LABELS[row.role] : row.role,\n })),\n ...extras.map((extra) => ({\n role: extra.role,\n label: extra.label,\n grants: extra.grants ? [...extra.grants] : [],\n })),\n ];\n}\n\nexport function defaultRolesFieldValue(extras: readonly RoleExtra[] = []): RoleRow[] {\n return seedRoleRows(extras).map((row) => ({ id: row.role, ...row }));\n}\n\nfunction readRoleRow(item: object): RoleRow | { error: string } {\n const role = \"role\" in item ? item.role : undefined;\n if (typeof role !== \"string\" || role.trim() === \"\") return { error: DUPLICATE_ROLE_SLUG_MESSAGE };\n if (!isRoleSlug(role)) return { error: DUPLICATE_ROLE_SLUG_MESSAGE };\n const label = \"label\" in item && typeof item.label === \"string\" ? item.label : undefined;\n return {\n id: role,\n role,\n label: roleLabel(role, label),\n grants: grantsFromStoredRole(item),\n };\n}\n\nexport function parseRolesMatrix(\n value: unknown,\n): { ok: true; rows: RoleRow[] } | { ok: false; message: string } {\n if (!Array.isArray(value)) {\n return { ok: false, message: MISSING_SEED_ROLES_MESSAGE };\n }\n\n const rows: RoleRow[] = [];\n const seen = new Set<string>();\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n // An Add Role row starts with no slug. Skip it so form-state can\n // build the fields; the slug field still refuses an empty save.\n const role = \"role\" in item ? item.role : undefined;\n if (typeof role !== \"string\" || role.trim() === \"\") continue;\n const parsed = readRoleRow(item);\n if (\"error\" in parsed) return { ok: false, message: parsed.error };\n if (seen.has(parsed.role)) return { ok: false, message: DUPLICATE_ROLE_SLUG_MESSAGE };\n seen.add(parsed.role);\n rows.push(parsed);\n }\n\n if (!seen.has(\"developer\")) {\n return { ok: false, message: MISSING_SEED_ROLES_MESSAGE };\n }\n return { ok: true, rows };\n}\n\nexport function roleHasGrant(row: RoleRow, slug: string): boolean {\n if (row.role === \"developer\") return true;\n return row.grants.includes(slug);\n}\n\nexport function roleHasCapability(row: RoleRow, capability: Capability): boolean {\n if (row.role === \"developer\") return true;\n return CAPABILITY_FEATURES[capability].some((slug) => row.grants.includes(slug));\n}\n\n/**\n * Mint a slug from the name only when the row has none yet. An existing\n * key — seed or custom — stays put so a rename cannot orphan users.\n */\nexport function applyRoleSlugsFromNames(value: unknown): unknown {\n if (!Array.isArray(value)) return value;\n return value.map((item) => {\n if (!item || typeof item !== \"object\") return item;\n const row = item as RoleRow;\n if (isRoleSlug(row.role)) return item;\n const slug = slugifyRoleName(row.label);\n return isRoleSlug(slug) ? { ...row, role: slug } : item;\n });\n}\n\nfunction hasDuplicateRoleNames(value: unknown): boolean {\n if (!Array.isArray(value)) return false;\n const seen = new Set<string>();\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n const role = \"role\" in item && typeof item.role === \"string\" ? item.role : \"\";\n const raw = \"label\" in item && typeof item.label === \"string\" ? item.label : \"\";\n const name = raw.trim() || (isRole(role) ? ROLE_LABELS[role] : \"\");\n if (!name) continue;\n const key = name.toLowerCase();\n if (seen.has(key)) return true;\n seen.add(key);\n }\n return false;\n}\n\nfunction hasInvalidRoleName(value: unknown): boolean {\n if (!Array.isArray(value)) return false;\n for (const item of value) {\n if (!item || typeof item !== \"object\") continue;\n const label = \"label\" in item && typeof item.label === \"string\" ? item.label.trim() : \"\";\n if (!label) continue;\n if (!isRoleName(label)) return true;\n }\n return false;\n}\n\nexport function validateRolesMatrix(value: unknown): true | string {\n if (hasDuplicateRoleNames(value)) return DUPLICATE_ROLE_NAME_MESSAGE;\n if (hasInvalidRoleName(value)) return INVALID_ROLE_NAME_MESSAGE;\n const parsed = parseRolesMatrix(applyRoleSlugsFromNames(value));\n if (!parsed.ok) return parsed.message;\n return true;\n}\n\n/**\n * Developer is exclusive. Admin does not swallow Designer: both store.\n * Unknown slugs (dropped catalogue keys such as `approver`) fall away unless\n * they appear on the matrix.\n */\nexport function normalizeStoredRoles(\n value: unknown,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): string[] {\n if (!Array.isArray(value)) return [];\n const allowed = new Set(matrix.map((row) => row.role));\n const roles = [...new Set(value.filter((entry): entry is string => typeof entry === \"string\" && allowed.has(entry)))];\n if (roles.includes(\"developer\")) return [\"developer\"];\n return roles;\n}\n\nexport function roleSelectOptions(matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX) {\n return matrix.map((row) => ({ label: roleLabel(row.role, row.label), value: row.role }));\n}\n\n/** Grant copy only. Developer names the unreleased catalogue; nothing about MCP or seed. */\nexport function roleDescription(role: string, matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX): string {\n if (role === \"developer\") return DEVELOPER_DESCRIPTION;\n const row = matrix.find((entry) => entry.role === role);\n if (!row) return \"No capabilities\";\n const ticks = row.grants.map((slug) => packageFeatureLabel(slug));\n return ticks.join(\", \") || \"No capabilities\";\n}\n\n/**\n * Seed grants and package labels come back; extra rows stay as they are.\n */\nexport function resetRolesMatrix(current: unknown): RoleRow[] {\n const extras: RoleRow[] = [];\n if (Array.isArray(current)) {\n for (const item of current) {\n if (!item || typeof item !== \"object\") continue;\n const parsed = readRoleRow(item);\n if (\"error\" in parsed || isRole(parsed.role)) continue;\n extras.push(parsed);\n }\n }\n return [...defaultRolesFieldValue(), ...extras];\n}\n","import type { Access, PayloadRequest } from \"payload\";\n\nimport { DEFAULT_ROLE_MATRIX, parseRolesMatrix, roleHasCapability, roleHasGrant, ROLES_SLUG, seedRoleRows } from \"./matrix\";\nimport { type Capability, type MaybeUser, type RoleExtra, type RoleRow } from \"./types\";\n\nexport type { MaybeUser } from \"./types\";\n\ntype AccessArgs = {\n req: {\n user?: MaybeUser;\n payload?: Pick<NonNullable<PayloadRequest[\"payload\"]>, \"findGlobal\">;\n };\n};\n\ntype CapabilityPredicate = {\n (user: MaybeUser, matrix?: readonly RoleRow[]): boolean;\n (args: AccessArgs): boolean | Promise<boolean>;\n};\n\nfunction isAccessArgs(value: unknown): value is AccessArgs {\n return typeof value === \"object\" && value !== null && \"req\" in value;\n}\n\nexport function storedRoles(user: MaybeUser): readonly string[] {\n return Array.isArray(user?.roles) ? user.roles : [];\n}\n\nexport function hasRole(user: MaybeUser, role: string): boolean {\n return storedRoles(user).includes(role);\n}\n\n/** Not a tick. True only when `developer` is stored on the row. */\nexport function isDeveloper(user: MaybeUser): boolean {\n return hasRole(user, \"developer\");\n}\n\nexport function hasCapability(\n user: MaybeUser,\n capability: Capability,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (isDeveloper(user)) return true;\n return storedRoles(user).some((role) => {\n const row = matrix.find((entry) => entry.role === role);\n return row ? roleHasCapability(row, capability) : false;\n });\n}\n\nexport function hasGrant(\n user: MaybeUser,\n slug: string,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (isDeveloper(user)) return true;\n return storedRoles(user).some((role) => {\n const row = matrix.find((entry) => entry.role === role);\n return row ? roleHasGrant(row, slug) : false;\n });\n}\n\n/**\n * Reads the saved Roles Global, falling back to the seed when the row is\n * empty, missing, or unreadable. Always override-access so a Designer\n * evaluating Theme does not have to read Settings → Roles.\n */\nexport async function getRolesMatrix(\n req: AccessArgs[\"req\"] = {},\n extras: readonly RoleExtra[] = [],\n): Promise<RoleRow[]> {\n const fallback = seedRoleRows(extras);\n const findGlobal = req.payload?.findGlobal;\n if (typeof findGlobal !== \"function\") return fallback;\n try {\n const doc = await findGlobal({\n slug: ROLES_SLUG,\n overrideAccess: true,\n req: req as PayloadRequest,\n });\n const parsed = parseRolesMatrix(doc && typeof doc === \"object\" && \"roles\" in doc ? doc.roles : undefined);\n return parsed.ok ? parsed.rows : fallback;\n } catch {\n return fallback;\n }\n}\n\nfunction capabilityPredicate(capability: Capability): CapabilityPredicate {\n function predicate(\n userOrArgs: MaybeUser | AccessArgs,\n matrix?: readonly RoleRow[],\n ): boolean | Promise<boolean> {\n if (isAccessArgs(userOrArgs)) {\n const user = userOrArgs.req.user as MaybeUser;\n if (matrix) return hasCapability(user, capability, matrix);\n return getRolesMatrix(userOrArgs.req).then((rows) => hasCapability(user, capability, rows));\n }\n return hasCapability(userOrArgs, capability, matrix ?? DEFAULT_ROLE_MATRIX);\n }\n return predicate as CapabilityPredicate;\n}\n\nexport const canManageContent = capabilityPredicate(\"content\");\nexport const canManageBrand = capabilityPredicate(\"brand\");\nexport const canPublish = capabilityPredicate(\"publish\");\n\n/** Users grant on any held role (Developer is implicit). */\nexport const isAdmin = capabilityPredicate(\"users\");\n\n/** This role id currently has the Users grant, or is Developer. */\nexport function isPrivilegedRole(\n role: unknown,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (typeof role !== \"string\") return false;\n if (role === \"developer\") return true;\n const row = matrix.find((entry) => entry.role === role);\n return row ? roleHasGrant(row, \"users\") : false;\n}\n\nexport function isAuthenticated(user: MaybeUser): boolean;\nexport function isAuthenticated(args: AccessArgs): boolean;\nexport function isAuthenticated(userOrArgs: MaybeUser | AccessArgs): boolean {\n if (isAccessArgs(userOrArgs)) return Boolean(userOrArgs.req.user);\n return Boolean(userOrArgs);\n}\n\nexport const isAdminOrSelf: Access = async ({ req }) => {\n if (!req.user) return false;\n if (await isAdmin({ req })) return true;\n return { id: { equals: req.user.id } };\n};\n\nexport const authenticatedOrPublished: Access = ({ req: { user } }) => {\n if (isAuthenticated(user as MaybeUser)) return true;\n return { _status: { equals: \"published\" } };\n};\n\n/**\n * API tab condition. Code-locked to the `developer` slug — not a Features\n * row and not a Role tick a client can grant.\n */\nexport function isDeveloperTab({ req }: AccessArgs): boolean {\n return isDeveloper(req.user as MaybeUser);\n}\n\n/** Access for chrome globals (Features, Better Editor settings). */\nexport function developerOnlyAccess(): { read: Access; update: Access } {\n return {\n read: ({ req }) => isDeveloper(req.user as MaybeUser),\n update: ({ req }) => isDeveloper(req.user as MaybeUser),\n };\n}\n\n/** `admin.hidden`: hide unless the login is Developer. */\nexport function hideUnlessDeveloper({ user }: { user?: MaybeUser }): boolean {\n return !isDeveloper(user);\n}\n","import type { PayloadRequest } from \"payload\";\n\nimport { getRolesMatrix, hasGrant, isDeveloper, type MaybeUser } from \"../roles/access\";\nimport { DEFAULT_ROLE_MATRIX } from \"../roles/matrix\";\nimport type { RoleRow } from \"../roles/types\";\nimport { LEGACY_THEME_FEATURE_SLUGS } from \"../roles/types\";\nimport { defaultFeaturesFieldValue, isGroupOnlySlug, parseFeaturesMatrix } from \"./matrix\";\nimport { FEATURE_GROUPS, FEATURES_SLUG, type FeatureRow } from \"./types\";\n\ntype AccessArgs = {\n req: {\n user?: MaybeUser;\n payload?: Pick<NonNullable<PayloadRequest[\"payload\"]>, \"findGlobal\">;\n };\n};\n\ntype FeaturePredicate = {\n (user: MaybeUser, features?: readonly FeatureRow[] | null, roles?: readonly RoleRow[]): boolean;\n (args: AccessArgs): boolean | Promise<boolean>;\n};\n\nfunction isAccessArgs(value: unknown): value is AccessArgs {\n return typeof value === \"object\" && value !== null && \"req\" in value;\n}\n\nfunction grantedOnReleased(\n user: MaybeUser,\n slug: string,\n row: FeatureRow,\n matrix: readonly RoleRow[],\n): boolean {\n if (!row.released) return false;\n return hasGrant(user, slug, matrix);\n}\n\n/**\n * True when the feature is released and a held role is granted it.\n * Developer is always allowed. An empty Global falls back to catalogue\n * defaults. A group slug (`pages`) is true when any child is.\n * `theme` is the Roles grant: Features cannot release or withhold it.\n */\nexport function hasFeature(\n user: MaybeUser,\n slug: string,\n features: readonly FeatureRow[] | null = null,\n matrix: readonly RoleRow[] = DEFAULT_ROLE_MATRIX,\n): boolean {\n if (isDeveloper(user)) return true;\n if (!user) return false;\n // Retired slugs (`brand-assets`, `theme-colors`, …) are the Theme grant.\n // Sites that still pass canUseFeature(\"brand-assets\") keep Designer access.\n if (slug === \"theme\" || (LEGACY_THEME_FEATURE_SLUGS as readonly string[]).includes(slug)) {\n return hasGrant(user, \"theme\", matrix);\n }\n const rows = features && features.length > 0 ? features : defaultFeaturesFieldValue();\n const leaf = rows.find((entry) => entry.slug === slug);\n if (leaf) return grantedOnReleased(user, slug, leaf, matrix);\n if (!isGroupOnlySlug(slug)) return false;\n return rows.some((entry) => entry.group === slug && grantedOnReleased(user, entry.slug, entry, matrix));\n}\n\n/**\n * Reads the saved Features Global. `null` means empty or unreadable — callers\n * fall back to catalogue defaults. Always override-access.\n */\nexport async function getFeaturesMatrix(req: AccessArgs[\"req\"] = {}): Promise<FeatureRow[] | null> {\n const findGlobal = req.payload?.findGlobal;\n if (typeof findGlobal !== \"function\") return null;\n try {\n const doc = await findGlobal({\n slug: FEATURES_SLUG,\n overrideAccess: true,\n req: req as PayloadRequest,\n });\n const parsed = parseFeaturesMatrix(\n doc && typeof doc === \"object\" && \"features\" in doc ? doc.features : undefined,\n );\n return parsed.ok ? parsed.rows : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Access / nav helper for one catalogue slug. Sync against a passed grid;\n * async when given `req` so it can read both Globals.\n */\nexport function canUseFeature(slug: string): FeaturePredicate {\n function predicate(\n userOrArgs: MaybeUser | AccessArgs,\n features?: readonly FeatureRow[] | null,\n roles?: readonly RoleRow[],\n ): boolean | Promise<boolean> {\n if (isAccessArgs(userOrArgs)) {\n const user = userOrArgs.req.user as MaybeUser;\n if (features !== undefined) return hasFeature(user, slug, features, roles ?? DEFAULT_ROLE_MATRIX);\n return Promise.all([getFeaturesMatrix(userOrArgs.req), getRolesMatrix(userOrArgs.req)]).then(\n ([grid, matrix]) => hasFeature(user, slug, grid, matrix),\n );\n }\n return hasFeature(userOrArgs, slug, features ?? null, roles ?? DEFAULT_ROLE_MATRIX);\n }\n return predicate as FeaturePredicate;\n}\n\n/**\n * Feature slugs (and group slugs) this login may use. Written onto the\n * user at afterRead so `admin.hidden({ user })` can follow the saved\n * Features and Roles Globals without a `req`.\n */\nexport async function allowedFeaturesForUser(\n user: MaybeUser,\n req: AccessArgs[\"req\"] = {},\n): Promise<string[]> {\n const [features, roles] = await Promise.all([getFeaturesMatrix(req), getRolesMatrix(req)]);\n const rows = features && features.length > 0 ? features : defaultFeaturesFieldValue();\n const slugs = [...rows.map((row) => row.slug), ...FEATURE_GROUPS];\n return slugs.filter((slug) => hasFeature(user, slug, features, roles));\n}\n\nfunction userHasAllowedFeature(user: MaybeUser, slug: string): boolean {\n if (isDeveloper(user)) return true;\n const allowed = user?.allowedFeatures;\n if (!Array.isArray(allowed)) return false;\n return allowed.includes(slug);\n}\n\n/** `admin.hidden`: hide when the login cannot use the feature. */\nexport function hideUnlessFeature(slug: string) {\n return (args: { user?: MaybeUser; req?: AccessArgs[\"req\"] }) => {\n const user = args.user ?? null;\n if (isDeveloper(user)) return false;\n if (user && Array.isArray(user.allowedFeatures)) {\n return !userHasAllowedFeature(user, slug);\n }\n if (args.req) {\n const result = canUseFeature(slug)({ req: { ...args.req, user } });\n if (result instanceof Promise) return result.then((ok) => !ok);\n return !result;\n }\n return !canUseFeature(slug)(user);\n };\n}\n","import { catalog, type FontEntry } from \"@bison-lab/fonts\";\nimport { DESTRUCTIVE_SCALE_HEX, presetHints, SHADE_STEPS, SUCCESS_SCALE_HEX } from \"@bison-lab/tokens\";\nimport type { Access, Field, GlobalConfig, SelectField } from \"payload\";\n\nimport {\n SAME_AS_BODY,\n THEME_APPEARANCE_FIELD,\n THEME_COLOR_SCALE_FIELD,\n THEME_FONT_FIELD,\n THEME_GREY_SCALE_FIELD,\n THEME_LIBRARY_FIELD,\n THEME_PAIRING_FIELD,\n THEME_DOCUMENT_CONTROLS,\n THEME_SECTION_HEADING,\n headingSelectValue,\n} from \"./fields\";\nimport { APPEARANCE_CHOICES } from \"./appearance-labels\";\nimport { themeConfigFromDoc, validateSourceIncluded, validateThemeHex } from \"./map\";\nimport { colorUsageEndpoints } from \"./color-usage-endpoints\";\nimport { READABILITY_TARGET } from \"./readability\";\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { THEME_SLUG, type CreateThemeOptions, type ThemeDoc } from \"./types\";\n\nconst publicThemeRead: Access = () => true;\n\nfunction resolveAccess(options: CreateThemeOptions): { read: Access; update: Access } {\n return {\n read: options.access?.read ?? publicThemeRead,\n update: options.access?.update ?? canUseFeature(\"theme\"),\n };\n}\n\nfunction requireDestructive(options: CreateThemeOptions): string {\n return options.destructive ?? options.seed.brandDestructive ?? DESTRUCTIVE_SCALE_HEX;\n}\n\nfunction namedSelect<K extends string>(\n name: string,\n label: string,\n choices: Record<K, { label: string; hint: string }>,\n defaultValue: K,\n field?: string,\n): SelectField {\n return {\n name,\n type: \"select\",\n label,\n required: true,\n defaultValue,\n options: (Object.entries(choices) as [K, { label: string; hint: string }][]).map(\n ([value, { label: optionLabel, hint }]) => ({\n label: `${optionLabel} — ${hint}`,\n value,\n }),\n ),\n ...(field ? { admin: { components: { Field: field } } } : {}),\n };\n}\n\nconst STEP_OPTIONS = SHADE_STEPS.map((step) => ({ label: String(step), value: String(step) }));\n\nfunction colorScaleFields(hexDefault?: string): Field[] {\n const hidden = { hidden: true } as const;\n return [\n {\n name: \"hex\",\n type: \"text\",\n label: \"Hex\",\n required: true,\n ...(hexDefault ? { defaultValue: hexDefault } : {}),\n validate: validateThemeHex,\n admin: hidden,\n },\n {\n name: \"sourceStep\",\n type: \"select\",\n label: \"Source step\",\n required: true,\n defaultValue: \"500\",\n options: STEP_OPTIONS,\n admin: hidden,\n },\n {\n name: \"scale\",\n type: \"json\",\n label: \"Scale\",\n admin: hidden,\n },\n {\n name: \"stale\",\n type: \"checkbox\",\n label: \"Stale\",\n defaultValue: false,\n admin: hidden,\n },\n {\n name: \"include\",\n type: \"select\",\n label: \"Include\",\n required: true,\n defaultValue: \"all\",\n options: [\n { label: \"Include all\", value: \"all\" },\n { label: \"Source only\", value: \"source\" },\n { label: \"Custom\", value: \"custom\" },\n ],\n admin: hidden,\n },\n {\n name: \"includedSteps\",\n type: \"select\",\n label: \"Included steps\",\n hasMany: true,\n options: STEP_OPTIONS,\n validate: validateSourceIncluded,\n admin: hidden,\n },\n ];\n}\n\nfunction systemColorGroup(name: string, label: string, hexDefault: string): Field {\n return {\n name,\n type: \"group\",\n label,\n fields: colorScaleFields(hexDefault),\n admin: { components: { Field: THEME_COLOR_SCALE_FIELD }, hideGutter: true },\n };\n}\n\nfunction fontField(\n name: string,\n label: string,\n defaultValue: string,\n fonts: readonly FontEntry[],\n fontsBaseUrl: string,\n sameAsBody: boolean,\n): SelectField {\n const options = fonts.map((font) => ({ label: font.family, value: font.id }));\n return {\n name,\n type: \"select\",\n label,\n required: !sameAsBody,\n defaultValue,\n options: sameAsBody ? [{ label: \"Same as body\", value: SAME_AS_BODY }, ...options] : options,\n admin: {\n components: { Field: THEME_FONT_FIELD },\n custom: { fontsBaseUrl, ids: fonts.map((font) => font.id), sameAsBody },\n },\n };\n}\n\nfunction colorsFields(seed: CreateThemeOptions[\"seed\"], destructive: string): Field[] {\n return [\n {\n name: \"colors\",\n type: \"group\",\n label: false,\n admin: { hideGutter: true, width: \"100%\" },\n fields: [\n {\n name: \"brand\",\n type: \"group\",\n label: false,\n admin: { hideGutter: true, width: \"100%\" },\n fields: [\n {\n name: \"themeColorsHeading\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_SECTION_HEADING },\n custom: {\n title: \"Brand colors\",\n hint: \"These colors define the visual identity of the site. Adjust them freely to match the brand.\",\n },\n },\n },\n systemColorGroup(\"primary\", \"Primary\", seed.brandPrimary),\n systemColorGroup(\"secondary\", \"Secondary\", seed.brandSecondary),\n systemColorGroup(\"accent\", \"Accent\", seed.brandAccent),\n systemColorGroup(\"highlight\", \"Highlight\", seed.brandHighlight),\n {\n name: \"libraryPlacement\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_LIBRARY_FIELD },\n custom: { dataPath: \"colors.library\" },\n },\n },\n {\n name: \"greyPlacement\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_GREY_SCALE_FIELD },\n custom: { dataPath: \"colors.greyScale\" },\n },\n },\n {\n name: \"statusColorsHeading\",\n type: \"ui\",\n admin: {\n components: { Field: THEME_SECTION_HEADING },\n custom: {\n title: \"Status colors\",\n hint: \"These colors communicate meaning across the site. You can adjust them to fit your brand, but we'll help keep them recognizable as success and error states.\",\n },\n },\n },\n systemColorGroup(\"success\", \"Success\", seed.brandSuccess || SUCCESS_SCALE_HEX),\n systemColorGroup(\"destructive\", \"Destructive\", destructive),\n ],\n },\n {\n ...namedSelect(\"greyScale\", \"Gray family\", presetHints.greyScale, seed.greyScale, THEME_GREY_SCALE_FIELD),\n admin: { hidden: true, components: { Field: THEME_GREY_SCALE_FIELD } },\n },\n {\n name: \"library\",\n type: \"array\",\n label: \"Additional colors\",\n labels: { singular: \"Color\", plural: \"Colors\" },\n fields: [\n { name: \"key\", type: \"text\", label: \"Key\", required: true, admin: { hidden: true } },\n { name: \"label\", type: \"text\", label: \"Name\", required: true, admin: { hidden: true } },\n ...colorScaleFields(),\n ],\n admin: { hidden: true, components: { Field: THEME_LIBRARY_FIELD }, width: \"100%\" },\n },\n ],\n },\n ];\n}\n\nfunction typographyFields(\n seed: CreateThemeOptions[\"seed\"],\n fonts: readonly FontEntry[],\n fontsBaseUrl: string,\n): Field[] {\n return [\n {\n name: \"typography\",\n type: \"group\",\n label: \"Typography\",\n fields: [\n fontField(\n \"heading\",\n \"Heading font\",\n headingSelectValue(seed.fontHeading),\n fonts,\n fontsBaseUrl,\n true,\n ),\n fontField(\"body\", \"Body font\", seed.fontBody, fonts, fontsBaseUrl, false),\n {\n name: \"pairing\",\n type: \"ui\",\n admin: { components: { Field: THEME_PAIRING_FIELD }, custom: { fontsBaseUrl } },\n },\n ],\n },\n ];\n}\n\nfunction appearanceFields(seed: CreateThemeOptions[\"seed\"]): Field[] {\n return [\n {\n name: \"appearance\",\n type: \"group\",\n label: \"Appearance\",\n fields: [\n namedSelect(\"defaultTheme\", \"Default theme\", APPEARANCE_CHOICES.defaultTheme, seed.defaultTheme),\n namedSelect(\"radius\", \"Corner style\", APPEARANCE_CHOICES.radius, seed.radius),\n namedSelect(\"shadow\", \"Depth\", APPEARANCE_CHOICES.shadow, seed.shadow),\n namedSelect(\"motion\", \"Motion\", APPEARANCE_CHOICES.motion, seed.motion),\n namedSelect(\"density\", \"Spacing\", APPEARANCE_CHOICES.density, seed.density),\n ],\n admin: { components: { Field: THEME_APPEARANCE_FIELD } },\n },\n ];\n}\n\nfunction identityFields(collection: string): Field[] {\n return [\n {\n name: \"logo\",\n type: \"upload\",\n relationTo: collection,\n label: \"Logo\",\n admin: {\n description: \"The full wordmark used in the header and footer.\",\n },\n },\n {\n name: \"favicon\",\n type: \"upload\",\n relationTo: collection,\n label: \"Favicon\",\n admin: {\n description: \"The small icon in the browser tab. PNG or SVG.\",\n },\n },\n {\n name: \"logoMark\",\n type: \"upload\",\n relationTo: collection,\n label: \"Mobile menu logo\",\n admin: {\n description:\n \"Optional. Used when the full logo is too wide for the mobile menu — typically the mark.\",\n },\n },\n ];\n}\n\n/**\n * One Theme Global. Colors, Typography, Appearance, and Identity are\n * tabs on that document. Save writes the whole form — Payload hydrates\n * every tab from the live row, so an untouched tab does not revert.\n * Locking is off. No draft mode, no preview pane.\n */\nexport function createTheme(options: CreateThemeOptions): GlobalConfig[] {\n const access = resolveAccess(options);\n const destructive = requireDestructive(options);\n const {\n seed,\n fonts = catalog,\n fontsBaseUrl = \"/fonts\",\n contrastTarget = READABILITY_TARGET,\n logo,\n identity,\n onPublish,\n colorUsages,\n } = options;\n\n const adminCustom = { contrastTarget, fontsBaseUrl, identityFallback: identity?.fallback };\n const colorFields = colorsFields(seed, destructive);\n const typeFields = typographyFields(seed, fonts, fontsBaseUrl);\n const lookFields = appearanceFields(seed);\n const markFields = logo ? identityFields(logo.collection) : [];\n\n return [\n {\n slug: THEME_SLUG,\n label: \"Theme\",\n lockDocuments: false,\n admin: {\n group: \"Theme\",\n hidden: hideUnlessFeature(\"theme\") as (args: { user: unknown }) => boolean,\n hideAPIURL: true,\n custom: adminCustom,\n components: {\n elements: { beforeDocumentControls: [THEME_DOCUMENT_CONTROLS] },\n },\n },\n access: {\n read: access.read,\n update: access.update,\n },\n fields: [\n {\n type: \"tabs\",\n tabs: [\n { label: \"Colors\", fields: colorFields },\n { label: \"Typography\", fields: typeFields },\n { label: \"Appearance\", fields: lookFields },\n ...(logo ? [{ label: \"Identity\" as const, fields: markFields }] : []),\n ],\n },\n ],\n endpoints: colorUsageEndpoints(access, colorUsages),\n hooks: {\n afterChange: [\n async ({ doc }) => {\n if (!onPublish) return;\n const themeDoc = doc as ThemeDoc;\n await onPublish(themeConfigFromDoc(themeDoc, seed), themeDoc);\n },\n ],\n },\n },\n ];\n}\n","const DANGEROUS_TAGS = [\"script\", \"foreignObject\", \"iframe\", \"embed\", \"object\"] as const;\n\n/**\n * Strips the SVG features a lockup does not need and an attacker would\n * use: script, foreignObject, iframe/embed/object, event handlers,\n * javascript: / data:text/html URLs, and xml-stylesheet. Internal `#`\n * refs and ordinary drawing elements stay.\n */\nexport function sanitizeSvg(source: string): string {\n if (!/<svg[\\s>]/i.test(source)) {\n throw new Error(\"Not an SVG\");\n }\n\n let out = source.replace(/<\\?xml-stylesheet[\\s\\S]*?\\?>/gi, \"\");\n\n for (const tag of DANGEROUS_TAGS) {\n out = out.replace(new RegExp(`<${tag}\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/${tag}\\\\s*>`, \"gi\"), \"\");\n out = out.replace(new RegExp(`<${tag}\\\\b[^>]*\\\\/>`, \"gi\"), \"\");\n }\n\n out = out.replace(/\\s+on[a-z][a-z0-9-]*\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/gi, \"\");\n out = out.replace(\n /((?:href|src|xlink:href)\\s*=\\s*)([\"'])\\s*(?:javascript:|data:text\\/html)[^\"']*\\2/gi,\n \"$1$2$2\",\n );\n\n return out;\n}\n\nexport function isSvgUpload(file: { mimetype?: string; name?: string; data?: Buffer }): boolean {\n if (file.mimetype === \"image/svg+xml\") return true;\n if (typeof file.name === \"string\" && file.name.toLowerCase().endsWith(\".svg\")) return true;\n return false;\n}\n","import type { Access, CollectionConfig } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { isSvgUpload, sanitizeSvg } from \"./sanitize\";\n\nexport const BRAND_ASSETS_SLUG = \"brand-assets\";\n\n/** SVG preferred; PNG allowed. ICO is for the favicon slot. */\nexport const BRAND_ASSETS_MIME_TYPES = [\n \"image/svg+xml\",\n \"image/png\",\n \"image/x-icon\",\n \"image/vnd.microsoft.icon\",\n] as const;\n\nexport interface CreateBrandAssetsOptions {\n /**\n * Same shape as `createTheme`. `read` defaults to public so the live site\n * can load the file; pass a stricter function to tighten it. `update`\n * defaults to `canUseFeature(\"theme\")` — the Theme grant — and covers\n * create, update, delete, and version history.\n */\n access?: { read?: Access; update?: Access };\n /** Default `brand-assets`. Pass the same slug to `createTheme({ logo })`. */\n slug?: string;\n}\n\nconst publicBrandRead: Access = () => true;\n\nfunction resolveAccess(options: CreateBrandAssetsOptions): { read: Access; update: Access } {\n return {\n read: options.access?.read ?? publicBrandRead,\n update: options.access?.update ?? canUseFeature(\"theme\"),\n };\n}\n\n/**\n * Locked cupboard for lockup and mark. Not ordinary Media — only a brand\n * manager writes it. Theme's `logo` / `logoMark` point here when the site\n * passes this slug as `logo.collection`.\n */\nexport function createBrandAssets(options: CreateBrandAssetsOptions = {}): CollectionConfig {\n const access = resolveAccess(options);\n const slug = options.slug ?? BRAND_ASSETS_SLUG;\n\n return {\n slug,\n labels: { singular: \"Brand asset\", plural: \"Brand assets\" },\n admin: {\n group: \"Settings\",\n useAsTitle: \"label\",\n hidden: hideUnlessFeature(\"theme\") as (args: { user: unknown }) => boolean,\n description: \"Logo, favicon, and mobile-menu mark. SVG preferred; PNG and ICO allowed.\",\n },\n upload: {\n mimeTypes: [...BRAND_ASSETS_MIME_TYPES],\n crop: false,\n focalPoint: false,\n },\n versions: true,\n access: {\n read: access.read,\n create: access.update,\n update: access.update,\n delete: access.update,\n readVersions: access.update,\n },\n fields: [\n { name: \"label\", type: \"text\", label: \"Label\" },\n { name: \"notes\", type: \"textarea\", label: \"Usage notes\" },\n { name: \"alt\", type: \"text\", label: \"Alt text\", required: true },\n ],\n hooks: {\n beforeOperation: [\n ({ req, operation }) => {\n if (operation !== \"create\" && operation !== \"update\") return;\n const file = req.file;\n if (!file || !isSvgUpload(file)) return;\n file.data = Buffer.from(sanitizeSvg(file.data.toString(\"utf8\")), \"utf8\");\n },\n ],\n },\n };\n}\n","import type { ThemeConfig } from \"@bison-lab/tokens\";\n\nimport { docFromConfig } from \"./map\";\nimport { THEME_SLUG } from \"./types\";\nimport type { ThemeDoc } from \"./types\";\n\nexport interface SeedThemePayload {\n updateGlobal: (args: {\n slug: string;\n data: ThemeDoc;\n draft?: boolean;\n }) => Promise<unknown>;\n}\n\n/**\n * Writes a published Theme from the seed. For a site's migration `up()`,\n * so the row exists on deploy and renders what `bison-theme.css` rendered.\n */\nexport async function seedTheme(payload: SeedThemePayload, seed: ThemeConfig): Promise<unknown> {\n return payload.updateGlobal({\n slug: THEME_SLUG,\n data: docFromConfig(seed),\n draft: false,\n });\n}\n","import { THEME_SLUG, type ThemeColorDoc, type ThemeDoc } from \"./types\";\n\nexport const THEME_CHILDREN = [\"colors\", \"typography\", \"appearance\", \"identity\"] as const;\n\nexport type ThemeChild = (typeof THEME_CHILDREN)[number];\n\n/**\n * Publishing a child writes that slice only. Other responsibilities stay\n * as they already are on the stored document. Unsaved form state on a\n * different child never goes live. A first save (no stored row) still\n * writes only the named child; `getPublishedTheme` fills the rest from\n * the seed.\n */\nexport function publishThemeChild(stored: ThemeDoc, incoming: ThemeDoc, child: ThemeChild): ThemeDoc {\n if (child === \"colors\") return { ...stored, colors: incoming.colors };\n if (child === \"typography\") return { ...stored, typography: incoming.typography };\n if (child === \"appearance\") return { ...stored, appearance: incoming.appearance };\n return { ...stored, logo: incoming.logo, favicon: incoming.favicon, logoMark: incoming.logoMark };\n}\n\nexport function isThemeChild(value: unknown): value is ThemeChild {\n return typeof value === \"string\" && (THEME_CHILDREN as readonly string[]).includes(value);\n}\n\nexport function sliceFromTheme(theme: ThemeDoc, child: ThemeChild): ThemeDoc {\n if (child === \"colors\") return { colors: theme.colors };\n if (child === \"typography\") return { typography: theme.typography };\n if (child === \"appearance\") return { appearance: theme.appearance };\n return { logo: theme.logo, favicon: theme.favicon, logoMark: theme.logoMark };\n}\n\nfunction colorHex(color: ThemeColorDoc | string | null | undefined): string | undefined {\n if (typeof color === \"string\") return color;\n return color?.hex ?? undefined;\n}\n\n/**\n * A Theme page is a real Global. Hydrate from the store only when this\n * page has never been saved — otherwise afterRead would overwrite the form.\n */\nexport function hasThemeSlice(doc: ThemeDoc | null | undefined, child: ThemeChild): boolean {\n if (!doc) return false;\n if (child === \"colors\") return Boolean(colorHex(doc.colors?.brand?.primary));\n if (child === \"typography\") return Boolean(doc.typography?.body);\n if (child === \"appearance\") return Boolean(doc.appearance?.radius);\n return Boolean(doc.logo || doc.favicon || doc.logoMark);\n}\n\nexport interface ThemeStorePayload {\n findGlobal: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n }) => Promise<ThemeDoc | null | undefined>;\n updateGlobal: (args: { slug: string; data: ThemeDoc; draft?: boolean }) => Promise<unknown>;\n}\n\n/**\n * Save on a Theme page writes that slice onto the hidden `theme` row.\n * Other children stay as stored.\n */\nexport async function persistThemeChild(\n payload: ThemeStorePayload,\n incoming: ThemeDoc,\n child: ThemeChild,\n): Promise<ThemeDoc> {\n const stored =\n (await payload.findGlobal({\n slug: THEME_SLUG,\n draft: false,\n overrideAccess: true,\n })) ?? {};\n const next = publishThemeChild(stored, incoming, child);\n await payload.updateGlobal({ slug: THEME_SLUG, data: next, draft: false });\n return next;\n}\n","/**\n * Import-map keys and helpers for the shared document header.\n * `documentTitleActions()` injects one admin provider so every\n * document shares the title-row lift. One-list Globals pass\n * `documentCreateNew` so Create New sits in that same slot.\n */\n\nexport const DOCUMENT_TITLE_ACTIONS = \"@bison-lab/payload-core/admin#DocumentTitleActions\";\nexport const DOCUMENT_CREATE_NEW = \"@bison-lab/payload-core/admin#DocumentCreateNew\";\n\nexport function documentCreateNew(path: string) {\n return { path: DOCUMENT_CREATE_NEW, clientProps: { path } };\n}\n","export const ROLES_MATRIX_FIELD = \"@bison-lab/payload-core/admin#RolesMatrixField\";\nexport const ROLES_ROW_LABEL = \"@bison-lab/payload-core/admin#RolesRowLabel\";\nexport const ROLE_SLUG_FIELD = \"@bison-lab/payload-core/admin#RoleSlugField\";\nexport const ROLE_NAME_FIELD = \"@bison-lab/payload-core/admin#RoleNameField\";\nexport const ROLES_FIELD = \"@bison-lab/payload-core/admin#RolesField\";\nexport const ROLES_GRANTS_FIELD = \"@bison-lab/payload-core/admin#RolesGrantsField\";\n","import type { ArrayField, GlobalConfig, TextFieldSingleValidation } from \"payload\";\n\nimport { documentCreateNew } from \"../admin/document-controls\";\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { isAdmin } from \"./access\";\nimport { ROLE_NAME_FIELD, ROLES_GRANTS_FIELD, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL } from \"./fields\";\nimport {\n applyRoleSlugsFromNames,\n defaultRolesFieldValue,\n DUPLICATE_ROLE_SLUG_MESSAGE,\n grantsFromStoredRole,\n INVALID_ROLE_NAME_MESSAGE,\n ROLES_FIELD_DESCRIPTION,\n ROLES_GLOBAL_DESCRIPTION,\n ROLES_SLUG,\n validateRolesMatrix,\n} from \"./matrix\";\nimport { isRoleName, isRoleSlug, type RoleExtra } from \"./types\";\n\nexport interface CreateRolesOptions {\n /**\n * Extra catalogue rows after the first-run defaults. Each is a slug, a\n * display label, and default grants. A site that passes nothing still\n * gets Developer / Admin / Designer / Author; an Admin may later remove\n * every row except Developer.\n */\n extras?: readonly RoleExtra[];\n}\n\nconst roleSlugValidate: TextFieldSingleValidation = (value) => {\n // Empty is fine while Create New is in progress; the name fills it on save.\n if (typeof value !== \"string\" || value === \"\") return true;\n return isRoleSlug(value) || DUPLICATE_ROLE_SLUG_MESSAGE;\n};\n\nconst roleNameValidate: TextFieldSingleValidation = (value) => {\n if (typeof value !== \"string\" || value.trim() === \"\") return true;\n return isRoleName(value) || INVALID_ROLE_NAME_MESSAGE;\n};\n\n/**\n * Settings → Roles. Rank is the array order (Payload's drag handle).\n * Ticks are released catalogue rows. Developer is implicit and shown\n * only to a Developer, with every catalogue tick locked on.\n */\nexport function createRoles({ extras = [] }: CreateRolesOptions = {}): GlobalConfig {\n const rolesField: ArrayField = {\n name: \"roles\",\n type: \"array\",\n label: \"Roles\",\n labels: { singular: \"Role\", plural: \"Roles\" },\n minRows: 1,\n required: true,\n defaultValue: defaultRolesFieldValue(extras),\n validate: validateRolesMatrix,\n hooks: {\n beforeChange: [({ value }) => applyRoleSlugsFromNames(value)],\n },\n admin: {\n components: { Field: ROLES_MATRIX_FIELD, RowLabel: ROLES_ROW_LABEL },\n description: ROLES_FIELD_DESCRIPTION,\n initCollapsed: false,\n },\n fields: [\n {\n name: \"role\",\n type: \"text\",\n label: \"Slug\",\n validate: roleSlugValidate,\n admin: { hidden: true },\n },\n {\n name: \"label\",\n type: \"text\",\n label: \"Name\",\n required: true,\n validate: roleNameValidate,\n admin: { components: { Field: ROLE_NAME_FIELD } },\n },\n {\n name: \"grants\",\n type: \"json\",\n label: \"Grants\",\n defaultValue: [],\n hooks: {\n beforeChange: [\n ({ value }) => (Array.isArray(value) ? grantsFromStoredRole({ grants: value }) : value),\n ],\n },\n admin: {\n components: { Field: ROLES_GRANTS_FIELD },\n },\n },\n ],\n };\n\n return {\n slug: ROLES_SLUG,\n label: \"Roles\",\n admin: {\n group: \"Settings\",\n hidden: hideUnlessFeature(\"roles\") as (args: { user: unknown }) => boolean,\n description: ROLES_GLOBAL_DESCRIPTION,\n components: {\n elements: {\n beforeDocumentControls: [documentCreateNew(\"roles\")],\n },\n },\n },\n access: {\n read: (args) => canUseFeature(\"roles\")(args),\n update: (args) => isAdmin(args),\n },\n fields: [rolesField],\n };\n}\n","import { defaultRolesFieldValue, ROLES_SLUG } from \"./matrix\";\nimport type { RoleExtra, RolesDoc } from \"./types\";\n\nexport interface SeedRolesPayload {\n updateGlobal: (args: { slug: string; data: RolesDoc }) => Promise<unknown>;\n}\n\n/**\n * Writes the default matrix (Developer, Admin, Designer, Author plus any\n * site extras). For a site's migration `up()`. Never writes a user row —\n * seeding `developer` on a person stays a site concern.\n */\nexport async function seedRoles(\n payload: SeedRolesPayload,\n extras: readonly RoleExtra[] = [],\n): Promise<unknown> {\n return payload.updateGlobal({\n slug: ROLES_SLUG,\n data: { roles: defaultRolesFieldValue(extras) },\n });\n}\n","export const BLOCK_LIBRARY_SLUG = \"block-library\";\n\nexport const BLOCK_LIBRARY_CATEGORIES = [\n { id: \"hero\", label: \"Hero\" },\n { id: \"feature\", label: \"Feature\" },\n { id: \"process\", label: \"Process\" },\n { id: \"faq\", label: \"FAQ\" },\n { id: \"testimonials\", label: \"Testimonials\" },\n { id: \"stats\", label: \"Stats\" },\n { id: \"content\", label: \"Content\" },\n { id: \"contact\", label: \"Contact\" },\n { id: \"cta\", label: \"CTA\" },\n { id: \"navigation\", label: \"Navigation\" },\n] as const;\n\nexport type BlockLibraryCategoryId = (typeof BLOCK_LIBRARY_CATEGORIES)[number][\"id\"];\n\nexport type BlockLibraryKind = \"hero\" | \"section\" | \"navbar\";\n\n/**\n * Package catalogue. `megaMenu` and `navLink` are header item blocks, not\n * cards. Navigation's card is `floatingNav`. CTA is a category for a site\n * extra; the package ships no CTA slug. The preview route is SPI-53.\n */\nexport const PACKAGE_BLOCK_SLUGS = [\n \"hero\",\n \"heroSweep\",\n \"heroCompact\",\n \"showcasePanels\",\n \"processSteps\",\n \"faqColumns\",\n \"testimonialMasonry\",\n \"statsBand\",\n \"richText\",\n \"nap\",\n \"floatingNav\",\n] as const;\n\nexport type PackageBlockSlug = (typeof PACKAGE_BLOCK_SLUGS)[number];\n\nexport interface BlockLibraryEntry {\n slug: string;\n label: string;\n category: string;\n /** Defaults from the category: hero, navbar for navigation, otherwise section. */\n kind?: BlockLibraryKind;\n supportsMega?: boolean;\n sample?: unknown;\n}\n\nexport interface BlockLibraryRow {\n id: string;\n slug: string;\n label: string;\n category: string;\n enabled: boolean;\n kind: BlockLibraryKind;\n}\n\nexport interface BlockLibraryHolder {\n title?: string | null;\n slug?: string | null;\n}\n\n/** A draft that still holds a slug: a collection document or a Global. */\nexport interface BlockLibraryDraftHolder extends BlockLibraryHolder {\n collection?: string;\n id?: string | number;\n global?: string;\n}\n\n/** Where a slug is used. `published` refuses a disable; `drafts` are stripped. */\nexport interface BlockLibraryUsage {\n published: BlockLibraryHolder[];\n drafts: BlockLibraryDraftHolder[];\n}\n","import type { BlockLibraryEntry, BlockLibraryHolder, BlockLibraryKind, BlockLibraryRow } from \"./types\";\nimport { PACKAGE_BLOCK_SLUGS } from \"./types\";\n\nconst NOT_CATALOGUE = new Set([\"megaMenu\", \"navLink\"]);\n\nconst PACKAGE_BLOCKS: readonly BlockLibraryEntry[] = [\n { slug: \"hero\", label: \"Hero\", category: \"hero\", kind: \"hero\" },\n { slug: \"heroSweep\", label: \"Sweep hero\", category: \"hero\", kind: \"hero\" },\n { slug: \"heroCompact\", label: \"Compact hero\", category: \"hero\", kind: \"hero\" },\n { slug: \"showcasePanels\", label: \"Showcase panels\", category: \"feature\", kind: \"section\" },\n { slug: \"processSteps\", label: \"Process steps\", category: \"process\", kind: \"section\" },\n { slug: \"faqColumns\", label: \"FAQ\", category: \"faq\", kind: \"section\" },\n { slug: \"testimonialMasonry\", label: \"Testimonials\", category: \"testimonials\", kind: \"section\" },\n { slug: \"statsBand\", label: \"Stats\", category: \"stats\", kind: \"section\" },\n { slug: \"richText\", label: \"Rich text\", category: \"content\", kind: \"section\" },\n { slug: \"nap\", label: \"Contact\", category: \"contact\", kind: \"section\" },\n { slug: \"floatingNav\", label: \"Floating navbar\", category: \"navigation\", kind: \"navbar\", supportsMega: true },\n];\n\nexport interface BlockLibraryOptions {\n blocks?: readonly BlockLibraryEntry[];\n previewPath: (slug: string) => string;\n}\n\nexport interface BlockLibraryCheck {\n originals?: readonly BlockLibraryRow[];\n /** Published documents that hold a slug being turned off. Any refuses. */\n holders?: readonly BlockLibraryHolder[];\n /** Drafts that hold it. Named in a refusal; never a reason to refuse. */\n drafts?: readonly BlockLibraryHolder[];\n pages?: unknown[];\n}\n\nexport function blockLibraryCatalogue(extras: readonly BlockLibraryEntry[] = []): BlockLibraryEntry[] {\n const extra = extras.filter((entry) => !NOT_CATALOGUE.has(entry.slug));\n return [...PACKAGE_BLOCKS.map((entry) => ({ ...entry })), ...extra];\n}\n\nexport function defaultBlockLibraryValue(options: BlockLibraryOptions): BlockLibraryRow[] {\n return blockLibraryCatalogue(options.blocks).map((entry) => toRow(entry, true));\n}\n\nfunction toRow(entry: BlockLibraryEntry, enabled = true): BlockLibraryRow {\n const kind = entry.kind ?? (entry.category === \"hero\" ? \"hero\" : entry.category === \"navigation\" ? \"navbar\" : \"section\");\n return {\n id: entry.slug,\n slug: entry.slug,\n label: entry.label,\n category: entry.category,\n enabled,\n kind,\n };\n}\n\nexport function stampBlockLibrary(value: unknown, options: BlockLibraryOptions): BlockLibraryRow[] {\n const catalogue = blockLibraryCatalogue(options.blocks);\n const incoming = new Map<string, boolean>();\n if (Array.isArray(value)) {\n for (const item of value) {\n if (!item || typeof item !== \"object\" || !(\"slug\" in item)) continue;\n const slug = item.slug;\n if (typeof slug !== \"string\" || NOT_CATALOGUE.has(slug)) continue;\n if (!catalogue.some((entry) => entry.slug === slug)) continue;\n if (\"enabled\" in item && typeof item.enabled === \"boolean\") incoming.set(slug, item.enabled);\n }\n }\n return catalogue.map((entry) => toRow(entry, incoming.get(entry.slug) ?? true));\n}\n\nfunction enabledOf(rows: readonly BlockLibraryRow[], kind: BlockLibraryKind): number {\n return rows.filter((row) => row.kind === kind && row.enabled).length;\n}\n\nfunction holderLabel(holder: BlockLibraryHolder): string {\n const title = holder.title?.trim() || \"Untitled\";\n const slug = holder.slug?.trim();\n return slug ? `${title} (${slug})` : title;\n}\n\n/**\n * Refuses a disable: the last hero, the last navbar, or a slug a published\n * document holds. Drafts alone never refuse; the Save that turns the slug\n * off strips them (`stripDrafts`). Pure — writes nothing.\n */\nexport async function validateBlockLibrary(\n value: unknown,\n options: BlockLibraryOptions,\n check: BlockLibraryCheck = {},\n): Promise<true | string> {\n const next = stampBlockLibrary(value, options);\n const previous = check.originals ?? defaultBlockLibraryValue(options);\n const turningOff = next.filter((row) => {\n const before = previous.find((entry) => entry.slug === row.slug);\n return before?.enabled !== false && row.enabled === false;\n });\n if (turningOff.length === 0) return true;\n\n if (turningOff.some((row) => row.kind === \"hero\") && enabledOf(next, \"hero\") === 0) {\n return \"Cannot disable the last hero.\";\n }\n if (turningOff.some((row) => row.kind === \"navbar\") && enabledOf(next, \"navbar\") === 0) {\n return \"Cannot disable the last navbar.\";\n }\n\n const holders = check.holders ?? [];\n if (holders.length > 0) {\n const names = holders.map(holderLabel).join(\", \");\n const slugs = turningOff.map((row) => row.label).join(\", \");\n const drafts = check.drafts ?? [];\n const draftNote =\n drafts.length > 0 ? ` Drafts also use it and were left as they are: ${drafts.map(holderLabel).join(\", \")}.` : \"\";\n return `Cannot disable ${slugs}. Still published on: ${names}. Remove it from those first.${draftNote}`;\n }\n\n return true;\n}\n\nexport function packageBlockSlugs(): readonly string[] {\n return PACKAGE_BLOCK_SLUGS;\n}\n","export const BLOCK_LIBRARY_FIELD = \"@bison-lab/payload-core/admin#BlockLibraryField\";\n","import { NAVIGATION_SLUG } from \"../navigation/types\";\nimport type { BlockLibraryDraftHolder, BlockLibraryHolder, BlockLibraryUsage } from \"./types\";\nimport { BLOCK_LIBRARY_SLUG } from \"./types\";\n\ntype FindResult = { docs: Record<string, unknown>[]; totalPages?: number };\n\nexport interface BlockLibraryPayload {\n config?: {\n collections?: { slug?: string }[];\n globals?: { slug?: string }[];\n };\n find: (args: {\n collection: string;\n draft?: boolean;\n depth?: number;\n limit?: number;\n page?: number;\n overrideAccess?: boolean;\n req?: unknown;\n }) => Promise<FindResult>;\n findGlobal?: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n req?: unknown;\n }) => Promise<Record<string, unknown> | null>;\n update?: (args: {\n collection: string;\n id: string | number;\n data: Record<string, unknown>;\n draft: true;\n depth?: number;\n overrideAccess?: boolean;\n req?: unknown;\n }) => Promise<unknown>;\n updateGlobal?: (args: {\n slug: string;\n data: Record<string, unknown>;\n draft: true;\n depth?: number;\n overrideAccess?: boolean;\n req?: unknown;\n }) => Promise<unknown>;\n}\n\nexport interface BlockUsageOptions {\n /** The slug is a navbar, so the published Header can hold it. */\n navbar?: boolean;\n /**\n * The navbar a Header uses when it names none. A Header names one with\n * `header.navbar`; until a second navbar package (BIS-132) adds that\n * picker, the package navbar is the active one.\n */\n defaultNavbar?: string;\n /** Read inside this request's transaction (a Save hook passes its `req`). */\n req?: unknown;\n}\n\n/** Payload's bookkeeping, never block rows. */\nconst NOT_CONTENT = new Set([\"id\", \"_status\", \"createdAt\", \"updatedAt\", \"globalType\"]);\n\nfunction slugsOf(value: { slug?: string }[] | undefined): string[] {\n return (value ?? []).map((item) => item.slug).filter((slug): slug is string => Boolean(slug));\n}\n\nfunction holdsSlug(value: unknown, slug: string): boolean {\n if (!value || typeof value !== \"object\") return false;\n if (Array.isArray(value)) return value.some((item) => holdsSlug(item, slug));\n const record = value as Record<string, unknown>;\n if (record.blockType === slug) return true;\n return Object.values(record).some((child) => holdsSlug(child, slug));\n}\n\n/**\n * A block row of one of `slugs`: an array row (`blockType`) or a Lexical\n * block node embedding one (`fields.blockType`), so a strip removes every\n * use `holdsSlug` counts.\n */\nfunction isRowOf(item: unknown, slugs: ReadonlySet<string>): boolean {\n if (!item || typeof item !== \"object\") return false;\n const record = item as { blockType?: unknown; fields?: { blockType?: unknown } | null };\n const blockType = record.blockType ?? (record.fields && typeof record.fields === \"object\" ? record.fields.blockType : undefined);\n return typeof blockType === \"string\" && slugs.has(blockType);\n}\n\n/** `value` with every block row of any of `slugs` removed, at any depth. */\nfunction withoutSlugs(value: unknown, slugs: ReadonlySet<string>): unknown {\n if (!value || typeof value !== \"object\") return value;\n if (Array.isArray(value)) {\n return value.filter((item) => !isRowOf(item, slugs)).map((item) => withoutSlugs(item, slugs));\n }\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, child]) => [key, withoutSlugs(child, slugs)]),\n );\n}\n\n/** The top-level fields of `doc` that hold any of `slugs`, with those rows removed. */\nfunction strippedFields(doc: Record<string, unknown>, slugs: ReadonlySet<string>): Record<string, unknown> {\n const data: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(doc)) {\n if (NOT_CONTENT.has(key) || ![...slugs].some((slug) => holdsSlug(value, slug))) continue;\n data[key] = withoutSlugs(value, slugs);\n }\n return data;\n}\n\nfunction asHolder(doc: Record<string, unknown>, fallback?: string): BlockLibraryHolder {\n return {\n title: typeof doc.title === \"string\" ? doc.title : fallback ?? null,\n slug: typeof doc.slug === \"string\" ? doc.slug : null,\n };\n}\n\n/** Payload's draft flag. A document without versions is always live. */\nfunction isDraft(doc: Record<string, unknown>): boolean {\n return doc._status === \"draft\";\n}\n\nfunction globalLabel(slug: string): string {\n return slug === NAVIGATION_SLUG ? \"Header\" : slug;\n}\n\n/** The navbar slug a Header document uses: `header.navbar`, else `fallback`. */\nexport function activeNavbar(doc: Record<string, unknown> | null | undefined, fallback: string): string {\n const header = doc?.header;\n if (header && typeof header === \"object\") {\n const navbar = (header as { navbar?: unknown }).navbar;\n if (typeof navbar === \"string\" && navbar) return navbar;\n }\n return fallback;\n}\n\nasync function findAll(\n payload: BlockLibraryPayload,\n collection: string,\n draft: boolean,\n req?: unknown,\n): Promise<Record<string, unknown>[]> {\n const docs: Record<string, unknown>[] = [];\n let page = 1;\n for (;;) {\n // A failed read throws. A partial answer would let the admin skip the\n // confirm for drafts it missed, and inside a Save Payload has already\n // rolled the transaction back.\n const result = await payload.find({\n collection,\n draft,\n depth: 0,\n limit: 100,\n page,\n overrideAccess: true,\n ...(req ? { req } : {}),\n });\n docs.push(...result.docs);\n const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);\n if (page >= totalPages || result.docs.length === 0) break;\n page += 1;\n }\n return docs;\n}\n\nasync function readGlobal(\n payload: BlockLibraryPayload,\n slug: string,\n draft: boolean,\n req?: unknown,\n): Promise<Record<string, unknown> | null> {\n if (!payload.findGlobal) return null;\n // Every slug read here is a registered Global; a failure throws (see findAll).\n return payload.findGlobal({ slug, draft, depth: 0, overrideAccess: true, ...(req ? { req } : {}) });\n}\n\n/**\n * Where `slug` is used, split the way a disable decides. Reads only.\n *\n * `published`: live documents that hold the slug (Payload's main row is the\n * published version), and the published Header when the slug is its navbar.\n * Any of these refuses the disable.\n *\n * `drafts`: documents whose newest version is a draft that holds the slug.\n * A page can be in both lists.\n */\nexport async function blockUsage(\n payload: BlockLibraryPayload,\n slug: string,\n options: BlockUsageOptions = {},\n): Promise<BlockLibraryUsage> {\n const collections = slugsOf(payload.config?.collections).filter(\n (name) => !name.startsWith(\"payload-\") && name !== BLOCK_LIBRARY_SLUG,\n );\n const globals = slugsOf(payload.config?.globals).filter((name) => name !== BLOCK_LIBRARY_SLUG);\n const published: BlockLibraryHolder[] = [];\n const drafts: BlockLibraryDraftHolder[] = [];\n\n for (const collection of collections) {\n const live = new Set<string>();\n for (const doc of await findAll(payload, collection, false, options.req)) {\n if (isDraft(doc) || !holdsSlug(doc, slug) || live.has(String(doc.id))) continue;\n live.add(String(doc.id));\n published.push(asHolder(doc));\n }\n const draft = new Set<string>();\n for (const doc of await findAll(payload, collection, true, options.req)) {\n if (doc.id == null || !isDraft(doc) || !holdsSlug(doc, slug) || draft.has(String(doc.id))) continue;\n draft.add(String(doc.id));\n drafts.push({ ...asHolder(doc), collection, id: doc.id as string | number });\n }\n }\n\n for (const global of globals) {\n const live = await readGlobal(payload, global, false, options.req);\n const navbarHere =\n options.navbar === true &&\n global === NAVIGATION_SLUG &&\n activeNavbar(live, options.defaultNavbar ?? \"\") === slug;\n if (live && !isDraft(live) && (holdsSlug(live, slug) || navbarHere)) {\n published.push(asHolder(live, globalLabel(global)));\n }\n const latest = await readGlobal(payload, global, true, options.req);\n if (latest && isDraft(latest) && holdsSlug(latest, slug)) {\n drafts.push({ ...asHolder(latest, globalLabel(global)), global });\n }\n }\n\n return { published, drafts };\n}\n\n/**\n * Removes every row of `slugs` from each draft and saves it as one new\n * draft version per document, inside `req`'s transaction. All slugs go in\n * one write so a second slug cannot write back a row the first removed.\n * Reads go through `req` too, so each starts from the newest version the\n * transaction can see. Published versions are untouched; only the fields\n * that held a slug are written.\n */\nexport async function stripDrafts(\n payload: BlockLibraryPayload,\n slugs: readonly string[],\n drafts: readonly BlockLibraryDraftHolder[],\n req?: unknown,\n): Promise<void> {\n const remove = new Set(slugs);\n if (remove.size === 0) return;\n const byCollection = new Map<string, Set<string>>();\n const globals = new Set<string>();\n for (const draft of drafts) {\n if (draft.global) globals.add(draft.global);\n if (!draft.collection || draft.id == null) continue;\n const ids = byCollection.get(draft.collection) ?? new Set<string>();\n ids.add(String(draft.id));\n byCollection.set(draft.collection, ids);\n }\n\n for (const [collection, ids] of byCollection) {\n if (!payload.update) throw new Error(\"Cannot remove blocks from drafts: Payload has no update.\");\n for (const doc of await findAll(payload, collection, true, req)) {\n if (!ids.has(String(doc.id)) || !isDraft(doc)) continue;\n const data = strippedFields(doc, remove);\n if (Object.keys(data).length === 0) continue;\n await payload.update({\n collection,\n id: doc.id as string | number,\n data,\n draft: true,\n depth: 0,\n overrideAccess: true,\n req,\n });\n }\n }\n\n for (const global of globals) {\n if (!payload.updateGlobal) throw new Error(\"Cannot remove blocks from drafts: Payload has no updateGlobal.\");\n const doc = await readGlobal(payload, global, true, req);\n if (!doc || !isDraft(doc)) continue;\n const data = strippedFields(doc, remove);\n if (Object.keys(data).length === 0) continue;\n await payload.updateGlobal({ slug: global, data, draft: true, depth: 0, overrideAccess: true, req });\n }\n}\n","import type { ArrayField, Endpoint, GlobalConfig } from \"payload\";\nimport { APIError } from \"payload\";\n\nimport { isAdmin, isAuthenticated } from \"../roles/access\";\nimport { blockLibraryCatalogue, defaultBlockLibraryValue, stampBlockLibrary, validateBlockLibrary, type BlockLibraryOptions } from \"./catalogue\";\nimport { BLOCK_LIBRARY_FIELD } from \"./fields\";\nimport { blockUsage, stripDrafts, type BlockLibraryPayload } from \"./holders\";\nimport { BLOCK_LIBRARY_SLUG, type BlockLibraryDraftHolder, type BlockLibraryEntry, type BlockLibraryRow } from \"./types\";\n\nexport interface CreateBlockLibraryOptions extends BlockLibraryOptions {\n /**\n * Who may change availability. Defaults to Admin. Not a Theme-style opt-in.\n */\n access?: {\n read?: GlobalConfig[\"access\"] extends infer A ? A extends { read?: infer R } ? R : never : never;\n update?: GlobalConfig[\"access\"] extends infer A ? A extends { update?: infer U } ? U : never : never;\n };\n /** Site extras, appended after the package catalogue, each with a category. */\n blocks?: readonly BlockLibraryEntry[];\n}\n\n/** A navbar can be held by the published Header; the package navbar is its default. */\nfunction usageOptions(row: BlockLibraryRow, rows: readonly BlockLibraryRow[]) {\n return {\n navbar: row.kind === \"navbar\",\n defaultNavbar: rows.find((entry) => entry.kind === \"navbar\")?.slug,\n };\n}\n\n/**\n * Settings → Block library. One card per installed option. Off is editorial\n * availability. The preview route that fills each island is SPI-53.\n *\n * Turning a slug off is refused while a published page or the published\n * Header holds it. Otherwise the Save that turns it off deletes its rows\n * from every draft that still holds it (the admin confirms first, using\n * `GET /api/globals/block-library/usage?slug=…`).\n */\nexport function createBlockLibrary({\n access,\n blocks = [],\n previewPath,\n}: CreateBlockLibraryOptions): GlobalConfig {\n const options = { blocks, previewPath };\n const catalogue = blockLibraryCatalogue(blocks);\n const previews = Object.fromEntries(catalogue.map((entry) => [entry.slug, previewPath(entry.slug)]));\n const blocksField: ArrayField = {\n name: \"blocks\",\n type: \"array\",\n label: \"Blocks\",\n minRows: catalogue.length,\n maxRows: catalogue.length,\n required: true,\n defaultValue: defaultBlockLibraryValue(options),\n validate: (value, args) => {\n const original = args?.siblingData ?? args?.previousValue;\n const originals = Array.isArray(original) ? stampBlockLibrary(original, options) : undefined;\n return validateBlockLibrary(value, options, { originals });\n },\n hooks: {\n beforeChange: [\n async ({ value, req, originalDoc }) => {\n const stamped = stampBlockLibrary(value, options);\n const stored =\n originalDoc && typeof originalDoc === \"object\" && \"blocks\" in originalDoc\n ? originalDoc.blocks\n : undefined;\n const originals = stampBlockLibrary(stored, options);\n const turningOff = stamped.filter((row) => {\n const before = originals.find((entry) => entry.slug === row.slug);\n return before?.enabled !== false && row.enabled === false;\n });\n if (turningOff.length === 0) return stamped;\n\n // Last hero / last navbar refuse before any document is read.\n const counted = await validateBlockLibrary(stamped, options, { originals });\n // Public (400) so the admin shows the reason, not \"Something went wrong.\"\n if (counted !== true) throw new APIError(counted, 400);\n\n const payload = req?.payload as unknown as BlockLibraryPayload | undefined;\n if (!payload) return stamped;\n\n // Every slug is checked before any draft is written, so one refusal\n // leaves every draft as it was; then one write per draft strips\n // every slug turning off.\n const drafts: BlockLibraryDraftHolder[] = [];\n for (const row of turningOff) {\n const usage = await blockUsage(payload, row.slug, { ...usageOptions(row, stamped), req });\n const alone = originals.map((entry) => (entry.slug === row.slug ? { ...entry, enabled: false } : entry));\n const message = await validateBlockLibrary(alone, options, {\n originals,\n holders: usage.published,\n drafts: usage.drafts,\n });\n if (message !== true) throw new APIError(message, 400);\n drafts.push(...usage.drafts);\n }\n if (drafts.length > 0) {\n await stripDrafts(\n payload,\n turningOff.map((row) => row.slug),\n drafts,\n req,\n );\n }\n return stamped;\n },\n ],\n },\n admin: {\n components: { Field: BLOCK_LIBRARY_FIELD },\n custom: { previews, rows: defaultBlockLibraryValue(options) },\n },\n fields: [\n { name: \"slug\", type: \"text\", required: true, admin: { readOnly: true } },\n { name: \"label\", type: \"text\", required: true, admin: { readOnly: true } },\n { name: \"category\", type: \"text\", required: true, admin: { readOnly: true } },\n { name: \"enabled\", type: \"checkbox\", admin: { hidden: true } },\n { name: \"kind\", type: \"text\", admin: { hidden: true } },\n ],\n };\n\n const update = access?.update ?? isAdmin;\n const usageEndpoint: Endpoint = {\n path: \"/usage\",\n method: \"get\",\n handler: async (req) => {\n const allowed = await Promise.resolve((update as (args: unknown) => unknown)({ req }));\n if (!allowed) return Response.json({ error: \"Forbidden\" }, { status: 403 });\n const slug = req.searchParams?.get(\"slug\") ?? \"\";\n const row = defaultBlockLibraryValue(options).find((entry) => entry.slug === slug);\n if (!row) return Response.json({ error: `Unknown block: ${slug}` }, { status: 400 });\n const usage = await blockUsage(req.payload as unknown as BlockLibraryPayload, slug, usageOptions(row, defaultBlockLibraryValue(options)));\n return Response.json(usage);\n },\n };\n\n return {\n slug: BLOCK_LIBRARY_SLUG,\n label: \"Block library\",\n admin: {\n group: \"Settings\",\n description: \"Which blocks editors may place. An island shows the sample under the published theme.\",\n },\n access: {\n read: access?.read ?? isAuthenticated,\n update,\n },\n endpoints: [usageEndpoint],\n fields: [blocksField],\n };\n}\n","export const FEATURES_MATRIX_FIELD = \"@bison-lab/payload-core/admin#FeaturesMatrixField\";\n","import type { ArrayField, GlobalConfig } from \"payload\";\n\nimport { developerOnlyAccess, hideUnlessDeveloper } from \"../roles/access\";\nimport { FEATURES_MATRIX_FIELD } from \"./fields\";\nimport { defaultFeaturesFieldValue, featureCatalogue, stampFeatureCatalogue, validateFeaturesMatrix } from \"./matrix\";\nimport { FEATURES_SLUG, type FeatureExtra } from \"./types\";\n\nexport interface CreateFeaturesOptions {\n /**\n * Site-only rows after the package catalogue. A second `createFeatures()`\n * without these extras never includes them.\n */\n extras?: readonly FeatureExtra[];\n}\n\n/**\n * Settings → Features. One release switch per catalogue row. Off hides\n * the tick on Roles; Developer still has the feature. This screen is\n * not itself a row.\n */\nexport function createFeatures({ extras = [] }: CreateFeaturesOptions = {}): GlobalConfig {\n const catalogue = featureCatalogue(extras);\n const featuresField: ArrayField = {\n name: \"features\",\n type: \"array\",\n label: \"Features\",\n labels: { singular: \"Feature\", plural: \"Features\" },\n minRows: catalogue.length,\n maxRows: catalogue.length,\n required: true,\n defaultValue: defaultFeaturesFieldValue(extras),\n validate: (value) => validateFeaturesMatrix(value, extras),\n hooks: {\n beforeValidate: [\n ({ value }) => (Array.isArray(value) ? stampFeatureCatalogue(value, extras) : value),\n ],\n beforeChange: [\n ({ value }) => (Array.isArray(value) ? stampFeatureCatalogue(value, extras) : value),\n ],\n },\n admin: {\n components: { Field: FEATURES_MATRIX_FIELD },\n description:\n \"Release a feature so it can be assigned on Roles. Off keeps it Developer-only.\",\n initCollapsed: false,\n },\n fields: [\n { name: \"slug\", type: \"text\", label: \"Slug\", required: true, admin: { readOnly: true } },\n { name: \"label\", type: \"text\", label: \"Name\", required: true, admin: { readOnly: true } },\n { name: \"group\", type: \"text\", label: \"Group\", admin: { hidden: true } },\n { name: \"released\", type: \"checkbox\", label: \"Released\", admin: { hidden: true } },\n ],\n };\n\n return {\n slug: FEATURES_SLUG,\n label: \"Features\",\n admin: {\n group: \"Settings\",\n hidden: hideUnlessDeveloper,\n description: \"Which features other people may be granted on Roles.\",\n },\n access: developerOnlyAccess(),\n fields: [featuresField],\n };\n}\n","import { defaultFeaturesFieldValue } from \"./matrix\";\nimport { FEATURES_SLUG, type FeatureExtra, type FeaturesDoc } from \"./types\";\n\nexport interface SeedFeaturesPayload {\n updateGlobal: (args: { slug: string; data: FeaturesDoc }) => Promise<unknown>;\n}\n\n/**\n * Writes the default switchboard (package rows plus any site extras).\n * For a site's migration `up()`.\n */\nexport async function seedFeatures(\n payload: SeedFeaturesPayload,\n extras: readonly FeatureExtra[] = [],\n): Promise<unknown> {\n return payload.updateGlobal({\n slug: FEATURES_SLUG,\n data: { features: defaultFeaturesFieldValue(extras) },\n });\n}\n","/**\n * The home page is the row whose `pageKey` is `/`. That key is the identifier.\n * The stored slug is an internal token so an unaddressed draft can keep an\n * empty slug without colliding with home. Editors see `/`, never the token.\n */\nexport const ROOT_PAGE_KEY = \"/\";\n\nexport const ROOT_PAGE_SLUG = \"__root__\";\n\nexport const REQUIRED_PAGE_CELL =\n \"@bison-lab/payload-core/admin#RequiredPageCell\";\n\nexport const REQUIRED_PAGE_FIELD =\n \"@bison-lab/payload-core/admin#RequiredPageField\";\n\nexport const PAGE_SLUG_CELL = \"@bison-lab/payload-core/admin#PageSlugCell\";\n\nexport const REQUIRED_PAGE_DELETE_MESSAGE =\n \"This page is required by the site and cannot be deleted.\";\n\nexport const REQUIRED_PAGE_UNPUBLISH_MESSAGE =\n \"This page is required by the site and cannot be unpublished.\";\n\nexport function isRootPageKey(value: unknown): value is typeof ROOT_PAGE_KEY {\n return value === ROOT_PAGE_KEY;\n}\n\nexport function isRequiredPageKey(\n value: unknown,\n requiredKeys: readonly string[],\n): boolean {\n return typeof value === \"string\" && requiredKeys.includes(value);\n}\n\n/** `/` is always required. Extras are site keys, not paths, and cannot be the root token. */\nexport function requiredPageKeys(extra: readonly string[] = []): string[] {\n const keys = [ROOT_PAGE_KEY];\n for (const key of extra) {\n if (key === ROOT_PAGE_KEY || key === ROOT_PAGE_SLUG || key.trim() === \"\") {\n throw new Error(\n `createPages requiredKeys cannot include ${JSON.stringify(key)}. The home page is always \"/\".`,\n );\n }\n if (!keys.includes(key)) keys.push(key);\n }\n return keys;\n}\n","import type {\n CheckboxField,\n CollectionBeforeChangeHook,\n CollectionSlug,\n Field,\n FieldAccess,\n PayloadRequest,\n TextField,\n TextFieldSingleValidation,\n Where,\n} from \"payload\";\nimport { ValidationError, validations } from \"payload\";\n\nimport { isRootPageKey, PAGE_SLUG_CELL, ROOT_PAGE_SLUG } from \"../collections/root-page-key\";\n\nexport const SLUG_FIELD = \"@bison-lab/payload-core/admin#SlugField\";\n\nexport const PAGE_TITLE_CELL = \"@bison-lab/payload-core/admin#PageTitleCell\";\n\n/** Sentinel the Parent control writes while the editor is naming a new folder. */\nexport const NEW_FOLDER_PARENT = \"__new__\";\n\nexport const EXISTING_PARENT_MESSAGE = \"That folder is already in the list. Pick it from the list.\";\n\nexport const SLUG_UNLOCK_WARNING =\n \"This page is live. Changing the address will send visitors from the old URL to the new one.\";\n\nexport interface SlugFieldOptions {\n /** The collection the field sits on — what the duplicate check searches. */\n collection: CollectionSlug;\n /**\n * True when a slug belongs to something the CMS does not own: a path the app\n * already serves from code, or one reserved for the framework. Which paths\n * those are is knowable only to the site, so it arrives as an option.\n */\n isReserved: (slug: string) => boolean;\n /**\n * Standing folder roots the site owns in code (`patients`, `providers`).\n * They appear on Parent even when no CMS page lives under them.\n */\n folderRoots?: string[];\n}\n\ninterface SlugCheckArgs extends SlugFieldOptions {\n id: number | string | undefined;\n pageKey?: unknown;\n req: PayloadRequest | undefined;\n}\n\nfunction pageKeyFrom(...sources: Array<{ pageKey?: unknown } | null | undefined>): unknown {\n for (const source of sources) {\n if (typeof source?.pageKey === \"string\" && source.pageKey) return source.pageKey;\n }\n return undefined;\n}\n\nasync function allSlugs({ collection, id, req }: SlugCheckArgs): Promise<string[]> {\n if (typeof req?.payload?.find !== \"function\") return [];\n\n const where: Where = {};\n if (id !== undefined) where.id = { not_equals: id };\n\n const query = {\n collection,\n depth: 0,\n limit: 500,\n overrideAccess: true,\n pagination: false,\n req,\n where,\n };\n\n const [live, drafts] = await Promise.all([\n req.payload.find(query),\n req.payload.find({ ...query, draft: true }),\n ]);\n\n return [...live.docs, ...drafts.docs].flatMap((doc) =>\n typeof doc.slug === \"string\" && doc.slug ? [doc.slug] : [],\n );\n}\n\nasync function existingParents(\n prefix: string,\n args: SlugCheckArgs,\n): Promise<boolean> {\n const roots = new Set((args.folderRoots ?? []).map(normalizeSlug).filter(Boolean));\n if (roots.has(prefix)) return true;\n\n const slugs = await allSlugs(args);\n if (slugs.includes(prefix)) return true;\n return inferredFolders(slugs).includes(prefix);\n}\n\nfunction slugifySegment(segment: string): string {\n return segment\n .normalize(\"NFKD\")\n .replace(/\\p{M}/gu, \"\")\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n}\n\n/**\n * A stored slug from whatever was typed: NFKD, hyphenated, slash segments\n * kept, so `Café / About Us` becomes `cafe/about-us`.\n */\nexport function normalizeSlug(value: string): string {\n return value.split(\"/\").map(slugifySegment).filter(Boolean).join(\"/\");\n}\n\n/** The folder prefix Parent stores. `__new__` resolves through `newFolder`. */\nexport function parentPrefix(parent: string | null | undefined, newFolder?: string | null): string {\n if (parent === NEW_FOLDER_PARENT) return normalizeSlug(newFolder ?? \"\");\n return typeof parent === \"string\" ? normalizeSlug(parent) : \"\";\n}\n\n/** Last segment of a stored slug — the title leaf once a folder is set. */\nexport function slugLeaf(slug: string): string {\n const parts = normalizeSlug(slug).split(\"/\");\n return parts[parts.length - 1] ?? \"\";\n}\n\n/**\n * Address from a parent prefix and a title (or an existing leaf). Title-follow\n * uses this so a folder is not wiped when the title changes.\n */\nexport function composeSlug(\n parent: string | null | undefined,\n title: string,\n newFolder?: string | null,\n): string {\n const prefix = parentPrefix(parent, newFolder);\n const leaf = slugifySegment(title);\n return prefix ? `${prefix}/${leaf}` : leaf;\n}\n\n/** Prefixes that exist only because a child slug lives under them. */\nexport function inferredFolders(slugs: string[]): string[] {\n const folders = new Set<string>();\n for (const slug of slugs) {\n const parts = normalizeSlug(slug).split(\"/\");\n for (let i = 1; i < parts.length; i += 1) {\n folders.add(parts.slice(0, i).join(\"/\"));\n }\n }\n return [...folders].sort();\n}\n\n/** Slash count after the first segment — how far to indent a list row. */\nexport function slugDepth(slug: string): number {\n const normalized = normalizeSlug(slug);\n if (!normalized) return 0;\n return normalized.split(\"/\").length - 1;\n}\n\nfunction resolvePrefix(\n ...sources: Array<{ parent?: unknown; newFolder?: unknown } | undefined>\n): { parent: string | undefined; newFolder: string | undefined } {\n let parent: string | undefined;\n let newFolder: string | undefined;\n for (const source of sources) {\n if (parent === undefined && typeof source?.parent === \"string\") parent = source.parent;\n if (newFolder === undefined && typeof source?.newFolder === \"string\") newFolder = source.newFolder;\n }\n return { parent, newFolder };\n}\n\nfunction isLockedDoc(doc: { slugLocked?: unknown; publishedSlug?: unknown } | undefined): boolean {\n return Boolean(doc?.slugLocked || doc?.publishedSlug);\n}\n\nfunction isUnlocking(data: { slugUnlock?: unknown } | undefined): boolean {\n return Boolean(data?.slugUnlock);\n}\n\nasync function slugProblem(\n slug: string,\n { collection, id, isReserved, pageKey, req }: SlugCheckArgs,\n): Promise<string | undefined> {\n if (!slug) return undefined;\n\n if (slug === ROOT_PAGE_SLUG && !isRootPageKey(pageKey)) {\n return \"That address is reserved for the home page. Please choose a different address.\";\n }\n\n if (isReserved(slug)) {\n return `\"/${slug}\" is a built-in page on this site, so a page here cannot use it. Please choose a different address.`;\n }\n\n if (typeof req?.payload?.find !== \"function\") return undefined;\n\n const where: Where = { slug: { equals: slug } };\n if (id !== undefined) {\n where.id = { not_equals: id };\n }\n\n const query = {\n collection,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n where,\n };\n\n const live = await req.payload.find(query);\n const taken =\n live.docs.length > 0 || (await req.payload.find({ ...query, draft: true })).docs.length > 0;\n\n return taken ? `Another page is already using \"/${slug}\". Please choose a different address.` : undefined;\n}\n\nconst slugUpdateAccess =\n (collection: CollectionSlug): FieldAccess =>\n async ({ doc, id, req, siblingData }) => {\n if (isRootPageKey(pageKeyFrom(doc, siblingData))) return false;\n if (isUnlocking(siblingData)) return true;\n if (isLockedDoc(doc)) return false;\n if (id === undefined || typeof req?.payload?.findByID !== \"function\") return true;\n try {\n const published = await req.payload.findByID({\n collection,\n id,\n depth: 0,\n draft: false,\n overrideAccess: true,\n req,\n });\n return published?._status !== \"published\";\n } catch {\n return true;\n }\n };\n\n/**\n * Locks the slug on first publish and remembers the live path so a later\n * change can write a redirect. Unlock is a one-save flag and is cleared here.\n */\nexport const lockSlugOnPublish: CollectionBeforeChangeHook = ({ data }) => {\n if (!data) return data;\n data.slugUnlock = false;\n if (data._status === \"published\") {\n data.slugLocked = true;\n if (typeof data.slug === \"string\") data.publishedSlug = data.slug;\n }\n return data;\n};\n\nfunction hiddenCheckbox(name: string, label: string): CheckboxField {\n return {\n name,\n type: \"checkbox\",\n label,\n defaultValue: false,\n admin: { hidden: true },\n };\n}\n\n/**\n * The path a document is published at, normalised on the way in. Unique\n * across the collection. Follows `title` until first publish, then locks.\n * `validate` is the message under the field; `beforeChange` is the enforcement\n * on a draft save, where Payload skips field validation.\n */\nexport function slugField({ collection, isReserved, folderRoots = [] }: SlugFieldOptions): Field[] {\n const validate: TextFieldSingleValidation = async (value, options) => {\n try {\n const builtIn = await validations.text(value, options);\n if (builtIn !== true) return builtIn;\n } catch {\n // form-state without a request still runs the reserved / duplicate checks\n }\n\n const problem = await slugProblem(typeof value === \"string\" ? value : \"\", {\n collection,\n id: options.id,\n isReserved,\n pageKey: pageKeyFrom(options.data, options.siblingData),\n req: options.req,\n });\n return problem ?? true;\n };\n\n const slug: TextField = {\n name: \"slug\",\n type: \"text\",\n required: true,\n unique: true,\n access: { update: slugUpdateAccess(collection) },\n admin: {\n description: 'Path under the site root, no leading slash: \"about-us\" or \"patients/stories\".',\n components: { Field: SLUG_FIELD, Cell: PAGE_SLUG_CELL },\n custom: { folderRoots },\n },\n hooks: {\n beforeValidate: [\n ({ data, originalDoc, siblingData, value }) => {\n if (isRootPageKey(pageKeyFrom(data, siblingData, originalDoc))) return ROOT_PAGE_SLUG;\n const title = typeof data?.title === \"string\" ? data.title : \"\";\n const { parent, newFolder } = resolvePrefix(siblingData, data, originalDoc);\n if (!isLockedDoc(originalDoc) && !isUnlocking(data) && !isUnlocking(siblingData) && title) {\n return composeSlug(parent, title, newFolder);\n }\n if ((isUnlocking(data) || isUnlocking(siblingData)) && (parent !== undefined || newFolder)) {\n const leaf =\n typeof value === \"string\" && value ? slugLeaf(value) : title ? slugifySegment(title) : \"\";\n return composeSlug(parent, leaf, newFolder);\n }\n return typeof value === \"string\" ? normalizeSlug(value) : value;\n },\n ],\n beforeChange: [\n async ({ data, originalDoc, req, siblingData, value }) => {\n if (isRootPageKey(pageKeyFrom(data, siblingData, originalDoc))) return ROOT_PAGE_SLUG;\n if (typeof value !== \"string\") return value;\n\n const problem = await slugProblem(value, {\n collection,\n id: originalDoc?.id ?? data?.id,\n isReserved,\n pageKey: pageKeyFrom(data, siblingData, originalDoc),\n req,\n });\n if (problem) {\n throw new ValidationError(\n { collection, errors: [{ message: problem, path: \"slug\" }], req },\n req?.t,\n );\n }\n return value;\n },\n ],\n },\n validate,\n };\n\n const parent: TextField = {\n name: \"parent\",\n type: \"text\",\n defaultValue: \"\",\n access: { update: slugUpdateAccess(collection) },\n admin: { hidden: true },\n hooks: {\n beforeValidate: [\n ({ data, originalDoc, siblingData, value }) => {\n const { newFolder } = resolvePrefix(siblingData, data, originalDoc);\n if (value === NEW_FOLDER_PARENT) return parentPrefix(NEW_FOLDER_PARENT, newFolder);\n return typeof value === \"string\" ? normalizeSlug(value) : \"\";\n },\n ],\n },\n validate: async (value, options) => {\n const { newFolder } = resolvePrefix(options.siblingData, options.data);\n if (value !== NEW_FOLDER_PARENT && !newFolder) return true;\n\n const prefix = parentPrefix(NEW_FOLDER_PARENT, newFolder);\n if (!prefix) return true;\n\n const taken = await existingParents(prefix, {\n collection,\n folderRoots,\n id: options.id,\n isReserved,\n req: options.req,\n });\n return taken ? EXISTING_PARENT_MESSAGE : true;\n },\n };\n\n const newFolder: TextField = {\n name: \"newFolder\",\n type: \"text\",\n admin: { hidden: true },\n access: { update: slugUpdateAccess(collection) },\n };\n\n return [\n parent,\n newFolder,\n slug,\n hiddenCheckbox(\"slugLocked\", \"Slug locked\"),\n hiddenCheckbox(\"slugUnlock\", \"Unlock slug\"),\n {\n name: \"publishedSlug\",\n type: \"text\",\n label: \"Published slug\",\n admin: { hidden: true },\n },\n ];\n}\n","import {\n APIError,\n type Access,\n type CollectionBeforeChangeHook,\n type CollectionBeforeDeleteHook,\n type Payload,\n type Where,\n} from \"payload\";\n\nimport {\n isRequiredPageKey,\n isRootPageKey,\n REQUIRED_PAGE_DELETE_MESSAGE,\n REQUIRED_PAGE_UNPUBLISH_MESSAGE,\n ROOT_PAGE_KEY,\n ROOT_PAGE_SLUG,\n} from \"./root-page-key\";\n\nfunction isDraftVersionWrite(\n req: { query?: Record<string, unknown> } | undefined,\n): boolean {\n const draft = req?.query?.draft;\n return draft === \"true\" || draft === true;\n}\n\n/**\n * Keeps a required key once set, and pins the home row to `/`: empty parent,\n * the internal slug, locked, with no unlock.\n */\nexport const keepRequiredPage: CollectionBeforeChangeHook = ({\n data,\n originalDoc,\n operation,\n}) => {\n if (!data) return data;\n if (\n operation === \"update\" &&\n typeof originalDoc?.pageKey === \"string\" &&\n originalDoc.pageKey\n ) {\n data.pageKey = originalDoc.pageKey;\n }\n if (isRootPageKey(data.pageKey) || isRootPageKey(originalDoc?.pageKey)) {\n data.pageKey = ROOT_PAGE_KEY;\n data.slug = ROOT_PAGE_SLUG;\n data.parent = \"\";\n data.slugLocked = true;\n data.slugUnlock = false;\n }\n return data;\n};\n\nexport function refuseRequiredUnpublish(\n requiredKeys: readonly string[],\n): CollectionBeforeChangeHook {\n return ({ data, originalDoc, req }) => {\n if (!data) return data;\n if (!isRequiredPageKey(originalDoc?.pageKey, requiredKeys)) return data;\n if (data._status !== \"draft\") return data;\n if (originalDoc?._status !== \"published\") return data;\n if (isDraftVersionWrite(req)) return data;\n throw new APIError(REQUIRED_PAGE_UNPUBLISH_MESSAGE, 400);\n };\n}\n\nexport function refuseRequiredPageDelete(\n requiredKeys: readonly string[],\n): CollectionBeforeDeleteHook {\n return async ({ id, req }) => {\n const doc = await req.payload.findByID({\n collection: \"pages\",\n id,\n depth: 0,\n overrideAccess: true,\n });\n if (isRequiredPageKey(doc.pageKey, requiredKeys)) {\n throw new APIError(REQUIRED_PAGE_DELETE_MESSAGE, 400);\n }\n };\n}\n\nexport function withRequiredPageDeleteLock(\n base: Access | undefined,\n requiredKeys: readonly string[],\n): Access {\n return async (args) => {\n const allowed =\n typeof base === \"function\" ? await base(args) : (base ?? true);\n if (allowed === false) return false;\n if (args.id != null) {\n try {\n const doc = await args.req.payload.findByID({\n collection: \"pages\",\n id: args.id,\n depth: 0,\n overrideAccess: true,\n });\n if (isRequiredPageKey(doc.pageKey, requiredKeys)) return false;\n } catch {\n // Missing id: let the delete operation report that itself.\n }\n }\n const keyedOut: Where = {\n or: [\n { pageKey: { exists: false } },\n { pageKey: { not_in: [...requiredKeys] } },\n ],\n };\n if (allowed === true) return keyedOut;\n return { and: [allowed, keyedOut] };\n };\n}\n\n/**\n * Creates the home page when it is missing. Safe to call from `onInit`.\n * Identity fields win over `data`: `pageKey` is `/`, the stored slug is the\n * internal token, and the row is published. Pass the hero and a section —\n * publish still requires both. The document title defaults to \"Home\"; that\n * word is the title, not the identifier.\n */\nexport async function ensureRootPage(\n payload: Payload,\n data: Record<string, unknown> = {},\n): Promise<unknown> {\n const found = await payload.find({\n collection: \"pages\",\n where: { pageKey: { equals: ROOT_PAGE_KEY } },\n overrideAccess: true,\n depth: 0,\n limit: 1,\n pagination: false,\n });\n if (found.docs[0]) return found.docs[0];\n\n return payload.create({\n collection: \"pages\",\n overrideAccess: true,\n data: {\n title: \"Home\",\n ...data,\n slug: ROOT_PAGE_SLUG,\n parent: \"\",\n pageKey: ROOT_PAGE_KEY,\n slugLocked: true,\n slugUnlock: false,\n _status: \"published\",\n },\n });\n}\n","import type { Access, Block, CollectionBeforeValidateHook, CollectionConfig } from \"payload\";\nimport { ValidationError } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { lockSlugOnPublish, PAGE_TITLE_CELL, slugField } from \"../fields/slug\";\nimport { authenticatedOrPublished, canPublish, isAdmin, isAuthenticated } from \"../roles/access\";\nimport {\n keepRequiredPage,\n refuseRequiredPageDelete,\n refuseRequiredUnpublish,\n withRequiredPageDeleteLock,\n} from \"./root-page\";\nimport {\n isRootPageKey,\n REQUIRED_PAGE_CELL,\n REQUIRED_PAGE_FIELD,\n requiredPageKeys,\n ROOT_PAGE_KEY,\n} from \"./root-page-key\";\n\n/** Standing copy on the Layout field — same job as the hero description. */\nexport const LAYOUT_DESCRIPTION =\n \"Every page needs at least one section below the hero. A page cannot be published without one.\";\n\n/** Field error when Publish is clicked with an empty body. */\nexport const LAYOUT_REQUIRED_MESSAGE =\n \"Add at least one section. A page cannot be published without one.\";\n\n/**\n * Toast label for that error. Payload's envelope is always\n * \"The following field is invalid: {label}\", so the label has to name the fix.\n */\nexport const LAYOUT_REQUIRED_LABEL = \"Layout — add a section\";\n\nfunction layoutRows(\n data: { layout?: unknown } | undefined,\n originalDoc: { layout?: unknown } | undefined,\n): unknown[] {\n if (data && \"layout\" in data && data.layout !== undefined) {\n return Array.isArray(data.layout) ? data.layout : [];\n }\n return Array.isArray(originalDoc?.layout) ? originalDoc.layout : [];\n}\n\n/**\n * Drafts may be empty. Publish with no section is refused here so the toast\n * names the fix — Payload's built-in minRows toast only says \"Content → Layout\".\n */\nexport const requireLayoutOnPublish: CollectionBeforeValidateHook = ({ collection, data, originalDoc, req }) => {\n if (!data || data._status !== \"published\") return data;\n if (layoutRows(data, originalDoc as { layout?: unknown } | undefined).length >= 1) return data;\n throw new ValidationError(\n {\n collection: typeof collection?.slug === \"string\" ? collection.slug : \"pages\",\n errors: [{ label: LAYOUT_REQUIRED_LABEL, message: LAYOUT_REQUIRED_MESSAGE, path: \"layout\" }],\n req,\n },\n req?.t,\n );\n};\n\n/**\n * Content to create or save a draft; Publish to publish or edit a live\n * page. Without Publish, update is constrained to `_status: draft`.\n */\nconst pagesUpdate: Access = async (args) => {\n const canEdit = await Promise.resolve(canUseFeature(\"content\")(args));\n if (!canEdit) return false;\n if (await Promise.resolve(canPublish(args))) return true;\n return { _status: { equals: \"draft\" } };\n};\n\nexport interface PagesOptions {\n /**\n * What a page may open with. One row, so this is the site's hero variants,\n * not a list a page picks several from.\n */\n heroBlocks: Block[];\n /** The sections a page body can be built out of. */\n layoutBlocks: Block[];\n /**\n * True when a slug is not the CMS's to hand out — a path the app already\n * serves from code, or one the framework reserves.\n */\n isReservedSlug: (slug: string) => boolean;\n /**\n * Public path of a page from its stored slug — the site's own route helper.\n * Drives the page preview overlay's iframe.\n */\n previewPath: (slug: string) => string;\n /**\n * Component path for Payload's native Preview button, as a key into the\n * site's committed `importMap.js`. Omit it for Payload's own button.\n */\n previewButton?: string;\n /**\n * Standing folder roots (`patients`, `providers`). Shown on Parent even\n * when no CMS page lives under them. Often the same paths `isReservedSlug`\n * refuses as leaf pages.\n */\n folderRoots?: string[];\n /**\n * Other pages that cannot be deleted or unpublished, besides the home page.\n * Keys, not paths (`find-a-doctor`). Home is always required and is not\n * listed here: its key is `/`.\n */\n requiredKeys?: readonly string[];\n}\n\n/**\n * CMS-managed pages: one required hero, then a reorderable body of sections.\n * The CMS owns copy and the order of sections; what a section looks like is\n * code-owned, which is why the blocks are an argument.\n */\nexport function createPages({\n folderRoots,\n heroBlocks,\n isReservedSlug,\n layoutBlocks,\n previewPath,\n previewButton,\n requiredKeys: extraRequiredKeys,\n}: PagesOptions): CollectionConfig {\n const [defaultHero] = heroBlocks;\n if (!defaultHero) throw new Error(\"createPages needs at least one hero block\");\n const keys = requiredPageKeys(extraRequiredKeys);\n\n return {\n slug: \"pages\",\n defaultSort: \"slug\",\n admin: {\n useAsTitle: \"title\",\n group: \"Content\",\n defaultColumns: [\"title\", \"pageKey\", \"slug\", \"_status\", \"updatedAt\"],\n hidden: hideUnlessFeature(\"content\") as (args: { user: unknown }) => boolean,\n // Home is previewed as `/`. An empty slug is still \"no address yet\".\n preview: (doc) =>\n previewPath(isRootPageKey(doc?.pageKey) ? ROOT_PAGE_KEY : typeof doc?.slug === \"string\" ? doc.slug : \"\"),\n ...(previewButton ? { components: { edit: { PreviewButton: previewButton } } } : {}),\n },\n access: {\n read: authenticatedOrPublished,\n readVersions: isAuthenticated,\n create: canUseFeature(\"content\"),\n update: pagesUpdate,\n delete: withRequiredPageDeleteLock(isAdmin, keys),\n },\n versions: {\n drafts: { autosave: { interval: 375 } },\n maxPerDoc: 50,\n },\n hooks: {\n beforeValidate: [requireLayoutOnPublish],\n beforeChange: [keepRequiredPage, lockSlugOnPublish, refuseRequiredUnpublish(keys)],\n beforeDelete: [refuseRequiredPageDelete(keys)],\n },\n fields: [\n {\n name: \"title\",\n type: \"text\",\n required: true,\n admin: { components: { Cell: PAGE_TITLE_CELL } },\n },\n {\n name: \"pageKey\",\n type: \"text\",\n label: \"Required\",\n unique: true,\n index: true,\n access: {\n create: () => false,\n update: () => false,\n },\n admin: {\n disableListFilter: true,\n custom: { listAlign: \"center\" },\n components: { Field: REQUIRED_PAGE_FIELD, Cell: REQUIRED_PAGE_CELL },\n },\n },\n ...slugField({ collection: \"pages\", folderRoots, isReserved: isReservedSlug }),\n {\n name: \"hero\",\n type: \"blocks\",\n required: true,\n minRows: 1,\n maxRows: 1,\n blocks: heroBlocks,\n defaultValue: [{ blockType: defaultHero.slug }],\n admin: {\n description: \"Every page opens with one hero. A page cannot be published without one.\",\n },\n },\n {\n name: \"layout\",\n type: \"blocks\",\n required: true,\n minRows: 1,\n blocks: layoutBlocks,\n labels: { singular: \"Section\", plural: \"Sections\" },\n admin: {\n description: LAYOUT_DESCRIPTION,\n },\n },\n ],\n };\n}\n","import type {\n CollectionConfig,\n PayloadRequest,\n SelectFieldManyValidation,\n TextField,\n TextFieldSingleValidation,\n Where,\n} from \"payload\";\nimport { APIError } from \"payload\";\nimport { select, text } from \"payload/shared\";\n\nimport { allowedFeaturesForUser, canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { getRolesMatrix, isAdmin, isAdminOrSelf, isPrivilegedRole } from \"../roles/access\";\nimport { ROLES_FIELD } from \"../roles/fields\";\nimport { normalizeStoredRoles, roleSelectOptions, seedRoleRows } from \"../roles/matrix\";\nimport type { RoleExtra, RoleRow } from \"../roles/types\";\n\nconst nameValidate: TextFieldSingleValidation = (value, options) => {\n if (options.operation === \"update\" && value === \"\" && options.previousValue === \"\") return true;\n return text(value, options);\n};\n\nfunction nameField(name: \"firstName\" | \"lastName\"): TextField {\n return { name, type: \"text\", required: true, validate: nameValidate };\n}\n\n/** Refuses the save that would remove Users from the only privileged user. */\nexport const LAST_ADMIN_DEMOTE_MESSAGE = \"Make another user an admin before removing it from this one.\";\n/** Refuses the delete that would remove the only privileged user. */\nexport const LAST_ADMIN_DELETE_MESSAGE = \"Make another user an admin before deleting this one.\";\n\ninterface TransactionalAdapter {\n execute?: (args: { db?: unknown; raw?: string }) => Promise<unknown>;\n sessions?: Record<string, { db: unknown } | undefined>;\n}\n\nconst LAST_ADMIN_LOCK = \"select pg_advisory_xact_lock(hashtext('users:last-admin'))\";\n\nasync function lockLastAdminDecision(req: PayloadRequest): Promise<void> {\n const { execute, sessions } = req.payload.db as unknown as TransactionalAdapter;\n const id = req.transactionID;\n const session = typeof id === \"string\" || typeof id === \"number\" ? sessions?.[id] : undefined;\n if (!session || typeof execute !== \"function\") return;\n await execute({ db: session.db, raw: LAST_ADMIN_LOCK });\n}\n\nfunction privilegedRoles(matrix: readonly RoleRow[]): string[] {\n return matrix.filter((row) => isPrivilegedRole(row.role, matrix)).map((row) => row.role);\n}\n\nfunction holdsPrivilegedRole(roles: unknown, matrix: readonly RoleRow[]): boolean {\n return Array.isArray(roles) && roles.some((role) => isPrivilegedRole(role, matrix));\n}\n\nfunction privilegedWhere(matrix: readonly RoleRow[]): Where {\n const roles = privilegedRoles(matrix);\n if (roles.length === 0) return { id: { equals: \"__none__\" } };\n return { or: roles.map((role) => ({ roles: { contains: role } })) };\n}\n\nasync function adminCount(req: PayloadRequest, excluding?: number | string): Promise<number> {\n await lockLastAdminDecision(req);\n const matrix = await getRolesMatrix(req);\n const holdsPrivileged = privilegedWhere(matrix);\n const { totalDocs } = await req.payload.count({\n collection: \"users\",\n overrideAccess: true,\n req,\n where:\n excluding === undefined\n ? holdsPrivileged\n : { and: [holdsPrivileged, { id: { not_equals: excluding } }] },\n });\n return totalDocs;\n}\n\nfunction rolesValidate(extras: readonly RoleExtra[]): SelectFieldManyValidation {\n return async (value, options) => {\n const matrix = await getRolesMatrix(options.req, extras);\n const builtIn = select(value, { ...options, options: roleSelectOptions(matrix) });\n if (builtIn !== true) return builtIn;\n if (options.operation !== \"update\" || options.id === undefined) return true;\n if (holdsPrivilegedRole(value, matrix) || !holdsPrivilegedRole(options.previousValue, matrix)) {\n return true;\n }\n return (await adminCount(options.req, options.id)) > 0 ? true : LAST_ADMIN_DEMOTE_MESSAGE;\n };\n}\n\nexport interface UsersOptions {\n /**\n * Whether the auth cookie is marked Secure. Passed in rather than read from\n * the environment here: which env var means \"served over HTTPS\" is the\n * host's business, not the CMS's.\n */\n secureCookies: boolean;\n /**\n * Component path for the roles field, as a key into the site's committed\n * `importMap.js`. Defaults to the package checklist. A value nothing\n * resolves renders the field as nothing.\n */\n rolesField?: string;\n /**\n * Same extras passed to `createRoles`. Offered on Users when the Global\n * is empty; a saved Global (including Admin-added rows) wins.\n */\n extras?: readonly RoleExtra[];\n}\n\nexport function createUsers({ secureCookies, rolesField, extras = [] }: UsersOptions): CollectionConfig {\n const fallback = seedRoleRows(extras);\n return {\n slug: \"users\",\n auth: {\n maxLoginAttempts: 5,\n lockTime: 10 * 60 * 1000,\n tokenExpiration: 2 * 60 * 60,\n cookies: {\n sameSite: \"Lax\",\n secure: secureCookies,\n },\n },\n admin: {\n group: \"Settings\",\n useAsTitle: \"email\",\n defaultColumns: [\"email\", \"firstName\", \"lastName\", \"roles\"],\n hidden: hideUnlessFeature(\"users\") as (args: { user: unknown }) => boolean,\n },\n access: {\n create: isAdmin,\n delete: isAdmin,\n unlock: isAdmin,\n read: async (args) => {\n if (await Promise.resolve(canUseFeature(\"users\")(args))) return true;\n return isAdminOrSelf(args);\n },\n update: isAdminOrSelf,\n },\n hooks: {\n beforeDelete: [\n async ({ id, req }) => {\n const doomed = await req.payload.findByID({\n collection: \"users\",\n id,\n depth: 0,\n disableErrors: true,\n overrideAccess: true,\n req,\n });\n const matrix = await getRolesMatrix(req, extras);\n if (!isAdmin(doomed, matrix) || (await adminCount(req, id)) > 0) return;\n throw new APIError(LAST_ADMIN_DELETE_MESSAGE, 400);\n },\n ],\n afterOperation: [\n async (arg) => {\n const { operation, req } = arg;\n const touchesRoles =\n (operation === \"update\" || operation === \"updateByID\") &&\n arg.args.data?.roles !== undefined;\n const deletes = operation === \"delete\" || operation === \"deleteByID\";\n if ((touchesRoles || deletes) && (await adminCount(req)) === 0) {\n throw new APIError(deletes ? LAST_ADMIN_DELETE_MESSAGE : LAST_ADMIN_DEMOTE_MESSAGE, 400);\n }\n return arg.result;\n },\n ],\n },\n fields: [\n {\n type: \"row\",\n fields: [nameField(\"firstName\"), nameField(\"lastName\")],\n },\n {\n name: \"roles\",\n type: \"select\",\n hasMany: true,\n required: true,\n saveToJWT: true,\n // Seed plus site extras. filterOptions replaces this with the saved\n // Global (labels and Admin-added slugs) when that row is readable.\n options: roleSelectOptions(fallback),\n admin: {\n components: { Field: rolesField ?? ROLES_FIELD },\n description: \"One person can hold several, e.g. Author + Designer.\",\n },\n access: {\n update: isAdmin,\n },\n validate: rolesValidate(extras),\n hooks: {\n beforeValidate: [\n async ({ value, req }) => {\n if (!Array.isArray(value)) return value;\n return normalizeStoredRoles(value, await getRolesMatrix(req, extras));\n },\n ],\n },\n },\n {\n name: \"allowedFeatures\",\n type: \"json\",\n admin: { hidden: true, readOnly: true },\n access: { update: () => false },\n saveToJWT: true,\n hooks: {\n afterRead: [\n async ({ siblingData, data, req }) =>\n allowedFeaturesForUser(\n {\n id: (siblingData?.id ?? data?.id) as string | number | undefined,\n roles: (siblingData?.roles ?? data?.roles) as readonly string[] | undefined,\n },\n req ?? {},\n ),\n ],\n },\n },\n ],\n };\n}\n","/** The name the editor just chose, or the stored filename on an existing row. */\nexport function filenameFromUpload(file: unknown, filename: unknown): string {\n if (typeof File !== \"undefined\" && file instanceof File) return file.name;\n if (typeof filename === \"string\") return filename;\n return \"\";\n}\n\n/** Alt text from an upload filename: drop the extension, hyphenate the rest. */\nexport function altFromFilename(filename: unknown): string {\n if (typeof filename !== \"string\") return \"\";\n return filename\n .trim()\n .replace(/\\.[a-z0-9]{1,5}$/i, \"\")\n .replace(/[_\\s]+/g, \"-\");\n}\n\n/**\n * Fill while Alt is empty or still the last auto value. Stop once the editor\n * types something else.\n */\nexport function shouldFillMediaAlt(existing: unknown, generated: string, lastAuto: string): boolean {\n if (!generated) return false;\n const current = typeof existing === \"string\" ? existing.trim() : \"\";\n if (current === generated) return false;\n if (!current) return true;\n return current === lastAuto;\n}\n\nexport function fillBlankAltFromFilename<T extends { alt?: unknown; filename?: unknown }>(data: T): T {\n if (data.alt != null && data.alt !== \"\") return data;\n const generated = altFromFilename(data.filename);\n if (generated) data.alt = generated;\n return data;\n}\n","/** Import-map strings and route paths shared by createMedia and admin views. */\nexport const MEDIA_LIST = \"@bison-lab/payload-core/admin#MediaListView\";\nexport const MEDIA_ALT_AUTOFILL = \"@bison-lab/payload-core/admin#MediaAltAutofill\";\nexport const MEDIA_IN_USE_PATH = \"/in-use\";\n","/**\n * Where a media id is referenced. Walks live field config — upload /\n * relationship paths whose relationTo includes media — plus Lexical\n * `upload` nodes. Does not guess from key names.\n */\n\nexport type MediaInUseScopes = true | { collections?: string[]; globals?: string[] };\n\nexport interface MediaInUsePayload {\n find: (args: {\n collection: string;\n draft?: boolean;\n depth?: number;\n limit?: number;\n page?: number;\n overrideAccess?: boolean;\n where?: Record<string, unknown>;\n }) => Promise<{ docs: Record<string, unknown>[]; totalPages?: number }>;\n findGlobal: (args: {\n slug: string;\n draft?: boolean;\n depth?: number;\n overrideAccess?: boolean;\n }) => Promise<Record<string, unknown> | null | undefined>;\n collections?: Record<string, { config?: CollectionShape }>;\n globals?: { config?: GlobalShape[] };\n config?: {\n collections?: CollectionShape[];\n globals?: GlobalShape[];\n };\n}\n\ntype CollectionShape = {\n slug?: string;\n fields?: FieldLike[];\n versions?: unknown;\n};\n\ntype GlobalShape = {\n slug?: string;\n fields?: FieldLike[];\n};\n\ntype FieldLike = {\n type?: string;\n name?: string;\n relationTo?: string | string[];\n fields?: FieldLike[];\n tabs?: { fields?: FieldLike[] }[];\n blocks?: { slug?: string; fields?: FieldLike[] }[];\n};\n\nconst MEDIA = \"media\";\n\nexport async function findMediaInUse(\n payload: MediaInUsePayload,\n scopes: MediaInUseScopes,\n): Promise<Set<string>> {\n const { collections, globals } = resolveScopes(payload, scopes);\n const ids = new Set<string>();\n const errors: string[] = [];\n for (const slug of collections) {\n const config = collectionOf(payload, slug);\n const publishedOnly = collectionHasDrafts(config);\n try {\n for await (const doc of eachCollectionDoc(payload, slug, publishedOnly)) {\n collectFromFields(config?.fields ?? [], doc, ids);\n }\n } catch {\n errors.push(slug);\n }\n }\n for (const slug of globals) {\n const config = globalOf(payload, slug);\n try {\n const doc = await readGlobal(payload, slug);\n if (!doc) continue;\n collectFromFields(config?.fields ?? [], doc, ids);\n } catch {\n errors.push(slug);\n }\n }\n if (errors.length > 0) {\n throw new Error(`Media in-use scan failed for: ${errors.join(\", \")}`);\n }\n return ids;\n}\n\nexport function resolveScopes(\n payload: MediaInUsePayload,\n scopes: MediaInUseScopes,\n): { collections: string[]; globals: string[] } {\n if (scopes === true) {\n return {\n collections: slugsOf(payload.config?.collections ?? payload.collections).filter(\n (slug) => !slug.startsWith(\"payload-\") && slug !== MEDIA,\n ),\n globals: slugsOf(payload.config?.globals ?? payload.globals?.config),\n };\n }\n return {\n collections: (scopes.collections ?? []).filter((slug) => slug !== MEDIA),\n globals: scopes.globals ?? [],\n };\n}\n\nfunction collectionOf(payload: MediaInUsePayload, slug: string): CollectionShape | undefined {\n const live = payload.collections?.[slug]?.config;\n if (live) return live;\n return payload.config?.collections?.find((entry) => entry.slug === slug);\n}\n\nfunction globalOf(payload: MediaInUsePayload, slug: string): GlobalShape | undefined {\n return (\n payload.config?.globals?.find((entry) => entry.slug === slug) ??\n payload.globals?.config?.find((entry) => entry.slug === slug)\n );\n}\n\nfunction collectionHasDrafts(config: CollectionShape | undefined): boolean {\n const versions = config?.versions;\n if (!versions || typeof versions !== \"object\") return false;\n return Boolean((versions as { drafts?: unknown }).drafts);\n}\n\nfunction slugsOf(value: { slug?: string }[] | Record<string, unknown> | undefined): string[] {\n if (Array.isArray(value)) {\n return value.map((item) => item?.slug).filter((slug): slug is string => Boolean(slug));\n }\n if (value && typeof value === \"object\") return Object.keys(value);\n return [];\n}\n\nasync function readGlobal(\n payload: MediaInUsePayload,\n slug: string,\n): Promise<Record<string, unknown> | null | undefined> {\n return payload.findGlobal({ slug, depth: 0, overrideAccess: true });\n}\n\nasync function* eachCollectionDoc(\n payload: MediaInUsePayload,\n collection: string,\n publishedOnly: boolean,\n): AsyncGenerator<Record<string, unknown>> {\n let page = 1;\n for (;;) {\n let result: { docs: Record<string, unknown>[]; totalPages?: number };\n result = await payload.find({\n collection,\n depth: 0,\n limit: 100,\n page,\n overrideAccess: true,\n ...(publishedOnly ? { where: { _status: { equals: \"published\" } } } : {}),\n });\n for (const doc of result.docs) yield doc;\n const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);\n if (page >= totalPages || result.docs.length === 0) break;\n page += 1;\n }\n}\n\nfunction collectFromFields(fields: FieldLike[], doc: unknown, ids: Set<string>): void {\n for (const field of fields) {\n if (!field) continue;\n if (field.type === \"tabs\") {\n for (const tab of field.tabs ?? []) collectFromFields(tab.fields ?? [], doc, ids);\n continue;\n }\n if (field.type === \"row\" || field.type === \"collapsible\") {\n collectFromFields(field.fields ?? [], doc, ids);\n continue;\n }\n if (field.type === \"group\") {\n collectFromFields(field.fields ?? [], field.name ? get(doc, field.name) : doc, ids);\n continue;\n }\n if (field.type === \"array\" && field.name) {\n const rows = get(doc, field.name);\n if (Array.isArray(rows)) {\n for (const row of rows) collectFromFields(field.fields ?? [], row, ids);\n }\n continue;\n }\n if (field.type === \"blocks\" && field.name) {\n const rows = get(doc, field.name);\n if (Array.isArray(rows)) {\n for (const row of rows) {\n if (!row || typeof row !== \"object\") continue;\n const type = (row as { blockType?: string }).blockType;\n const block = field.blocks?.find((entry) => entry.slug === type);\n if (block) collectFromFields(block.fields ?? [], row, ids);\n }\n }\n continue;\n }\n if (\n (field.type === \"upload\" || field.type === \"relationship\") &&\n field.name &&\n relationToMedia(field.relationTo)\n ) {\n collectMediaIds(get(doc, field.name), ids);\n continue;\n }\n if (field.type === \"richText\" && field.name) {\n collectLexicalUploads(get(doc, field.name), ids);\n }\n }\n}\n\nfunction relationToMedia(relationTo: string | string[] | undefined): boolean {\n if (relationTo === MEDIA) return true;\n return Array.isArray(relationTo) && relationTo.includes(MEDIA);\n}\n\nfunction collectMediaIds(value: unknown, ids: Set<string>): void {\n if (value == null) return;\n if (typeof value === \"number\" || typeof value === \"string\") {\n ids.add(String(value));\n return;\n }\n if (Array.isArray(value)) {\n for (const item of value) collectMediaIds(item, ids);\n return;\n }\n if (typeof value === \"object\") {\n const obj = value as { relationTo?: string; value?: unknown; id?: unknown };\n if (obj.relationTo && obj.relationTo !== MEDIA) return;\n collectMediaIds(obj.value ?? obj.id, ids);\n }\n}\n\nfunction collectLexicalUploads(node: unknown, ids: Set<string>): void {\n if (!node || typeof node !== \"object\") return;\n const obj = node as {\n type?: string;\n relationTo?: string;\n value?: unknown;\n children?: unknown[];\n root?: unknown;\n };\n if (obj.type === \"upload\" && (obj.relationTo == null || obj.relationTo === MEDIA)) {\n collectMediaIds(obj.value, ids);\n }\n if (obj.root) collectLexicalUploads(obj.root, ids);\n if (Array.isArray(obj.children)) {\n for (const child of obj.children) collectLexicalUploads(child, ids);\n }\n}\n\nfunction get(doc: unknown, name: string): unknown {\n if (!doc || typeof doc !== \"object\") return undefined;\n return (doc as Record<string, unknown>)[name];\n}\n","import type { CollectionConfig, Endpoint, ImageSize, PayloadRequest } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { isAdmin } from \"../roles/access\";\nimport { SHARE_IMAGE_SIZE } from \"../seo/share-image\";\nimport { altFromFilename, fillBlankAltFromFilename } from \"./media-alt\";\nimport { MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST } from \"./media-constants\";\nimport { findMediaInUse, type MediaInUsePayload, type MediaInUseScopes } from \"./media-in-use\";\n\nexport { altFromFilename, fillBlankAltFromFilename } from \"./media-alt\";\nexport { MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST } from \"./media-constants\";\n\nexport type MediaInUseOption = MediaInUseScopes | false;\n\nexport interface MediaOptions {\n /** Where uploads land, relative to the app root. */\n staticDir?: string;\n mimeTypes?: string[];\n /**\n * Renditions sharp cuts on upload, each served at its own URL under\n * `sizes.<name>` on the document. Omit to get the share card (1200×630)\n * with list/filter/group hides. A site that passes its own list owns\n * those flags on each size.\n */\n imageSizes?: ImageSize[];\n /**\n * `true` walks every registered collection and global at request time\n * (Payload internals and media itself skipped). A slug list narrows.\n * `false` hides the column and skips the scan.\n */\n inUse?: MediaInUseOption;\n}\n\nconst DEFAULT_RESIZE = {\n width: 2560,\n height: 2560,\n fit: \"inside\" as const,\n withoutEnlargement: true,\n};\n\nfunction defaultShareSizes(): ImageSize[] {\n return [\n {\n ...SHARE_IMAGE_SIZE,\n admin: {\n disableGroupBy: true,\n disableListColumn: true,\n disableListFilter: true,\n },\n },\n ];\n}\n\n/**\n * Client uploads write the original before Sharp resizes `req.file`.\n * Drop the flag so the resized buffer overwrites that object. Disk\n * uploads have no flag; this is a no-op.\n */\nexport function replaceClientOriginalWithResizedFile(req: { file?: object }): void {\n if (req.file && \"clientUploadContext\" in req.file) {\n delete (req.file as { clientUploadContext?: unknown }).clientUploadContext;\n }\n}\n\n/**\n * Uploads, readable by anyone: the public site serves these files. Writing is\n * an editorial action, deleting is not — removing an asset a live page\n * references breaks that page.\n */\nexport function createMedia({\n staticDir = \"media\",\n mimeTypes = [\"image/*\"],\n imageSizes,\n inUse = true,\n}: MediaOptions = {}): CollectionConfig {\n return {\n slug: \"media\",\n admin: {\n hidden: hideUnlessFeature(\"media\") as (args: { user: unknown }) => boolean,\n useAsTitle: \"filename\",\n defaultColumns: [\"filename\", \"alt\", \"updatedAt\", \"createdAt\"],\n listSearchableFields: [\"filename\", \"alt\"],\n pagination: { defaultLimit: 10 },\n custom: { mediaInUse: inUse !== false },\n components: {\n views: {\n list: { Component: MEDIA_LIST },\n },\n },\n },\n access: {\n read: () => true,\n create: canUseFeature(\"media\"),\n update: canUseFeature(\"media\"),\n delete: isAdmin,\n },\n upload: {\n staticDir,\n mimeTypes,\n imageSizes: imageSizes ?? defaultShareSizes(),\n resizeOptions: DEFAULT_RESIZE,\n },\n hooks: {\n beforeValidate: [({ data }) => (data ? fillBlankAltFromFilename(data) : data)],\n beforeChange: [\n ({ data, req }) => {\n replaceClientOriginalWithResizedFile(req);\n return data;\n },\n ],\n },\n endpoints: inUse === false ? [] : [inUseEndpoint(inUse)],\n fields: [\n {\n name: \"alt\",\n type: \"text\",\n required: true,\n admin: {\n components: {\n afterInput: [MEDIA_ALT_AUTOFILL],\n },\n },\n },\n ],\n };\n}\n\nfunction inUseEndpoint(scopes: MediaInUseScopes): Endpoint {\n return {\n path: MEDIA_IN_USE_PATH,\n method: \"get\",\n handler: async (req: PayloadRequest) => {\n if (!req.user) return Response.json({ error: \"Unauthorized\" }, { status: 401 });\n try {\n const ids = [...await findMediaInUse(req.payload as unknown as MediaInUsePayload, scopes)];\n return Response.json({ ids });\n } catch (error) {\n const message = error instanceof Error ? error.message : \"Media in-use scan failed\";\n return Response.json({ error: message }, { status: 503 });\n }\n },\n };\n}\n","import type { Access, CollectionConfig } from \"payload\";\n\nexport interface CreateTaxonomyOptions {\n slug: string;\n labels: { singular: string; plural: string };\n /**\n * Required, no default — same shape as `createBrandAssets`. `update`\n * covers create, delete, and versions.\n */\n access: { read: Access; update: Access };\n /** Default true — terms are managed from the FAQ Library list. */\n hidden?: boolean;\n}\n\nfunction requireAccess(options: CreateTaxonomyOptions): CreateTaxonomyOptions[\"access\"] {\n const read = options.access?.read;\n const update = options.access?.update;\n if (!read || !update) {\n throw new Error(\n \"createTaxonomy requires access.read and access.update. Pass canUseFeature(\\\"questions\\\") as update when Topics are edited from the FAQ Library.\",\n );\n }\n return { read, update };\n}\n\n/**\n * Name-only terms collection. Topics (and later news or blog) share the\n * same documents. Hidden from the left nav by default; add and delete for\n * `manage: true` facets happen on the FAQ Library list.\n */\nexport function createTaxonomy(options: CreateTaxonomyOptions): CollectionConfig {\n const access = requireAccess(options);\n const hidden = options.hidden ?? true;\n\n return {\n slug: options.slug,\n labels: options.labels,\n admin: {\n useAsTitle: \"name\",\n hidden,\n },\n versions: true,\n access: {\n read: access.read,\n create: access.update,\n update: access.update,\n delete: access.update,\n readVersions: access.update,\n },\n fields: [{ name: \"name\", type: \"text\", required: true, label: \"Name\" }],\n };\n}\n","/** Import-map string. A site runs `payload generate:importmap`. */\nexport const QUESTIONS_LIST = \"@bison-lab/payload-core/admin#QuestionsList\";\n","import type { CollectionBeforeChangeHook } from \"payload\";\n\n/**\n * Plain text inside a Lexical document (or a leftover string). Empty\n * when there are no text nodes, or only whitespace — the same rule the\n * kit dialog uses to refuse an empty answer.\n */\nexport function lexicalPlainText(value: unknown): string {\n if (value == null) return \"\";\n if (typeof value === \"string\") return value.replace(/\\s+/g, \" \").trim();\n return collect(value).replace(/\\s+/g, \" \").trim();\n}\n\nconst BLOCK_SIBLING = new Set([\"paragraph\", \"heading\", \"quote\", \"list\", \"listitem\"]);\n\nfunction isBlockSibling(node: unknown): boolean {\n if (!node || typeof node !== \"object\") return false;\n return BLOCK_SIBLING.has(String((node as { type?: unknown }).type));\n}\n\nfunction collect(node: unknown): string {\n if (typeof node === \"string\") return node;\n if (!node || typeof node !== \"object\") return \"\";\n const rec = node as { type?: unknown; text?: unknown; children?: unknown; root?: unknown };\n if (typeof rec.text === \"string\") return rec.text;\n if (rec.type === \"linebreak\") return \" \";\n if (rec.root) return collect(rec.root);\n if (!Array.isArray(rec.children)) return \"\";\n let out = \"\";\n for (const child of rec.children) {\n const piece = collect(child);\n if (!piece) continue;\n if (out && isBlockSibling(child)) out += \" \";\n out += piece;\n }\n return out;\n}\n\n/**\n * Copies `lexicalPlainText(answer)` onto hidden `answerText` so list search\n * queries a varchar, never the jsonb Lexical column.\n */\nexport const syncAnswerText: CollectionBeforeChangeHook = ({ data }) => {\n if (!data || !(\"answer\" in data)) return data;\n return { ...data, answerText: lexicalPlainText(data.answer) };\n};\n","export const QUESTIONS_SLUG = \"questions\";\nexport const QUESTIONS_FEATURE = \"questions\";\n\n/**\n * Theme family for chips on a linked facet. The list fetches this\n * Global and maps each row's label (and key, if present) to `family`\n * so a badge can set `data-look`. Term documents that already store\n * `family` or `look` win.\n */\nexport interface OrganizeByLook {\n /** Global slug whose rows carry a Theme family. */\n global: string;\n /** Array field on that Global. Default `areas`. */\n path?: string;\n /** Label field on each row, matched to the term name. Default `label`. */\n label?: string;\n /** Theme family field. Default `family`. */\n family?: string;\n}\n\nexport interface OrganizeByEntry {\n /** FAQ relationship field name. Must be a valid Payload field name. */\n name: string;\n /** Filters, table heading, and Manage column. */\n label: string;\n /** Terms collection slug. */\n collection: string;\n /**\n * When true, Manage organization can add and delete terms. Default\n * false — linked collections stay read-only here.\n */\n manage?: boolean;\n /** Optional Theme family source for this facet's chips. */\n look?: OrganizeByLook;\n}\n\nexport interface CreateQuestionsOptions {\n /**\n * Optional. Empty is valid: the list is question, answer, published,\n * used-on. Each entry writes one `hasMany` relationship.\n */\n organizeBy?: readonly OrganizeByEntry[];\n /** Default `questions`. */\n slug?: string;\n /** Default FAQ / FAQ Library. */\n labels?: { singular: string; plural: string };\n}\n","import type { CollectionConfig, Field } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { authenticatedOrPublished } from \"../roles/access\";\nimport { QUESTIONS_LIST } from \"./fields\";\nimport { syncAnswerText } from \"./lexical-text\";\nimport {\n QUESTIONS_FEATURE,\n QUESTIONS_SLUG,\n type CreateQuestionsOptions,\n type OrganizeByEntry,\n} from \"./types\";\n\nfunction organizeByFields(entries: readonly OrganizeByEntry[]): Field[] {\n return entries.map((entry) => ({\n name: entry.name,\n type: \"relationship\" as const,\n relationTo: entry.collection,\n hasMany: true,\n label: entry.label,\n }));\n}\n\n/**\n * One document per FAQ, drafts, a kit List that replaces Payload's stock\n * collection list. Answer is the default Lexical editor (`type: \"richText\"`,\n * no custom `editor`) — the same one the pages rich-text block uses\n * (SPI-104). Hidden `answerText` is the varchar search index, written by\n * `syncAnswerText`. Used-on stays 0 until BIS-127 stores block\n * relationships (BIS-125 is the consume mockup). Without those,\n * faqColumns and page consume still do not read these Lexical answers.\n */\nexport function createQuestions(options: CreateQuestionsOptions = {}): CollectionConfig {\n const organizeBy = options.organizeBy ?? [];\n const slug = options.slug ?? QUESTIONS_SLUG;\n const labels = options.labels ?? { singular: \"FAQ\", plural: \"FAQ Library\" };\n const hidden = hideUnlessFeature(QUESTIONS_FEATURE);\n const write = canUseFeature(QUESTIONS_FEATURE);\n\n return {\n slug,\n labels,\n admin: {\n group: \"Content\",\n useAsTitle: \"question\",\n hidden: hidden as (args: { user: unknown }) => boolean,\n listSearchableFields: [\"question\", \"answerText\"],\n custom: { organizeBy },\n components: {\n views: {\n list: {\n Component: {\n path: QUESTIONS_LIST,\n clientProps: { organizeBy },\n },\n },\n },\n },\n },\n access: {\n read: authenticatedOrPublished,\n create: write,\n update: write,\n delete: write,\n readVersions: write,\n },\n versions: {\n drafts: true,\n },\n hooks: {\n beforeChange: [syncAnswerText],\n },\n fields: [\n { name: \"question\", type: \"text\", required: true, label: \"Question\" },\n { name: \"answer\", type: \"richText\", required: true, label: \"Answer\" },\n {\n name: \"answerText\",\n type: \"text\",\n admin: { hidden: true, disableListColumn: true, disableListFilter: true },\n },\n ...organizeByFields(organizeBy),\n ],\n };\n}\n","import { redirectsPlugin } from \"@payloadcms/plugin-redirects\";\nimport type {\n CollectionAfterChangeHook,\n CollectionConfig,\n Payload,\n PayloadRequest,\n Plugin,\n Where,\n} from \"payload\";\n\nimport { ROOT_PAGE_SLUG } from \"../collections/root-page-key\";\nimport { canUseFeature } from \"../features/access\";\nimport { normalizeSlug } from \"../fields/slug\";\nimport { isAdmin } from \"../roles/access\";\n\nexport const REDIRECTS_SLUG = \"redirects\";\n\nexport function redirectPath(slug: string): string {\n if (slug === ROOT_PAGE_SLUG) return \"/\";\n const normalized = normalizeSlug(slug);\n return normalized ? `/${normalized}` : \"\";\n}\n\nexport async function recordPublishedSlugRedirect({\n fromSlug,\n payload,\n req,\n toSlug,\n}: {\n fromSlug: string;\n payload: Payload;\n req?: PayloadRequest;\n toSlug: string;\n}): Promise<void> {\n const from = redirectPath(fromSlug);\n const to = redirectPath(toSlug);\n if (!from || !to || from === to) return;\n\n const found = async (where: Where) =>\n payload.find({\n collection: REDIRECTS_SLUG,\n depth: 0,\n limit: 100,\n overrideAccess: true,\n pagination: false,\n req,\n where,\n });\n\n for (const doc of (await found({ from: { equals: to } })).docs) {\n await payload.delete({ collection: REDIRECTS_SLUG, id: doc.id, overrideAccess: true, req });\n }\n\n for (const doc of (await found({ \"to.url\": { equals: from } })).docs) {\n await payload.update({\n collection: REDIRECTS_SLUG,\n data: { to: { type: \"custom\", url: to } },\n id: doc.id,\n overrideAccess: true,\n req,\n });\n }\n\n const data = { from, to: { type: \"custom\" as const, url: to }, type: \"308\" };\n const existing = (await found({ from: { equals: from } })).docs[0];\n if (existing) {\n await payload.update({\n collection: REDIRECTS_SLUG,\n data,\n id: existing.id,\n overrideAccess: true,\n req,\n });\n return;\n }\n\n await payload.create({ collection: REDIRECTS_SLUG, data, overrideAccess: true, req });\n}\n\nexport const writePublishedSlugRedirect: CollectionAfterChangeHook = async ({\n doc,\n previousDoc,\n req,\n}) => {\n if (doc._status !== \"published\") return doc;\n const fromSlug = typeof previousDoc?.publishedSlug === \"string\" ? previousDoc.publishedSlug : \"\";\n const toSlug = typeof doc.slug === \"string\" ? doc.slug : \"\";\n await recordPublishedSlugRedirect({ fromSlug, payload: req.payload, req, toSlug });\n return doc;\n};\n\nfunction withPublishedSlugRedirect(collection: CollectionConfig): CollectionConfig {\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n afterChange: [...(collection.hooks?.afterChange ?? []), writePublishedSlugRedirect],\n },\n };\n}\n\n/**\n * `@payloadcms/plugin-redirects` scoped to `pages`, 308 only. A published\n * slug change writes the redirect and collapses chains. The plugin stores\n * rows; the site still has to serve them.\n */\nexport function createRedirects(): Plugin {\n const plugin = redirectsPlugin({\n collections: [\"pages\"],\n redirectTypeFieldOverride: {\n admin: { hidden: true },\n defaultValue: \"308\",\n },\n redirectTypes: [\"308\"],\n overrides: {\n access: {\n create: canUseFeature(\"content\"),\n delete: isAdmin,\n update: canUseFeature(\"content\"),\n },\n admin: { group: \"Content\" },\n },\n });\n\n return (config) => {\n const next = plugin(config);\n return {\n ...next,\n collections: next.collections?.map((collection) =>\n collection.slug === \"pages\" ? withPublishedSlugRedirect(collection) : collection,\n ),\n };\n };\n}\n","export const ADMIN_NAV = \"@bison-lab/payload-core/admin#AdminNav\";\nexport const ADMIN_NAV_ROW_LABEL = \"@bison-lab/payload-core/admin#AdminNavRowLabel\";\nexport const ADMIN_NAV_ITEM_ROW_LABEL = \"@bison-lab/payload-core/admin#AdminNavItemRowLabel\";\nexport const ADMIN_NAV_ENTITY_FIELD = \"@bison-lab/payload-core/admin#AdminNavEntityField\";\n","/**\n * Developer-owned admin sidebar. SPI-10 skins this with AppSidebarBlock;\n * this package ships the document and the default Nav. A consuming site\n * waits for SPI-97 after this and BIS-110 publish.\n */\n\nexport const ADMIN_NAV_SLUG = \"admin-nav\";\n\nexport type AdminNavEntityType = \"collection\" | \"global\";\n\nexport interface AdminNavItem {\n type: AdminNavEntityType;\n slug: string;\n label: string;\n}\n\nexport interface AdminNavGroup {\n label: string;\n items: AdminNavItem[];\n}\n\nexport interface AdminNavDoc {\n groups?: Array<{\n id?: string | null;\n label?: string | null;\n items?: Array<{\n id?: string | null;\n type?: string | null;\n slug?: string | null;\n }> | null;\n }> | null;\n}\n\nexport interface AdminNavVisibleEntities {\n collections?: readonly string[];\n globals?: readonly string[];\n}\n\nexport interface AdminNavEntityConfig {\n slug: string;\n admin?: { group?: unknown };\n label?: unknown;\n labels?: { plural?: unknown; singular?: unknown };\n}\n\nexport interface AdminNavConfig {\n collections?: readonly AdminNavEntityConfig[];\n globals?: readonly AdminNavEntityConfig[];\n}\n\nexport interface ResolveAdminNavArgs {\n config: AdminNavConfig;\n doc?: AdminNavDoc | null;\n visibleEntities?: AdminNavVisibleEntities;\n}\n","import type { TextFieldSingleValidation } from \"payload\";\n\nconst UNKNOWN_ENTITY_MESSAGE = \"Not in this site's config.\";\n\n/**\n * A Developer cannot invent a collection or global that is not registered.\n */\nexport const validateAdminNavSlug: TextFieldSingleValidation = (value, { req, siblingData }) => {\n if (typeof value !== \"string\" || value === \"\") return true;\n const type = siblingData && typeof siblingData === \"object\" && \"type\" in siblingData ? siblingData.type : null;\n const list =\n type === \"global\" ? req.payload?.config?.globals : type === \"collection\" ? req.payload?.config?.collections : [];\n const slugs = (list ?? []).map((entity) => entity.slug);\n return slugs.includes(value) || UNKNOWN_ENTITY_MESSAGE;\n};\n","import type { ArrayField, GlobalConfig } from \"payload\";\n\nimport { hideUnlessDeveloper, isAuthenticated, isDeveloper, type MaybeUser } from \"../roles/access\";\nimport { ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL } from \"./fields\";\nimport { ADMIN_NAV_SLUG } from \"./types\";\nimport { validateAdminNavSlug } from \"./validate\";\n\nconst groupsField: ArrayField = {\n name: \"groups\",\n type: \"array\",\n label: \"Groups\",\n labels: { singular: \"Group\", plural: \"Groups\" },\n admin: {\n components: { RowLabel: ADMIN_NAV_ROW_LABEL },\n description: \"Sidebar headers and the collections or globals under each. Drag to reorder. An empty header still shows.\",\n initCollapsed: false,\n },\n fields: [\n {\n name: \"label\",\n type: \"text\",\n label: \"Header\",\n },\n {\n name: \"items\",\n type: \"array\",\n label: \"Items\",\n labels: { singular: \"Item\", plural: \"Items\" },\n admin: { components: { RowLabel: ADMIN_NAV_ITEM_ROW_LABEL } },\n fields: [\n {\n type: \"row\",\n fields: [\n {\n name: \"type\",\n type: \"select\",\n label: \"Type\",\n required: true,\n defaultValue: \"collection\",\n options: [\n { label: \"Collection\", value: \"collection\" },\n { label: \"Global\", value: \"global\" },\n ],\n admin: { width: \"40%\" },\n },\n {\n name: \"slug\",\n type: \"text\",\n label: \"Slug\",\n required: true,\n validate: validateAdminNavSlug,\n admin: { width: \"60%\", components: { Field: ADMIN_NAV_ENTITY_FIELD } },\n },\n ],\n },\n ],\n },\n ],\n};\n\n/**\n * Settings → Admin nav. Developer chrome, not a Features row. Save writes\n * immediately. The package Nav reads this document. An empty row falls\n * back to Payload's first-seen walk; a saved row is the sidebar.\n */\nexport function createAdminNav(): GlobalConfig {\n return {\n slug: ADMIN_NAV_SLUG,\n label: \"Admin nav\",\n admin: {\n group: \"Settings\",\n hidden: hideUnlessDeveloper,\n description:\n \"Sidebar group headers and order. An empty document falls back to Payload's first-seen walk. Once you save, only the groups and items you listed appear — omitted collections and globals stay off the sidebar.\",\n },\n access: {\n read: isAuthenticated,\n update: ({ req }) => isDeveloper(req.user as MaybeUser),\n },\n fields: [groupsField],\n };\n}\n","import type { Config } from \"payload\";\nimport { definePlugin } from \"payload\";\n\nimport { ADMIN_NAV } from \"./fields\";\n\n/**\n * Sets `admin.components.Nav` to the package Nav. A consuming site must\n * not write its own Nav — SPI-10 is the later skin, and it reads\n * `resolveAdminNav` rather than a second layout source.\n */\nexport const adminNav = definePlugin({\n slug: \"admin-nav\",\n order: 1000,\n plugin: ({ config }): Config => ({\n ...config,\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n Nav: ADMIN_NAV,\n },\n },\n }),\n});\n","import type {\n AdminNavConfig,\n AdminNavDoc,\n AdminNavEntityConfig,\n AdminNavEntityType,\n AdminNavGroup,\n AdminNavItem,\n ResolveAdminNavArgs,\n} from \"./types\";\n\nfunction sidebarGroup(group: unknown): string | false {\n if (group === false) return false;\n if (typeof group === \"string\") return group;\n return \"\";\n}\n\nfunction asLabel(value: unknown, fallback: string): string {\n return typeof value === \"string\" && value ? value : fallback;\n}\n\nfunction entityLabel(entity: AdminNavEntityConfig, type: AdminNavEntityType): string {\n if (type === \"collection\") {\n return asLabel(entity.labels?.plural, asLabel(entity.labels?.singular, entity.slug));\n }\n return asLabel(entity.label, entity.slug);\n}\n\nfunction keyOf(type: AdminNavEntityType, slug: string): string {\n return `${type}:${slug}`;\n}\n\ninterface CatalogEntry {\n type: AdminNavEntityType;\n slug: string;\n label: string;\n group: string | false;\n}\n\nfunction catalog(config: AdminNavConfig): CatalogEntry[] {\n const collections = (config.collections ?? []).map((entity) => ({\n type: \"collection\" as const,\n slug: entity.slug,\n label: entityLabel(entity, \"collection\"),\n group: sidebarGroup(entity.admin?.group),\n }));\n const globals = (config.globals ?? []).map((entity) => ({\n type: \"global\" as const,\n slug: entity.slug,\n label: entityLabel(entity, \"global\"),\n group: sidebarGroup(entity.admin?.group),\n }));\n return [...collections, ...globals];\n}\n\nfunction defaultGroups(entities: readonly CatalogEntry[]): AdminNavGroup[] {\n const groups: AdminNavGroup[] = [];\n for (const entity of entities) {\n if (entity.group === false) continue;\n let group = groups.find((entry) => entry.label === entity.group);\n if (!group) {\n group = { label: entity.group, items: [] };\n groups.push(group);\n }\n group.items.push({ type: entity.type, slug: entity.slug, label: entity.label });\n }\n return groups;\n}\n\nfunction itemFromSaved(\n item: { type?: string | null; slug?: string | null },\n byKey: Map<string, CatalogEntry>,\n): AdminNavItem | null {\n const type = item.type === \"global\" || item.type === \"collection\" ? item.type : null;\n const slug = typeof item.slug === \"string\" ? item.slug : \"\";\n if (!type || !slug) return null;\n const entity = byKey.get(keyOf(type, slug));\n if (!entity || entity.group === false) return null;\n return { type, slug, label: entity.label };\n}\n\nfunction fromDocument(doc: AdminNavDoc, entities: readonly CatalogEntry[]): AdminNavGroup[] {\n const byKey = new Map(entities.map((entity) => [keyOf(entity.type, entity.slug), entity]));\n return (doc.groups ?? []).map((row) => ({\n label: typeof row.label === \"string\" ? row.label : \"\",\n items: (row.items ?? []).flatMap((item) => {\n const resolved = itemFromSaved(item ?? {}, byKey);\n return resolved ? [resolved] : [];\n }),\n }));\n}\n\n/**\n * Layout for the package Nav (and later SPI-10). Permissions are\n * `visibleEntities` — this function does not re-derive access.\n */\nexport function resolveAdminNav({ config, doc, visibleEntities }: ResolveAdminNavArgs): AdminNavGroup[] {\n const entities = catalog(config);\n const saved = Array.isArray(doc?.groups) ? doc.groups : [];\n let groups = saved.length === 0 ? defaultGroups(entities) : fromDocument({ groups: saved }, entities);\n\n if (visibleEntities) {\n const collections = new Set(visibleEntities.collections ?? []);\n const globals = new Set(visibleEntities.globals ?? []);\n groups = groups.map((group) => ({\n ...group,\n items: group.items.filter((item) =>\n item.type === \"collection\" ? collections.has(item.slug) : globals.has(item.slug),\n ),\n }));\n }\n\n return groups;\n}\n","import { Forbidden, type GlobalBeforeChangeHook, type GlobalConfig } from \"payload\";\n\nimport { canUseFeature, hideUnlessFeature } from \"../features/access\";\nimport { canPublish, isAuthenticated } from \"../roles/access\";\nimport { FOOTER_COLUMNS_FIELD, footerFields } from \"./footer\";\nimport { linkField } from \"./link\";\nimport {\n NAVIGATION_DB_NAME,\n NAVIGATION_FEATURE,\n NAVIGATION_FOOTER_DB_NAME,\n NAVIGATION_FOOTER_SLUG,\n NAVIGATION_SLUG,\n type CreateNavigationOptions,\n} from \"./types\";\n\nconst refusePublishWithoutTick: GlobalBeforeChangeHook = async ({ data, req }) => {\n if (data._status !== \"published\") return data;\n if (!req.user) return data;\n if (await Promise.resolve(canPublish({ req } as never))) return data;\n throw new Forbidden();\n};\n\n/**\n * Header (`navigation` / `nav`) and Footer (`navigation-footer` / `navf`).\n * One Features tick (`navigation`). Independent Save / Publish / drafts —\n * a draft header does not publish the footer.\n *\n * Header opts into the admin workspace (`AdminWorkspace`). Bar stays in the\n * schema and is hidden; SPI-99 consumes `headerFromNavigation`. Payload's\n * left nav stays until BIS-90.\n */\nexport function createNavigation({\n blocks,\n preview,\n livePreview,\n previewButton,\n pagesCollection,\n footerCopyrightName,\n}: CreateNavigationOptions): [GlobalConfig, GlobalConfig] {\n if (blocks.length === 0) {\n throw new Error(\"createNavigation needs at least one header block\");\n }\n\n const hidden = hideUnlessFeature(NAVIGATION_FEATURE);\n const update = canUseFeature(NAVIGATION_FEATURE);\n const previewAdmin = {\n ...(preview ? { preview } : {}),\n ...(livePreview ? { livePreview } : {}),\n };\n\n const header: GlobalConfig = {\n slug: NAVIGATION_SLUG,\n dbName: NAVIGATION_DB_NAME,\n label: \"Header\",\n admin: {\n group: \"Navigation\",\n hidden: hidden as (args: { user: unknown }) => boolean,\n description: \"The public header. A draft never reaches the live site until you publish.\",\n ...previewAdmin,\n components: {\n ...(previewButton ? { elements: { PreviewButton: previewButton } } : {}),\n views: {\n edit: {\n default: {\n Component: \"@bison-lab/payload-blocks/admin#AdminWorkspace\",\n },\n },\n },\n },\n },\n access: {\n read: () => true,\n readVersions: isAuthenticated,\n update,\n },\n versions: {\n drafts: { autosave: { interval: 375 } },\n },\n hooks: {\n beforeChange: [refusePublishWithoutTick],\n },\n fields: [\n {\n name: \"header\",\n type: \"group\",\n label: false,\n admin: { hideGutter: true },\n fields: [\n {\n name: \"items\",\n type: \"blocks\",\n labels: { singular: \"Item\", plural: \"Items\" },\n blocks,\n admin: {\n components: {\n Field: \"@bison-lab/payload-blocks/admin#NavItemsField\",\n },\n },\n },\n linkField({\n name: \"cta\",\n label: \"Header button\",\n toggle: true,\n pagesCollection,\n admin: {\n hidden: true,\n },\n }),\n ],\n },\n {\n name: \"bar\",\n type: \"group\",\n label: false,\n admin: {\n hidden: true,\n },\n fields: [\n {\n name: \"hideOnScroll\",\n type: \"checkbox\",\n label: \"Hide on scroll\",\n defaultValue: true,\n admin: {\n description: \"Slide the bar away as the page scrolls down.\",\n },\n },\n {\n name: \"viewport\",\n type: \"checkbox\",\n label: \"Shared viewport\",\n defaultValue: false,\n admin: {\n description:\n \"Centre one animated panel under the bar. Off (the default) anchors each mega menu under its own trigger.\",\n },\n },\n {\n name: \"defaultMaxWidth\",\n type: \"select\",\n label: \"Default panel width\",\n defaultValue: \"standard\",\n options: [\n { label: \"Narrow\", value: \"narrow\" },\n { label: \"Standard\", value: \"standard\" },\n { label: \"Wide\", value: \"wide\" },\n ],\n admin: {\n description:\n \"Used when a mega menu does not set its own width. Per-panel widths still win.\",\n },\n },\n ],\n },\n ],\n };\n\n const footer: GlobalConfig = {\n slug: NAVIGATION_FOOTER_SLUG,\n dbName: NAVIGATION_FOOTER_DB_NAME,\n label: \"Footer\",\n admin: {\n group: \"Navigation\",\n hidden: hidden as (args: { user: unknown }) => boolean,\n description:\n \"The public footer. Columns, brand copy, and socials. A draft never reaches the live site until you publish.\",\n ...previewAdmin,\n custom: footerCopyrightName ? { footerCopyrightName } : undefined,\n components: {\n ...(previewButton ? { elements: { PreviewButton: previewButton } } : {}),\n views: {\n edit: {\n default: {\n Component: \"@bison-lab/payload-blocks/admin#AdminWorkspace\",\n },\n },\n },\n },\n },\n access: {\n read: () => true,\n readVersions: isAuthenticated,\n update,\n },\n versions: {\n drafts: { autosave: { interval: 375 } },\n },\n hooks: {\n beforeChange: [refusePublishWithoutTick],\n },\n fields: [\n {\n name: \"footer\",\n type: \"group\",\n label: false,\n admin: {\n hideGutter: true,\n components: {\n Field: FOOTER_COLUMNS_FIELD,\n },\n },\n fields: footerFields({ pagesCollection }),\n },\n ],\n };\n\n return [header, footer];\n}\n","import type { CollectionConfig, GlobalConfig } from \"payload\";\nimport { definePlugin } from \"payload\";\n\nimport { isDeveloperTab } from \"../roles/access\";\n\ntype Entity = CollectionConfig | GlobalConfig;\n\nfunction gateApiTab<T extends Entity>(entity: T): T {\n const components = entity.admin?.components;\n const edit = components?.views?.edit;\n const api = edit && \"api\" in edit ? edit.api : undefined;\n return {\n ...entity,\n admin: {\n ...entity.admin,\n components: {\n ...components,\n views: {\n ...components?.views,\n edit: {\n ...edit,\n api: { ...api, tab: { ...api?.tab, condition: isDeveloperTab } },\n },\n },\n },\n },\n };\n}\n\n/**\n * Gates the document API tab to Developer, config-wide. After plugins that\n * use `definePlugin` order (MCP is 10), so a collection those plugins\n * register is still covered.\n */\nexport const adminOnlyApiTab = definePlugin({\n slug: \"admin-only-api-tab\",\n order: 1000,\n plugin: ({ config }) => ({\n ...config,\n collections: config.collections?.map(gateApiTab),\n globals: config.globals?.map(gateApiTab),\n }),\n});\n","import type { Config } from \"payload\";\nimport { definePlugin } from \"payload\";\n\nimport { DOCUMENT_TITLE_ACTIONS } from \"../admin/document-controls\";\n\ntype AdminProviders = NonNullable<\n NonNullable<NonNullable<Config[\"admin\"]>[\"components\"]>[\"providers\"]\n>;\n\nfunction asList(value: AdminProviders | undefined): AdminProviders {\n if (!value) return [];\n return value;\n}\n\nfunction alreadyHasTitleActions(providers: AdminProviders): boolean {\n return providers.some((entry) => {\n if (typeof entry === \"string\") return entry === DOCUMENT_TITLE_ACTIONS;\n if (entry && typeof entry === \"object\" && \"path\" in entry) {\n return entry.path === DOCUMENT_TITLE_ACTIONS;\n }\n return false;\n });\n}\n\nfunction withTitleActions(config: Config): Config {\n const providers = asList(config.admin?.components?.providers);\n if (alreadyHasTitleActions(providers)) return config;\n return {\n ...config,\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n providers: [DOCUMENT_TITLE_ACTIONS, ...providers],\n },\n },\n };\n}\n\n/**\n * Puts every document's primary actions on the title row — the same\n * slot collection lists use for Create New — and hides the dead Edit\n * tab when it has no sibling. One admin provider so Roles, Theme,\n * Features, Account, and a site's own Globals cannot drift.\n */\nexport const documentTitleActions = definePlugin({\n slug: \"document-title-actions\",\n order: 1000,\n plugin: ({ config }) => withTitleActions(config),\n});\n","/** Import-map key for the provider `listAlign()` mounts. */\nexport const LIST_ALIGN = \"@bison-lab/payload-core/admin#ListAlignStyles\";\n","import type { Config, Field } from \"payload\";\nimport { definePlugin } from \"payload\";\n\nimport { LIST_ALIGN } from \"../admin/list-align-key\";\n\n/**\n * Where a list column's header and cells sit. `start` is Payload's\n * default and writes no rule.\n */\nexport type ListAlign = \"start\" | \"center\" | \"end\";\n\ntype ListAlignField = Field & {\n admin?: { custom?: { listAlign?: unknown } };\n};\n\ntype AdminProviders = NonNullable<\n NonNullable<NonNullable<Config[\"admin\"]>[\"components\"]>[\"providers\"]\n>;\n\nexport type ListAlignColumn = {\n collection: string;\n /** Payload's list accessor: `group.field` for a field in a named group. */\n accessor: string;\n align: Exclude<ListAlign, \"start\">;\n};\n\nfunction readAlign(field: ListAlignField): ListAlignColumn[\"align\"] | undefined {\n const value = field.admin?.custom?.listAlign;\n return value === \"center\" || value === \"end\" ? value : undefined;\n}\n\n/**\n * Walks a field list the way Payload builds list columns: rows,\n * collapsibles, and unnamed tabs flatten into the parent; a named group\n * or tab prefixes its children with `name.`.\n */\nfunction collectFields(\n fields: readonly Field[],\n collection: string,\n prefix: string,\n out: ListAlignColumn[],\n) {\n for (const field of fields) {\n if (field.type === \"row\" || field.type === \"collapsible\") {\n collectFields(field.fields, collection, prefix, out);\n continue;\n }\n if (field.type === \"tabs\") {\n for (const tab of field.tabs) {\n const named = \"name\" in tab && typeof tab.name === \"string\" && tab.name.length > 0;\n collectFields(tab.fields, collection, named ? `${prefix}${tab.name}.` : prefix, out);\n }\n continue;\n }\n if (!(\"name\" in field) || typeof field.name !== \"string\") continue;\n if (field.type === \"group\") {\n collectFields(field.fields, collection, `${prefix}${field.name}.`, out);\n continue;\n }\n const align = readAlign(field as ListAlignField);\n if (align) out.push({ collection, accessor: `${prefix}${field.name}`, align });\n }\n}\n\n/** Every field in the config that asked for a non-default list alignment. */\nexport function listAlignColumns(config: Pick<Config, \"collections\">): ListAlignColumn[] {\n const out: ListAlignColumn[] = [];\n for (const collection of config.collections ?? []) {\n collectFields(collection.fields, collection.slug, \"\", out);\n }\n return out;\n}\n\nfunction cssIdent(value: string): string {\n return value.replace(/[^a-zA-Z0-9_-]/g, (char) => `\\\\${char}`);\n}\n\n/**\n * One rule set per aligned column, so header and cells cannot drift.\n *\n * Payload's header is `th#heading-<accessor>` holding a full-width flex\n * `.sort-column` (label, then the sort arrows), so `text-align` alone\n * never moves it. Centered: the sort column shrinks to the label and the\n * arrows hang outside it, so the label word — not label-plus-arrows —\n * sits on the cell's center line. End: the arrows move to the label's\n * leading side so the label ends where the values end. Cells take\n * `text-align`, and the cell's child (Payload's line-clamp box) shrinks\n * to its content and sits on the same edge or center.\n */\nexport function listAlignCss(columns: readonly ListAlignColumn[]): string {\n return columns\n .map(({ collection, accessor, align }) => {\n const id = cssIdent(accessor.replace(/\\./g, \"__\"));\n const table = `.collection-list--${cssIdent(collection)} .table`;\n const th = `${table} th#heading-${id}`;\n const td = `${table} td.cell-${id}`;\n // Payload clamps a cell's child with `display:-webkit-box`, a block,\n // so it never follows `text-align`. Shrink it to its content and push\n // it with auto margins; the clamp still wraps at the column width.\n const margins = align === \"center\" ? \"margin-inline:auto\" : \"margin-inline-start:auto\";\n const header =\n align === \"center\"\n ? `${th} .sort-column{display:inline-flex;position:relative;max-width:100%;vertical-align:middle}` +\n `${th} .sort-column__buttons{position:absolute;left:100%;top:50%;transform:translateY(-50%);margin-inline-start:calc(var(--base) / 4)}`\n : `${th} .sort-column{flex-direction:row-reverse;justify-content:flex-start}`;\n return (\n `${th},${td}{text-align:${align}}` +\n `${td}>*{width:fit-content;max-width:100%;${margins}}` +\n header\n );\n })\n .join(\"\\n\");\n}\n\nfunction withoutListAlign(providers: AdminProviders): AdminProviders {\n return providers.filter((entry) => {\n if (typeof entry === \"string\") return entry !== LIST_ALIGN;\n if (entry && typeof entry === \"object\" && \"path\" in entry) return entry.path !== LIST_ALIGN;\n return true;\n });\n}\n\n/**\n * Reads `admin.custom.listAlign` off every collection field and paints\n * the matching list header and cells from one stylesheet, mounted as an\n * admin provider. Declare the alignment on the field; never write a\n * per-column selector in a site stylesheet.\n *\n * Runs late (`order`) so collections other plugins add are seen.\n */\nexport const listAlign = definePlugin({\n slug: \"list-align\",\n order: 1001,\n plugin: ({ config }) => {\n const css = listAlignCss(listAlignColumns(config));\n const providers = withoutListAlign(config.admin?.components?.providers ?? []);\n if (!css) {\n return {\n ...config,\n admin: { ...config.admin, components: { ...config.admin?.components, providers } },\n };\n }\n return {\n ...config,\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n providers: [...providers, { path: LIST_ALIGN, clientProps: { css } }],\n },\n },\n };\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;AAOA,MAAa,eAA8B;CACzC,MAAM;CACN,MAAM;CACN,OAAO;CACP,cAAc;CACd,OAAO,EACL,aACE,qHACH;CACF;;;;ACfD,MAAa,qBAAqB;;;;;;;AAQlC,SAAgB,eAAe,MAAc,MAAA,KAAkC;CAC7E,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,QAAQ,UAAU,IAAK,QAAO;CAClC,MAAM,MAAM,QAAQ,MAAM,GAAG,IAAI;CACjC,MAAM,YAAY,IAAI,YAAY,IAAI;AACtC,QAAO,GAAG,YAAY,IAAI,IAAI,MAAM,GAAG,UAAU,GAAG,IAAI;;;;;;;;;;;;;;;;ACmD1D,SAAgB,UAAwC,EACtD,UACA,QACA,cACA,UACA,cAAc,CAAC,QAAQ,EACvB,oBAAoB,WACa;CACjC,MAAM,iBAAsC,EAAE,UAC5C,KAAK,QAAQ,cAAc,UAAU,IAAI,MAAM,GAAG;CACpD,MAAM,uBAAkD,EAAE,UACxD,eAAe,eAAe,IAAI,IAAI,GAAG;CAC3C,MAAM,eAAkC,EAAE,UAAU,OAAO,IAAI,IAAI;CAEnE,MAAM,gBAAiD,YAClD,EAAE,UAAU,SAAS,IAAI,IAAI,KAC9B,KAAA;AAEJ,QAAOA,YAAiB;EACtB;EACA;EACA,UAAU;EACV;EACA;EACA;EACA,GAAI,gBAAgB,EAAE,eAAe,GAAG,EAAE;EAC1C,SAAS,EAAE,oBAAoB,CAAC,GAAG,eAAe,aAAa;EAChE,CAAC;;;;;;;;AASJ,SAAgB,aACd,QACA,QAAQ,SACa;AACrB,KAAI,CAAC,MAAM,QAAQ,OAAO,CAA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