Shared image lightbox: LightboxProvider, LightboxTrigger, LightboxDialog, lightboxImage

Opt-in click-to-enlarge for small images (cards, galleries, rich text):
- /client: LightboxProvider (one viewer per site), LightboxTrigger (button
  around any thumbnail, works without a provider), LightboxDialog
  (controlled viewer), useLightbox / useOptionalLightbox
- accessible dialog: aria-modal, focus trap and return, Esc, arrows,
  Home/End, swipe, counter, caption, scroll lock, reduced motion
- lightboxImage builds src + srcSet from Payload image sizes
- labels: ipalKit({ lightbox: true }) adds Notifications -> Lightbox;
  getNotificationTexts().lightbox and getSiteShell().lightboxTexts,
  English fallbacks otherwise
- RenderRichText lightbox / withLightboxUploads wrap image uploads
- SiteProviders lightbox mounts the provider
- styling from --ipal-lightbox-* variables; unstyled + classNames,
  renderImage, renderDialog, icons, loop overrides
- tests with happy-dom (vitest's pinned optional peer)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-27 14:49:38 +01:00
co-authored by Claude Opus 5.5
parent e53d09b720
commit 476c3ac1df
23 changed files with 1203 additions and 15 deletions
+10 -7
View File
@@ -9,6 +9,7 @@ import type { ConstructionMode } from '../construction/types.js'
import type { PathVisibility } from '../construction/visibility.js'
import type { ArchiveEntries, ContentOption, ResolvedRoute } from '../content/index.js'
import type { I18nConfig } from '../i18n/index.js'
import type { LightboxTexts } from '../lightbox/types.js'
import type { LinkValue, NavItem, ResolvedLink, ResolveLinkHrefOptions, SystemLink } from '../links/index.js'
import type { CreateMcpRouteArgs } from '../mcp/createMcpRoute.js'
import type { FormNotificationTexts } from '../notifications/types.js'
@@ -795,23 +796,22 @@ export function createContentHelpers({
// ── Layout ────────────────────────────────────────────────────────────────
/** Notifications → form texts in this locale (BuilderForm / RenderForm `texts`). */
const getFormTexts = cache(async (locale: string): Promise<FormNotificationTexts> =>
(await getNotificationTexts({ locale, payload: await getCachedPayload() })).form,
)
const getNotifications = cache(async (locale: string) => getNotificationTexts({ locale, payload: await getCachedPayload() }))
const getFormTexts = cache(async (locale: string): Promise<FormNotificationTexts> => (await getNotifications(locale)).form)
/**
* Everything the [locale] layout reads, in one cached call: consent texts,
* analytics IDs, Turnstile site key, site JSON-LD, form texts and Site
* analytics IDs, Turnstile site key, site JSON-LD, form and lightbox texts and Site
* Settings. Feed it to <SiteProviders> (/rsc) — or use the pieces yourself.
*/
const getSiteShell = cache(async (locale: string): Promise<SiteShell> => {
const payload = await getCachedPayload()
const [consent, analytics, turnstile, settings, formTexts] = await Promise.all([
const [consent, analytics, turnstile, settings, notifications] = await Promise.all([
getConsentTexts({ config: needI18n('getSiteShell'), locale, payload, settingsSlug }),
getAnalyticsConfig(payload),
getTurnstileConfig(payload),
getSettings(locale) as Promise<Record<string, unknown>>,
getFormTexts(locale),
getNotifications(locale),
])
let jsonLd: Record<string, unknown>[] = []
if (typeof siteJsonLd === 'function') {
@@ -828,8 +828,9 @@ export function createContentHelpers({
return {
analytics,
consent,
formTexts,
formTexts: notifications.form,
jsonLd: jsonLd.map(({ '@context': _context, ...node }) => node),
lightboxTexts: notifications.lightbox,
settings: settings ?? {},
theme: themeConfigFrom(settings),
turnstileSiteKey: turnstile.siteKey,
@@ -910,6 +911,8 @@ export type SiteShell = {
formTexts: FormNotificationTexts
/** Site-wide nodes (WebSite, Organization…) for <JsonLdGraph>. */
jsonLd: Record<string, unknown>[]
/** Notifications → Lightbox (English fallbacks without ipalKit `lightbox`) — <SiteProviders lightbox> reads it. */
lightboxTexts?: LightboxTexts
settings: Record<string, unknown>
/** Site Settings → Theme, for <ThemeScript> / <SiteProviders theme> and <ThemeSwitcher label>. */
theme: ThemeConfig