Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6f177a37d | ||
|
|
1a9c51a1fd |
+14
-7
@@ -1,3 +1,4 @@
|
|||||||
|
import type { Payload } from 'payload';
|
||||||
/**
|
/**
|
||||||
* White-label admin branding: the Payload admin panel's logo (login + nav) and
|
* White-label admin branding: the Payload admin panel's logo (login + nav) and
|
||||||
* icon, pulled from the project's SiteSettings so each client sees THEIR brand,
|
* icon, pulled from the project's SiteSettings so each client sees THEIR brand,
|
||||||
@@ -5,13 +6,13 @@
|
|||||||
* automatically by `ipalKit({ whiteLabel: true })` (it injects
|
* automatically by `ipalKit({ whiteLabel: true })` (it injects
|
||||||
* admin.components.graphics.Logo/Icon pointing here).
|
* admin.components.graphics.Logo/Icon pointing here).
|
||||||
*
|
*
|
||||||
* Server Components — they read the SiteSettings global at render. Data access
|
* Server Components — they read the SiteSettings global at render, using the
|
||||||
* uses the project's `@payload-config` alias (universal in Payload 3 Next apps),
|
* `payload` instance Payload itself passes to admin server components. NO
|
||||||
* loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to
|
* `import('@payload-config')`: a variable-specifier import isn't traced by the
|
||||||
* resolve it (same pattern as the optional 2FA import). Everything is wrapped in
|
* Next bundler ("Cannot find module '@payload-config'") — same bug class as the
|
||||||
* try/catch: on the login screen before the DB is ready, or a build with no DB,
|
* old 2FA import. Everything is wrapped in try/catch: no payload prop, DB not
|
||||||
* the component falls back to the site name text, then to null (Payload's own
|
* ready, etc. → site name text, then null (Payload's own default) — never
|
||||||
* default) — never throws, never blocks the panel.
|
* throws, never blocks the panel.
|
||||||
*
|
*
|
||||||
* A0: no client brand in code. The logo/name come from the panel; if nothing is
|
* A0: no client brand in code. The logo/name come from the panel; if nothing is
|
||||||
* set, nothing is forced.
|
* set, nothing is forced.
|
||||||
@@ -19,8 +20,14 @@
|
|||||||
type BrandingProps = {
|
type BrandingProps = {
|
||||||
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
|
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
|
||||||
imageField?: string;
|
imageField?: string;
|
||||||
|
/** Injected by Payload — current admin locale (object or code). */
|
||||||
|
locale?: {
|
||||||
|
code?: string;
|
||||||
|
} | string;
|
||||||
/** Field holding the site name. Default 'siteName'. */
|
/** Field holding the site name. Default 'siteName'. */
|
||||||
nameField?: string;
|
nameField?: string;
|
||||||
|
/** Injected by Payload into admin server components. */
|
||||||
|
payload?: Payload;
|
||||||
/** SiteSettings global slug. Default 'site-settings'. */
|
/** SiteSettings global slug. Default 'site-settings'. */
|
||||||
settingsSlug?: string;
|
settingsSlug?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
+33
-13
@@ -1,25 +1,45 @@
|
|||||||
import { jsx as _jsx } from "react/jsx-runtime";
|
import { jsx as _jsx } from "react/jsx-runtime";
|
||||||
import { getPayload } from 'payload';
|
/** A localized text field may arrive as a string or a { locale: value } map. */ function pickText(value, locale) {
|
||||||
async function loadBranding(settingsSlug, nameField, imageField) {
|
if (typeof value === 'string') {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (value && typeof value === 'object') {
|
||||||
|
const map = value;
|
||||||
|
const preferred = locale ? map[locale] : undefined;
|
||||||
|
if (typeof preferred === 'string') {
|
||||||
|
return preferred;
|
||||||
|
}
|
||||||
|
const first = Object.values(map).find((v)=>typeof v === 'string');
|
||||||
|
return first ?? null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
async function loadBranding(props, settingsSlug, nameField, imageField) {
|
||||||
|
const { payload } = props;
|
||||||
|
if (!payload) {
|
||||||
|
return {
|
||||||
|
name: null,
|
||||||
|
url: null
|
||||||
|
};
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Consumer alias — resolved in the project's build, hidden from plugin tsc.
|
const locale = typeof props.locale === 'string' ? props.locale : props.locale?.code;
|
||||||
const spec = '@payload-config';
|
|
||||||
const mod = await import(spec);
|
|
||||||
const payload = await getPayload({
|
|
||||||
config: mod.default
|
|
||||||
});
|
|
||||||
const settings = await payload.findGlobal({
|
const settings = await payload.findGlobal({
|
||||||
slug: settingsSlug,
|
slug: settingsSlug,
|
||||||
depth: 1
|
depth: 1,
|
||||||
|
...locale ? {
|
||||||
|
locale: locale
|
||||||
|
} : {}
|
||||||
});
|
});
|
||||||
const name = typeof settings[nameField] === 'string' ? settings[nameField] : null;
|
const name = pickText(settings[nameField], locale);
|
||||||
const image = settings[imageField];
|
const image = settings[imageField];
|
||||||
const url = image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null;
|
const url = image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null;
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
url
|
url
|
||||||
};
|
};
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.warn('[ipal] admin branding: falling back to Payload default:', error);
|
||||||
return {
|
return {
|
||||||
name: null,
|
name: null,
|
||||||
url: null
|
url: null
|
||||||
@@ -32,7 +52,7 @@ async function loadBranding(settingsSlug, nameField, imageField) {
|
|||||||
* falls back to `siteName` text. Sized generously for the login screen.
|
* falls back to `siteName` text. Sized generously for the login screen.
|
||||||
*/ export async function AdminLogo(props = {}) {
|
*/ export async function AdminLogo(props = {}) {
|
||||||
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
|
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
|
||||||
const { name, url } = await loadBranding(settingsSlug, nameField, imageField);
|
const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField);
|
||||||
if (url) {
|
if (url) {
|
||||||
return /*#__PURE__*/ _jsx("img", {
|
return /*#__PURE__*/ _jsx("img", {
|
||||||
alt: name ?? '',
|
alt: name ?? '',
|
||||||
@@ -59,7 +79,7 @@ async function loadBranding(settingsSlug, nameField, imageField) {
|
|||||||
}
|
}
|
||||||
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */ export async function AdminIcon(props = {}) {
|
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */ export async function AdminIcon(props = {}) {
|
||||||
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
|
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props;
|
||||||
const { name, url } = await loadBranding(settingsSlug, nameField, imageField);
|
const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField);
|
||||||
if (url) {
|
if (url) {
|
||||||
return /*#__PURE__*/ _jsx("img", {
|
return /*#__PURE__*/ _jsx("img", {
|
||||||
alt: name ?? '',
|
alt: name ?? '',
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@intecion/ipal-kit",
|
"name": "@intecion/ipal-kit",
|
||||||
"version": "1.7.9",
|
"version": "1.7.10",
|
||||||
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getPayload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* White-label admin branding: the Payload admin panel's logo (login + nav) and
|
* White-label admin branding: the Payload admin panel's logo (login + nav) and
|
||||||
@@ -7,13 +7,13 @@ import { getPayload } from 'payload'
|
|||||||
* automatically by `ipalKit({ whiteLabel: true })` (it injects
|
* automatically by `ipalKit({ whiteLabel: true })` (it injects
|
||||||
* admin.components.graphics.Logo/Icon pointing here).
|
* admin.components.graphics.Logo/Icon pointing here).
|
||||||
*
|
*
|
||||||
* Server Components — they read the SiteSettings global at render. Data access
|
* Server Components — they read the SiteSettings global at render, using the
|
||||||
* uses the project's `@payload-config` alias (universal in Payload 3 Next apps),
|
* `payload` instance Payload itself passes to admin server components. NO
|
||||||
* loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to
|
* `import('@payload-config')`: a variable-specifier import isn't traced by the
|
||||||
* resolve it (same pattern as the optional 2FA import). Everything is wrapped in
|
* Next bundler ("Cannot find module '@payload-config'") — same bug class as the
|
||||||
* try/catch: on the login screen before the DB is ready, or a build with no DB,
|
* old 2FA import. Everything is wrapped in try/catch: no payload prop, DB not
|
||||||
* the component falls back to the site name text, then to null (Payload's own
|
* ready, etc. → site name text, then null (Payload's own default) — never
|
||||||
* default) — never throws, never blocks the panel.
|
* throws, never blocks the panel.
|
||||||
*
|
*
|
||||||
* A0: no client brand in code. The logo/name come from the panel; if nothing is
|
* A0: no client brand in code. The logo/name come from the panel; if nothing is
|
||||||
* set, nothing is forced.
|
* set, nothing is forced.
|
||||||
@@ -22,35 +22,54 @@ import { getPayload } from 'payload'
|
|||||||
type BrandingProps = {
|
type BrandingProps = {
|
||||||
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
|
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
|
||||||
imageField?: string
|
imageField?: string
|
||||||
|
/** Injected by Payload — current admin locale (object or code). */
|
||||||
|
locale?: { code?: string } | string
|
||||||
/** Field holding the site name. Default 'siteName'. */
|
/** Field holding the site name. Default 'siteName'. */
|
||||||
nameField?: string
|
nameField?: string
|
||||||
|
/** Injected by Payload into admin server components. */
|
||||||
|
payload?: Payload
|
||||||
/** SiteSettings global slug. Default 'site-settings'. */
|
/** SiteSettings global slug. Default 'site-settings'. */
|
||||||
settingsSlug?: string
|
settingsSlug?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type MediaLike = { url?: null | string } | null | undefined
|
type MediaLike = { url?: null | string } | null | undefined
|
||||||
|
|
||||||
|
/** A localized text field may arrive as a string or a { locale: value } map. */
|
||||||
|
function pickText(value: unknown, locale: string | undefined): null | string {
|
||||||
|
if (typeof value === 'string') {return value}
|
||||||
|
if (value && typeof value === 'object') {
|
||||||
|
const map = value as Record<string, unknown>
|
||||||
|
const preferred = locale ? map[locale] : undefined
|
||||||
|
if (typeof preferred === 'string') {return preferred}
|
||||||
|
const first = Object.values(map).find((v): v is string => typeof v === 'string')
|
||||||
|
return first ?? null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
async function loadBranding(
|
async function loadBranding(
|
||||||
|
props: BrandingProps,
|
||||||
settingsSlug: string,
|
settingsSlug: string,
|
||||||
nameField: string,
|
nameField: string,
|
||||||
imageField: string,
|
imageField: string,
|
||||||
): Promise<{ name: null | string; url: null | string }> {
|
): Promise<{ name: null | string; url: null | string }> {
|
||||||
|
const { payload } = props
|
||||||
|
if (!payload) {return { name: null, url: null }}
|
||||||
try {
|
try {
|
||||||
// Consumer alias — resolved in the project's build, hidden from plugin tsc.
|
const locale = typeof props.locale === 'string' ? props.locale : props.locale?.code
|
||||||
const spec = '@payload-config'
|
|
||||||
const mod = (await import(spec)) as { default: unknown }
|
|
||||||
const payload = await getPayload({ config: mod.default as never })
|
|
||||||
const settings = (await payload.findGlobal({
|
const settings = (await payload.findGlobal({
|
||||||
slug: settingsSlug as never,
|
slug: settingsSlug as never,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
|
...(locale ? { locale: locale as never } : {}),
|
||||||
})) as Record<string, unknown>
|
})) as Record<string, unknown>
|
||||||
|
|
||||||
const name = typeof settings[nameField] === 'string' ? (settings[nameField]) : null
|
const name = pickText(settings[nameField], locale)
|
||||||
const image = settings[imageField] as MediaLike
|
const image = settings[imageField] as MediaLike
|
||||||
const url =
|
const url =
|
||||||
image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null
|
image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null
|
||||||
return { name, url }
|
return { name, url }
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.warn('[ipal] admin branding: falling back to Payload default:', error)
|
||||||
return { name: null, url: null }
|
return { name: null, url: null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +81,7 @@ async function loadBranding(
|
|||||||
*/
|
*/
|
||||||
export async function AdminLogo(props: BrandingProps = {}) {
|
export async function AdminLogo(props: BrandingProps = {}) {
|
||||||
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props
|
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props
|
||||||
const { name, url } = await loadBranding(settingsSlug, nameField, imageField)
|
const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField)
|
||||||
if (url) {
|
if (url) {
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
@@ -79,7 +98,7 @@ export async function AdminLogo(props: BrandingProps = {}) {
|
|||||||
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */
|
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */
|
||||||
export async function AdminIcon(props: BrandingProps = {}) {
|
export async function AdminIcon(props: BrandingProps = {}) {
|
||||||
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props
|
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props
|
||||||
const { name, url } = await loadBranding(settingsSlug, nameField, imageField)
|
const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField)
|
||||||
if (url) {
|
if (url) {
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
|
|||||||
Reference in New Issue
Block a user