diff --git a/dist/exports/rsc.d.ts b/dist/exports/rsc.d.ts index ca8795f..71e4f0c 100644 --- a/dist/exports/rsc.d.ts +++ b/dist/exports/rsc.d.ts @@ -7,4 +7,6 @@ */ export { RenderBlocks } from '../modules/blocks/index.js'; export type { BlockComponentMap, BlockData, EnhanceProps, RenderBlocksProps, } from '../modules/blocks/index.js'; +export { RenderRichText } from '../modules/richtext/index.js'; +export type { RenderRichTextProps } from '../modules/richtext/index.js'; export { MediaPreconnect } from '../modules/storage/MediaPreconnect.js'; diff --git a/dist/exports/rsc.js b/dist/exports/rsc.js index 7be092a..c46658d 100644 --- a/dist/exports/rsc.js +++ b/dist/exports/rsc.js @@ -5,6 +5,7 @@ * lives here rather than in the main package entry to keep React out of the * server-config bundle. */ export { RenderBlocks } from '../modules/blocks/index.js'; +export { RenderRichText } from '../modules/richtext/index.js'; export { MediaPreconnect } from '../modules/storage/MediaPreconnect.js'; //# sourceMappingURL=rsc.js.map \ No newline at end of file diff --git a/dist/exports/rsc.js.map b/dist/exports/rsc.js.map index 0665d19..b336797 100644 --- a/dist/exports/rsc.js.map +++ b/dist/exports/rsc.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["/**\n * Entry point: ipal-kit/rsc\n *\n * Server-component exports. RenderBlocks is a React Server Component, so it\n * lives here rather than in the main package entry to keep React out of the\n * server-config bundle.\n */\nexport { RenderBlocks } from '../modules/blocks/index.js'\nexport type {\n BlockComponentMap,\n BlockData,\n EnhanceProps,\n RenderBlocksProps,\n} from '../modules/blocks/index.js'\nexport { MediaPreconnect } from '../modules/storage/MediaPreconnect.js'\n"],"names":["RenderBlocks","MediaPreconnect"],"mappings":"AAAA;;;;;;CAMC,GACD,SAASA,YAAY,QAAQ,6BAA4B;AAOzD,SAASC,eAAe,QAAQ,wCAAuC"} \ No newline at end of file +{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["/**\n * Entry point: ipal-kit/rsc\n *\n * Server-component exports. RenderBlocks is a React Server Component, so it\n * lives here rather than in the main package entry to keep React out of the\n * server-config bundle.\n */\nexport { RenderBlocks } from '../modules/blocks/index.js'\nexport type {\n BlockComponentMap,\n BlockData,\n EnhanceProps,\n RenderBlocksProps,\n} from '../modules/blocks/index.js'\nexport { RenderRichText } from '../modules/richtext/index.js'\nexport type { RenderRichTextProps } from '../modules/richtext/index.js'\nexport { MediaPreconnect } from '../modules/storage/MediaPreconnect.js'\n"],"names":["RenderBlocks","RenderRichText","MediaPreconnect"],"mappings":"AAAA;;;;;;CAMC,GACD,SAASA,YAAY,QAAQ,6BAA4B;AAOzD,SAASC,cAAc,QAAQ,+BAA8B;AAE7D,SAASC,eAAe,QAAQ,wCAAuC"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 548be3c..f68ddd3 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -23,6 +23,7 @@ export type { I18nConfig, LocaleDefinition, LocalizedSlugs } from './modules/i18 export { buildLocalizedPath, getDefaultLocale, getLocaleCodes, getLocaleDefinition, getLocalizedSlugs, isValidLocale, LOCALE_COOKIE_NAME, matchAcceptLanguage, negotiateLocale, switchLocalePath, } from './modules/i18n/index.js'; export type { LocaleMiddlewareResult } from './modules/i18n/index.js'; export { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './modules/i18n/index.js'; +export { createProxy, DEFAULT_PROXY_MATCHER } from './modules/i18n/index.js'; export { normalizeFilename, normalizeFilenameHook } from './modules/media/index.js'; export { getNotificationTexts, NOTIFICATION_FALLBACK, resolveFormMessage, } from './modules/notifications/index.js'; export type { FormNotificationTexts, NotificationTexts } from './modules/notifications/index.js'; @@ -38,12 +39,13 @@ export type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js'; export { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js'; export type { AutoFillMapping, RobotsRules, SitemapEntry } from './modules/seo/index.js'; export { buildAutoFillMetaHook, buildRobots, buildSitemapEntries, createMetadataGenerator, createPageMetadata, injectAutoFillMeta, } from './modules/seo/index.js'; +export { createLlmsTxtRoute, createManifestHandler, createSitemapRouteHandler, } from './modules/seo/index.js'; export { buildIconsMetadata, buildOrganizationJsonLd, validateFaviconField, } from './modules/seo/index.js'; export { buildBreadcrumbJsonLd, buildSiteNavigationJsonLd, buildWebSiteJsonLd, } from './modules/seo/index.js'; export { buildFaqJsonLd, buildLocalBusinessJsonLd, buildServiceJsonLd, } from './modules/seo/index.js'; export { buildArticleJsonLd } from './modules/seo/index.js'; -export { buildSitemapXml } from './modules/seo/index.js'; export { buildLlmsTxt } from './modules/seo/index.js'; +export { buildSitemapXml } from './modules/seo/index.js'; export { buildSlugField, toSlug } from './modules/slug/index.js'; export { buildR2Storage } from './modules/storage/index.js'; export { ipalKit } from './plugin.js'; diff --git a/dist/index.js b/dist/index.js index 40231c9..471a6a1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14,6 +14,7 @@ export { createContentHelpers } from './modules/frontend/index.js'; export { buildPreventDeleteSystemPage, buildRevalidateHook, buildValidateUniqueRole, setPublishedAtHook, trackSlugHistoryHook } from './modules/hooks/index.js'; export { buildLocalizedPath, getDefaultLocale, getLocaleCodes, getLocaleDefinition, getLocalizedSlugs, isValidLocale, LOCALE_COOKIE_NAME, matchAcceptLanguage, negotiateLocale, switchLocalePath } from './modules/i18n/index.js'; export { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './modules/i18n/index.js'; +export { createProxy, DEFAULT_PROXY_MATCHER } from './modules/i18n/index.js'; export { normalizeFilename, normalizeFilenameHook } from './modules/media/index.js'; export { getNotificationTexts, NOTIFICATION_FALLBACK, resolveFormMessage } from './modules/notifications/index.js'; export { ALL_SYSTEM_PAGE_ROLES, getSystemPagePath } from './modules/pages/index.js'; @@ -22,13 +23,14 @@ export { buildSecurityHeaders } from './modules/security/index.js'; export { buildCsp } from './modules/security/index.js'; export { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js'; export { buildAutoFillMetaHook, buildRobots, buildSitemapEntries, createMetadataGenerator, createPageMetadata, injectAutoFillMeta } from './modules/seo/index.js'; +export { createLlmsTxtRoute, createManifestHandler, createSitemapRouteHandler } from './modules/seo/index.js'; export { buildIconsMetadata, buildOrganizationJsonLd, validateFaviconField } from './modules/seo/index.js'; export { buildBreadcrumbJsonLd, buildSiteNavigationJsonLd, buildWebSiteJsonLd } from './modules/seo/index.js'; // Local SEO structured data — LocalBusiness (map pack), Service (offering), FAQPage. export { buildFaqJsonLd, buildLocalBusinessJsonLd, buildServiceJsonLd } from './modules/seo/index.js'; export { buildArticleJsonLd } from './modules/seo/index.js'; -export { buildSitemapXml } from './modules/seo/index.js'; export { buildLlmsTxt } from './modules/seo/index.js'; +export { buildSitemapXml } from './modules/seo/index.js'; export { buildSlugField, toSlug } from './modules/slug/index.js'; export { buildR2Storage } from './modules/storage/index.js'; export { ipalKit } from './plugin.js'; diff --git a/dist/index.js.map b/dist/index.js.map index 6c7c033..ff4d44b 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type { AccessOption, Role } from './modules/access/index.js'\nexport {\n adminOnly,\n adminOnlyField,\n adminOrEditor,\n adminOrEditorField,\n adminOrSelf,\n authenticated,\n hasMinimumRole,\n isAdmin,\n isEditor,\n requireRole,\n requireRoleField,\n ROLE_HIERARCHY,\n} from './modules/access/index.js'\nexport {\n A11Y_COOKIE,\n A11Y_DEFAULT,\n a11yAttributes,\n parseA11y,\n serializeA11y,\n} from './modules/accessibility/index.js'\nexport type { A11yState } from './modules/accessibility/index.js'\nexport type { AnalyticsConfig } from './modules/analytics/index.js'\nexport { getAnalyticsConfig } from './modules/analytics/index.js'\nexport {\n ACCEPT_ALL_CONSENT,\n CONSENT_CATEGORIES,\n CONSENT_COOKIE,\n CONSENT_MAX_AGE,\n CONSENT_VERSION,\n DEFAULT_CONSENT,\n getConsentTexts,\n parseConsent,\n REJECT_ALL_CONSENT,\n serializeConsent,\n setDefaultConsent,\n updateConsent,\n} from './modules/consent/index.js'\nexport type { ConsentCategory, ConsentState, ConsentTexts } from './modules/consent/index.js'\nexport type {\n ContentCollectionOption,\n ContentOption,\n ResolvedRoute,\n} from './modules/content/index.js'\nexport {\n archiveFieldName,\n buildArchivePath,\n buildEntryPath,\n getArchiveEntries,\n parsePageParam,\n resolveRoute,\n} from './modules/content/index.js'\nexport type { ArchiveEntries } from './modules/content/index.js'\nexport { graphAdapter } from './modules/email/graphAdapter.js'\nexport type { GraphAdapterArgs } from './modules/email/graphAdapter.js'\nexport { mailAdapter } from './modules/email/mailAdapter.js'\nexport type { MailAdapterArgs } from './modules/email/mailAdapter.js'\n// Imported straight from the file, NOT from ./modules/email/index.js — that\n// barrel re-exports sendEmail, which imports 'server-only' and would crash when\n// Payload loads the config (or runs generate:importmap) as a plain Node script.\nexport { panelSmtpAdapter } from './modules/email/panelSmtpAdapter.js'\nexport type { PanelSmtpAdapterArgs } from './modules/email/panelSmtpAdapter.js'\nexport { buildFormsPlugin } from './modules/forms/formsPluginConfig.js'\nexport type {\n FormsCollectionOverrides,\n FormsFieldsOverride,\n FormsOption,\n} from './modules/forms/types.js'\nexport { createContentHelpers } from './modules/frontend/index.js'\nexport {\n buildPreventDeleteSystemPage,\n buildRevalidateHook,\n buildValidateUniqueRole,\n setPublishedAtHook,\n trackSlugHistoryHook,\n} from './modules/hooks/index.js'\nexport type { I18nConfig, LocaleDefinition, LocalizedSlugs } from './modules/i18n/index.js'\nexport {\n buildLocalizedPath,\n getDefaultLocale,\n getLocaleCodes,\n getLocaleDefinition,\n getLocalizedSlugs,\n isValidLocale,\n LOCALE_COOKIE_NAME,\n matchAcceptLanguage,\n negotiateLocale,\n switchLocalePath,\n} from './modules/i18n/index.js'\nexport type { LocaleMiddlewareResult } from './modules/i18n/index.js'\nexport { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './modules/i18n/index.js'\nexport { normalizeFilename, normalizeFilenameHook } from './modules/media/index.js'\nexport {\n getNotificationTexts,\n NOTIFICATION_FALLBACK,\n resolveFormMessage,\n} from './modules/notifications/index.js'\nexport type { FormNotificationTexts, NotificationTexts } from './modules/notifications/index.js'\nexport type { PagesOption, SystemPageRole } from './modules/pages/index.js'\nexport { ALL_SYSTEM_PAGE_ROLES, getSystemPagePath } from './modules/pages/index.js'\nexport type { GlobalQueryOptions } from './modules/payload/index.js'\nexport {\n getGlobal,\n getSiteIntegrations,\n getSiteSettings,\n SITE_INTEGRATIONS_SLUG,\n SITE_SETTINGS_SLUG,\n} from './modules/payload/index.js'\nexport { buildSecurityHeaders } from './modules/security/index.js'\nexport { buildCsp } from './modules/security/index.js'\nexport type { BuildCspArgs } from './modules/security/index.js'\nexport type { BuildSecurityHeadersArgs, SecurityHeader } from './modules/security/index.js'\n\nexport type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js'\nexport { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js'\nexport type { AutoFillMapping, RobotsRules, SitemapEntry } from './modules/seo/index.js'\nexport {\n buildAutoFillMetaHook,\n buildRobots,\n buildSitemapEntries,\n createMetadataGenerator,\n createPageMetadata,\n injectAutoFillMeta,\n} from './modules/seo/index.js'\nexport {\n buildIconsMetadata,\n buildOrganizationJsonLd,\n validateFaviconField,\n} from './modules/seo/index.js'\nexport {\n buildBreadcrumbJsonLd,\n buildSiteNavigationJsonLd,\n buildWebSiteJsonLd,\n} from './modules/seo/index.js'\n// Local SEO structured data — LocalBusiness (map pack), Service (offering), FAQPage.\nexport {\n buildFaqJsonLd,\n buildLocalBusinessJsonLd,\n buildServiceJsonLd,\n} from './modules/seo/index.js'\nexport { buildArticleJsonLd } from './modules/seo/index.js'\nexport { buildSitemapXml } from './modules/seo/index.js'\nexport { buildLlmsTxt } from './modules/seo/index.js'\nexport { buildSlugField, toSlug } from './modules/slug/index.js'\nexport { buildR2Storage } from './modules/storage/index.js'\nexport { ipalKit } from './plugin.js'\nexport type { IpalOptions } from './types.js'\n"],"names":["adminOnly","adminOnlyField","adminOrEditor","adminOrEditorField","adminOrSelf","authenticated","hasMinimumRole","isAdmin","isEditor","requireRole","requireRoleField","ROLE_HIERARCHY","A11Y_COOKIE","A11Y_DEFAULT","a11yAttributes","parseA11y","serializeA11y","getAnalyticsConfig","ACCEPT_ALL_CONSENT","CONSENT_CATEGORIES","CONSENT_COOKIE","CONSENT_MAX_AGE","CONSENT_VERSION","DEFAULT_CONSENT","getConsentTexts","parseConsent","REJECT_ALL_CONSENT","serializeConsent","setDefaultConsent","updateConsent","archiveFieldName","buildArchivePath","buildEntryPath","getArchiveEntries","parsePageParam","resolveRoute","graphAdapter","mailAdapter","panelSmtpAdapter","buildFormsPlugin","createContentHelpers","buildPreventDeleteSystemPage","buildRevalidateHook","buildValidateUniqueRole","setPublishedAtHook","trackSlugHistoryHook","buildLocalizedPath","getDefaultLocale","getLocaleCodes","getLocaleDefinition","getLocalizedSlugs","isValidLocale","LOCALE_COOKIE_NAME","matchAcceptLanguage","negotiateLocale","switchLocalePath","createLocaleMiddleware","DEFAULT_MIDDLEWARE_MATCHER","normalizeFilename","normalizeFilenameHook","getNotificationTexts","NOTIFICATION_FALLBACK","resolveFormMessage","ALL_SYSTEM_PAGE_ROLES","getSystemPagePath","getGlobal","getSiteIntegrations","getSiteSettings","SITE_INTEGRATIONS_SLUG","SITE_SETTINGS_SLUG","buildSecurityHeaders","buildCsp","buildHreflangAlternates","buildMetadata","composeTitle","buildAutoFillMetaHook","buildRobots","buildSitemapEntries","createMetadataGenerator","createPageMetadata","injectAutoFillMeta","buildIconsMetadata","buildOrganizationJsonLd","validateFaviconField","buildBreadcrumbJsonLd","buildSiteNavigationJsonLd","buildWebSiteJsonLd","buildFaqJsonLd","buildLocalBusinessJsonLd","buildServiceJsonLd","buildArticleJsonLd","buildSitemapXml","buildLlmsTxt","buildSlugField","toSlug","buildR2Storage","ipalKit"],"mappings":"AACA,SACEA,SAAS,EACTC,cAAc,EACdC,aAAa,EACbC,kBAAkB,EAClBC,WAAW,EACXC,aAAa,EACbC,cAAc,EACdC,OAAO,EACPC,QAAQ,EACRC,WAAW,EACXC,gBAAgB,EAChBC,cAAc,QACT,4BAA2B;AAClC,SACEC,WAAW,EACXC,YAAY,EACZC,cAAc,EACdC,SAAS,EACTC,aAAa,QACR,mCAAkC;AAGzC,SAASC,kBAAkB,QAAQ,+BAA8B;AACjE,SACEC,kBAAkB,EAClBC,kBAAkB,EAClBC,cAAc,EACdC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,EACjBC,aAAa,QACR,6BAA4B;AAOnC,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,iBAAiB,EACjBC,cAAc,EACdC,YAAY,QACP,6BAA4B;AAEnC,SAASC,YAAY,QAAQ,kCAAiC;AAE9D,SAASC,WAAW,QAAQ,iCAAgC;AAE5D,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,SAASC,gBAAgB,QAAQ,sCAAqC;AAEtE,SAASC,gBAAgB,QAAQ,uCAAsC;AAMvE,SAASC,oBAAoB,QAAQ,8BAA6B;AAClE,SACEC,4BAA4B,EAC5BC,mBAAmB,EACnBC,uBAAuB,EACvBC,kBAAkB,EAClBC,oBAAoB,QACf,2BAA0B;AAEjC,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,cAAc,EACdC,mBAAmB,EACnBC,iBAAiB,EACjBC,aAAa,EACbC,kBAAkB,EAClBC,mBAAmB,EACnBC,eAAe,EACfC,gBAAgB,QACX,0BAAyB;AAEhC,SAASC,sBAAsB,EAAEC,0BAA0B,QAAQ,0BAAyB;AAC5F,SAASC,iBAAiB,EAAEC,qBAAqB,QAAQ,2BAA0B;AACnF,SACEC,oBAAoB,EACpBC,qBAAqB,EACrBC,kBAAkB,QACb,mCAAkC;AAGzC,SAASC,qBAAqB,EAAEC,iBAAiB,QAAQ,2BAA0B;AAEnF,SACEC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,sBAAsB,EACtBC,kBAAkB,QACb,6BAA4B;AACnC,SAASC,oBAAoB,QAAQ,8BAA6B;AAClE,SAASC,QAAQ,QAAQ,8BAA6B;AAKtD,SAASC,uBAAuB,EAAEC,aAAa,EAAEC,YAAY,QAAQ,yBAAwB;AAE7F,SACEC,qBAAqB,EACrBC,WAAW,EACXC,mBAAmB,EACnBC,uBAAuB,EACvBC,kBAAkB,EAClBC,kBAAkB,QACb,yBAAwB;AAC/B,SACEC,kBAAkB,EAClBC,uBAAuB,EACvBC,oBAAoB,QACf,yBAAwB;AAC/B,SACEC,qBAAqB,EACrBC,yBAAyB,EACzBC,kBAAkB,QACb,yBAAwB;AAC/B,qFAAqF;AACrF,SACEC,cAAc,EACdC,wBAAwB,EACxBC,kBAAkB,QACb,yBAAwB;AAC/B,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,eAAe,QAAQ,yBAAwB;AACxD,SAASC,YAAY,QAAQ,yBAAwB;AACrD,SAASC,cAAc,EAAEC,MAAM,QAAQ,0BAAyB;AAChE,SAASC,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,OAAO,QAAQ,cAAa"} \ No newline at end of file +{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type { AccessOption, Role } from './modules/access/index.js'\nexport {\n adminOnly,\n adminOnlyField,\n adminOrEditor,\n adminOrEditorField,\n adminOrSelf,\n authenticated,\n hasMinimumRole,\n isAdmin,\n isEditor,\n requireRole,\n requireRoleField,\n ROLE_HIERARCHY,\n} from './modules/access/index.js'\nexport {\n A11Y_COOKIE,\n A11Y_DEFAULT,\n a11yAttributes,\n parseA11y,\n serializeA11y,\n} from './modules/accessibility/index.js'\nexport type { A11yState } from './modules/accessibility/index.js'\nexport type { AnalyticsConfig } from './modules/analytics/index.js'\nexport { getAnalyticsConfig } from './modules/analytics/index.js'\nexport {\n ACCEPT_ALL_CONSENT,\n CONSENT_CATEGORIES,\n CONSENT_COOKIE,\n CONSENT_MAX_AGE,\n CONSENT_VERSION,\n DEFAULT_CONSENT,\n getConsentTexts,\n parseConsent,\n REJECT_ALL_CONSENT,\n serializeConsent,\n setDefaultConsent,\n updateConsent,\n} from './modules/consent/index.js'\nexport type { ConsentCategory, ConsentState, ConsentTexts } from './modules/consent/index.js'\nexport type {\n ContentCollectionOption,\n ContentOption,\n ResolvedRoute,\n} from './modules/content/index.js'\nexport {\n archiveFieldName,\n buildArchivePath,\n buildEntryPath,\n getArchiveEntries,\n parsePageParam,\n resolveRoute,\n} from './modules/content/index.js'\nexport type { ArchiveEntries } from './modules/content/index.js'\nexport { graphAdapter } from './modules/email/graphAdapter.js'\nexport type { GraphAdapterArgs } from './modules/email/graphAdapter.js'\nexport { mailAdapter } from './modules/email/mailAdapter.js'\nexport type { MailAdapterArgs } from './modules/email/mailAdapter.js'\n// Imported straight from the file, NOT from ./modules/email/index.js — that\n// barrel re-exports sendEmail, which imports 'server-only' and would crash when\n// Payload loads the config (or runs generate:importmap) as a plain Node script.\nexport { panelSmtpAdapter } from './modules/email/panelSmtpAdapter.js'\nexport type { PanelSmtpAdapterArgs } from './modules/email/panelSmtpAdapter.js'\nexport { buildFormsPlugin } from './modules/forms/formsPluginConfig.js'\nexport type {\n FormsCollectionOverrides,\n FormsFieldsOverride,\n FormsOption,\n} from './modules/forms/types.js'\nexport { createContentHelpers } from './modules/frontend/index.js'\nexport {\n buildPreventDeleteSystemPage,\n buildRevalidateHook,\n buildValidateUniqueRole,\n setPublishedAtHook,\n trackSlugHistoryHook,\n} from './modules/hooks/index.js'\nexport type { I18nConfig, LocaleDefinition, LocalizedSlugs } from './modules/i18n/index.js'\nexport {\n buildLocalizedPath,\n getDefaultLocale,\n getLocaleCodes,\n getLocaleDefinition,\n getLocalizedSlugs,\n isValidLocale,\n LOCALE_COOKIE_NAME,\n matchAcceptLanguage,\n negotiateLocale,\n switchLocalePath,\n} from './modules/i18n/index.js'\nexport type { LocaleMiddlewareResult } from './modules/i18n/index.js'\nexport { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './modules/i18n/index.js'\nexport { createProxy, DEFAULT_PROXY_MATCHER } from './modules/i18n/index.js'\nexport { normalizeFilename, normalizeFilenameHook } from './modules/media/index.js'\nexport {\n getNotificationTexts,\n NOTIFICATION_FALLBACK,\n resolveFormMessage,\n} from './modules/notifications/index.js'\nexport type { FormNotificationTexts, NotificationTexts } from './modules/notifications/index.js'\nexport type { PagesOption, SystemPageRole } from './modules/pages/index.js'\nexport { ALL_SYSTEM_PAGE_ROLES, getSystemPagePath } from './modules/pages/index.js'\nexport type { GlobalQueryOptions } from './modules/payload/index.js'\nexport {\n getGlobal,\n getSiteIntegrations,\n getSiteSettings,\n SITE_INTEGRATIONS_SLUG,\n SITE_SETTINGS_SLUG,\n} from './modules/payload/index.js'\nexport { buildSecurityHeaders } from './modules/security/index.js'\nexport { buildCsp } from './modules/security/index.js'\n\nexport type { BuildCspArgs } from './modules/security/index.js'\nexport type { BuildSecurityHeadersArgs, SecurityHeader } from './modules/security/index.js'\nexport type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js'\nexport { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js'\nexport type { AutoFillMapping, RobotsRules, SitemapEntry } from './modules/seo/index.js'\nexport {\n buildAutoFillMetaHook,\n buildRobots,\n buildSitemapEntries,\n createMetadataGenerator,\n createPageMetadata,\n injectAutoFillMeta,\n} from './modules/seo/index.js'\nexport {\n createLlmsTxtRoute,\n createManifestHandler,\n createSitemapRouteHandler,\n} from './modules/seo/index.js'\nexport {\n buildIconsMetadata,\n buildOrganizationJsonLd,\n validateFaviconField,\n} from './modules/seo/index.js'\nexport {\n buildBreadcrumbJsonLd,\n buildSiteNavigationJsonLd,\n buildWebSiteJsonLd,\n} from './modules/seo/index.js'\n// Local SEO structured data — LocalBusiness (map pack), Service (offering), FAQPage.\nexport {\n buildFaqJsonLd,\n buildLocalBusinessJsonLd,\n buildServiceJsonLd,\n} from './modules/seo/index.js'\nexport { buildArticleJsonLd } from './modules/seo/index.js'\nexport { buildLlmsTxt } from './modules/seo/index.js'\nexport { buildSitemapXml } from './modules/seo/index.js'\nexport { buildSlugField, toSlug } from './modules/slug/index.js'\nexport { buildR2Storage } from './modules/storage/index.js'\nexport { ipalKit } from './plugin.js'\nexport type { IpalOptions } from './types.js'\n"],"names":["adminOnly","adminOnlyField","adminOrEditor","adminOrEditorField","adminOrSelf","authenticated","hasMinimumRole","isAdmin","isEditor","requireRole","requireRoleField","ROLE_HIERARCHY","A11Y_COOKIE","A11Y_DEFAULT","a11yAttributes","parseA11y","serializeA11y","getAnalyticsConfig","ACCEPT_ALL_CONSENT","CONSENT_CATEGORIES","CONSENT_COOKIE","CONSENT_MAX_AGE","CONSENT_VERSION","DEFAULT_CONSENT","getConsentTexts","parseConsent","REJECT_ALL_CONSENT","serializeConsent","setDefaultConsent","updateConsent","archiveFieldName","buildArchivePath","buildEntryPath","getArchiveEntries","parsePageParam","resolveRoute","graphAdapter","mailAdapter","panelSmtpAdapter","buildFormsPlugin","createContentHelpers","buildPreventDeleteSystemPage","buildRevalidateHook","buildValidateUniqueRole","setPublishedAtHook","trackSlugHistoryHook","buildLocalizedPath","getDefaultLocale","getLocaleCodes","getLocaleDefinition","getLocalizedSlugs","isValidLocale","LOCALE_COOKIE_NAME","matchAcceptLanguage","negotiateLocale","switchLocalePath","createLocaleMiddleware","DEFAULT_MIDDLEWARE_MATCHER","createProxy","DEFAULT_PROXY_MATCHER","normalizeFilename","normalizeFilenameHook","getNotificationTexts","NOTIFICATION_FALLBACK","resolveFormMessage","ALL_SYSTEM_PAGE_ROLES","getSystemPagePath","getGlobal","getSiteIntegrations","getSiteSettings","SITE_INTEGRATIONS_SLUG","SITE_SETTINGS_SLUG","buildSecurityHeaders","buildCsp","buildHreflangAlternates","buildMetadata","composeTitle","buildAutoFillMetaHook","buildRobots","buildSitemapEntries","createMetadataGenerator","createPageMetadata","injectAutoFillMeta","createLlmsTxtRoute","createManifestHandler","createSitemapRouteHandler","buildIconsMetadata","buildOrganizationJsonLd","validateFaviconField","buildBreadcrumbJsonLd","buildSiteNavigationJsonLd","buildWebSiteJsonLd","buildFaqJsonLd","buildLocalBusinessJsonLd","buildServiceJsonLd","buildArticleJsonLd","buildLlmsTxt","buildSitemapXml","buildSlugField","toSlug","buildR2Storage","ipalKit"],"mappings":"AACA,SACEA,SAAS,EACTC,cAAc,EACdC,aAAa,EACbC,kBAAkB,EAClBC,WAAW,EACXC,aAAa,EACbC,cAAc,EACdC,OAAO,EACPC,QAAQ,EACRC,WAAW,EACXC,gBAAgB,EAChBC,cAAc,QACT,4BAA2B;AAClC,SACEC,WAAW,EACXC,YAAY,EACZC,cAAc,EACdC,SAAS,EACTC,aAAa,QACR,mCAAkC;AAGzC,SAASC,kBAAkB,QAAQ,+BAA8B;AACjE,SACEC,kBAAkB,EAClBC,kBAAkB,EAClBC,cAAc,EACdC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,EACjBC,aAAa,QACR,6BAA4B;AAOnC,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,iBAAiB,EACjBC,cAAc,EACdC,YAAY,QACP,6BAA4B;AAEnC,SAASC,YAAY,QAAQ,kCAAiC;AAE9D,SAASC,WAAW,QAAQ,iCAAgC;AAE5D,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,SAASC,gBAAgB,QAAQ,sCAAqC;AAEtE,SAASC,gBAAgB,QAAQ,uCAAsC;AAMvE,SAASC,oBAAoB,QAAQ,8BAA6B;AAClE,SACEC,4BAA4B,EAC5BC,mBAAmB,EACnBC,uBAAuB,EACvBC,kBAAkB,EAClBC,oBAAoB,QACf,2BAA0B;AAEjC,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,cAAc,EACdC,mBAAmB,EACnBC,iBAAiB,EACjBC,aAAa,EACbC,kBAAkB,EAClBC,mBAAmB,EACnBC,eAAe,EACfC,gBAAgB,QACX,0BAAyB;AAEhC,SAASC,sBAAsB,EAAEC,0BAA0B,QAAQ,0BAAyB;AAC5F,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,0BAAyB;AAC5E,SAASC,iBAAiB,EAAEC,qBAAqB,QAAQ,2BAA0B;AACnF,SACEC,oBAAoB,EACpBC,qBAAqB,EACrBC,kBAAkB,QACb,mCAAkC;AAGzC,SAASC,qBAAqB,EAAEC,iBAAiB,QAAQ,2BAA0B;AAEnF,SACEC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,sBAAsB,EACtBC,kBAAkB,QACb,6BAA4B;AACnC,SAASC,oBAAoB,QAAQ,8BAA6B;AAClE,SAASC,QAAQ,QAAQ,8BAA6B;AAKtD,SAASC,uBAAuB,EAAEC,aAAa,EAAEC,YAAY,QAAQ,yBAAwB;AAE7F,SACEC,qBAAqB,EACrBC,WAAW,EACXC,mBAAmB,EACnBC,uBAAuB,EACvBC,kBAAkB,EAClBC,kBAAkB,QACb,yBAAwB;AAC/B,SACEC,kBAAkB,EAClBC,qBAAqB,EACrBC,yBAAyB,QACpB,yBAAwB;AAC/B,SACEC,kBAAkB,EAClBC,uBAAuB,EACvBC,oBAAoB,QACf,yBAAwB;AAC/B,SACEC,qBAAqB,EACrBC,yBAAyB,EACzBC,kBAAkB,QACb,yBAAwB;AAC/B,qFAAqF;AACrF,SACEC,cAAc,EACdC,wBAAwB,EACxBC,kBAAkB,QACb,yBAAwB;AAC/B,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,YAAY,QAAQ,yBAAwB;AACrD,SAASC,eAAe,QAAQ,yBAAwB;AACxD,SAASC,cAAc,EAAEC,MAAM,QAAQ,0BAAyB;AAChE,SAASC,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,OAAO,QAAQ,cAAa"} \ No newline at end of file diff --git a/dist/modules/consent/CookieBanner.js b/dist/modules/consent/CookieBanner.js index aae002e..57e59bb 100644 --- a/dist/modules/consent/CookieBanner.js +++ b/dist/modules/consent/CookieBanner.js @@ -4,6 +4,7 @@ import { Cookie } from 'lucide-react'; import { useEffect, useState } from 'react'; import { CONSENT_CATEGORIES } from './categories.js'; import { useConsentContext } from './ConsentContext.js'; +import { useIsMounted } from './useIsMounted.js'; /** * Colours and radius come from CSS custom properties with built-in fallbacks, * so the banner looks right with no setup, and re-skinning per client means @@ -36,6 +37,7 @@ const bodyText = 'text-[var(--ipal-text,#404040)] dark:text-[var(--ipal-text-dar const strongText = 'text-[var(--ipal-text-strong,#171717)] dark:text-[var(--ipal-text-strong-dark,#f5f5f5)]'; const mutedText = 'text-[var(--ipal-text-muted,#737373)] dark:text-[var(--ipal-text-muted-dark,#a3a3a3)]'; export function CookieBanner({ classNames } = {}) { + const isMounted = useIsMounted(); const { acceptAll, decided, rejectAll, savePreferences, state, texts } = useConsentContext(); const [showSettings, setShowSettings] = useState(false); const [choices, setChoices] = useState(state); @@ -44,6 +46,12 @@ export function CookieBanner({ classNames } = {}) { }, [ state ]); + // Render nothing until mounted — avoids the React 19 hydration mismatch that + // projects used to work around with a setTimeout ConsentWrapper. No wrapper + // needed now. + if (!isMounted) { + return null; + } if (decided) { return null; } diff --git a/dist/modules/consent/CookieBanner.js.map b/dist/modules/consent/CookieBanner.js.map index f268c1a..83f0e62 100644 --- a/dist/modules/consent/CookieBanner.js.map +++ b/dist/modules/consent/CookieBanner.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/consent/CookieBanner.tsx"],"sourcesContent":["'use client'\nimport { Cookie } from 'lucide-react'\nimport { useEffect, useState } from 'react'\n\nimport { CONSENT_CATEGORIES, type ConsentCategory } from './categories.js'\nimport { useConsentContext } from './ConsentContext.js'\n\n/**\n * Optional class overrides — for when tokens aren't enough, e.g. turning the\n * bottom bar into a centred modal. Replaces the slot's classes outright.\n */\nexport type CookieBannerClassNames = {\n primaryButton?: string\n root?: string\n secondaryButton?: string\n}\n\n/**\n * Colours and radius come from CSS custom properties with built-in fallbacks,\n * so the banner looks right with no setup, and re-skinning per client means\n * declaring a few variables — no imports, no props, no specificity fights:\n *\n * ```css\n * :root {\n * --ipal-primary: #16a34a;\n * --ipal-radius: 1rem;\n * }\n * ```\n *\n * Available: --ipal-surface, --ipal-border, --ipal-text, --ipal-text-strong,\n * --ipal-text-muted, --ipal-primary, --ipal-primary-hover, --ipal-primary-text,\n * --ipal-hover, --ipal-radius. Each has a `-dark` counterpart used under\n * Tailwind's `dark:` variant (e.g. --ipal-surface-dark).\n *\n * Layout stays in Tailwind: spacing and flow aren't things a brand changes, and\n * exposing them as tokens would mean re-inventing CSS one variable at a time.\n */\nconst surface = 'bg-[var(--ipal-surface,#fff)] dark:bg-[var(--ipal-surface-dark,#171717)]'\nconst border = 'border-[var(--ipal-border,#e5e5e5)] dark:border-[var(--ipal-border-dark,#262626)]'\nconst radius = 'rounded-[var(--ipal-radius,0.375rem)]'\nconst accent = 'text-[var(--ipal-primary,#2563eb)]'\n\nconst defaults = {\n primaryButton: `${radius} px-3 py-1.5 text-sm font-medium bg-[var(--ipal-primary,#2563eb)] text-[var(--ipal-primary-text,#fff)] hover:bg-[var(--ipal-primary-hover,#1d4ed8)]`,\n root: `fixed inset-x-0 bottom-0 z-50 border-t p-4 shadow-lg ${surface} ${border}`,\n secondaryButton: `${radius} px-3 py-1.5 text-sm font-medium text-[var(--ipal-text,#404040)] hover:bg-[var(--ipal-hover,#f5f5f5)] dark:text-[var(--ipal-text-dark,#e5e5e5)] dark:hover:bg-[var(--ipal-hover-dark,#262626)]`,\n}\n\nconst bodyText = 'text-[var(--ipal-text,#404040)] dark:text-[var(--ipal-text-dark,#d4d4d4)]'\nconst strongText =\n 'text-[var(--ipal-text-strong,#171717)] dark:text-[var(--ipal-text-strong-dark,#f5f5f5)]'\nconst mutedText =\n 'text-[var(--ipal-text-muted,#737373)] dark:text-[var(--ipal-text-muted-dark,#a3a3a3)]'\n\nexport function CookieBanner({ classNames }: { classNames?: CookieBannerClassNames } = {}) {\n const { acceptAll, decided, rejectAll, savePreferences, state, texts } = useConsentContext()\n const [showSettings, setShowSettings] = useState(false)\n const [choices, setChoices] = useState>(state)\n\n useEffect(() => {\n setChoices(state)\n }, [state])\n\n if (decided) {return null}\n\n const toggle = (cat: ConsentCategory) => {\n if (cat === 'necessary') {return}\n setChoices((prev) => ({ ...prev, [cat]: !prev[cat] }))\n }\n\n const rootClass = classNames?.root ?? defaults.root\n const primaryClass = classNames?.primaryButton ?? defaults.primaryButton\n const secondaryClass = classNames?.secondaryButton ?? defaults.secondaryButton\n\n return (\n
\n
\n {!showSettings ? (\n
\n
\n \n

\n {texts.message}\n {texts.privacyLink && (\n <>\n {' '}\n \n {texts.privacyLink.label}\n \n \n )}\n

\n
\n
\n \n \n \n
\n
\n ) : (\n
\n

\n \n {texts.settingsTitle}\n

\n
    \n {CONSENT_CATEGORIES.map((cat) => (\n
  • \n
    \n

    \n {texts.categories[cat].title}\n

    \n

    {texts.categories[cat].description}

    \n
    \n toggle(cat)}\n type=\"checkbox\"\n />\n
  • \n ))}\n
\n
\n \n \n
\n
\n )}\n
\n
\n )\n}\n"],"names":["Cookie","useEffect","useState","CONSENT_CATEGORIES","useConsentContext","surface","border","radius","accent","defaults","primaryButton","root","secondaryButton","bodyText","strongText","mutedText","CookieBanner","classNames","acceptAll","decided","rejectAll","savePreferences","state","texts","showSettings","setShowSettings","choices","setChoices","toggle","cat","prev","rootClass","primaryClass","secondaryClass","div","aria-label","className","data-ipal","role","aria-hidden","p","message","privacyLink","a","href","label","button","onClick","buttons","settings","reject","h2","settingsTitle","ul","map","li","categories","title","description","input","checked","disabled","onChange","type","back","save"],"mappings":"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"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/consent/CookieBanner.tsx"],"sourcesContent":["'use client'\nimport { Cookie } from 'lucide-react'\nimport { useEffect, useState } from 'react'\n\nimport { CONSENT_CATEGORIES, type ConsentCategory } from './categories.js'\nimport { useConsentContext } from './ConsentContext.js'\nimport { useIsMounted } from './useIsMounted.js'\n\n/**\n * Optional class overrides — for when tokens aren't enough, e.g. turning the\n * bottom bar into a centred modal. Replaces the slot's classes outright.\n */\nexport type CookieBannerClassNames = {\n primaryButton?: string\n root?: string\n secondaryButton?: string\n}\n\n/**\n * Colours and radius come from CSS custom properties with built-in fallbacks,\n * so the banner looks right with no setup, and re-skinning per client means\n * declaring a few variables — no imports, no props, no specificity fights:\n *\n * ```css\n * :root {\n * --ipal-primary: #16a34a;\n * --ipal-radius: 1rem;\n * }\n * ```\n *\n * Available: --ipal-surface, --ipal-border, --ipal-text, --ipal-text-strong,\n * --ipal-text-muted, --ipal-primary, --ipal-primary-hover, --ipal-primary-text,\n * --ipal-hover, --ipal-radius. Each has a `-dark` counterpart used under\n * Tailwind's `dark:` variant (e.g. --ipal-surface-dark).\n *\n * Layout stays in Tailwind: spacing and flow aren't things a brand changes, and\n * exposing them as tokens would mean re-inventing CSS one variable at a time.\n */\nconst surface = 'bg-[var(--ipal-surface,#fff)] dark:bg-[var(--ipal-surface-dark,#171717)]'\nconst border = 'border-[var(--ipal-border,#e5e5e5)] dark:border-[var(--ipal-border-dark,#262626)]'\nconst radius = 'rounded-[var(--ipal-radius,0.375rem)]'\nconst accent = 'text-[var(--ipal-primary,#2563eb)]'\n\nconst defaults = {\n primaryButton: `${radius} px-3 py-1.5 text-sm font-medium bg-[var(--ipal-primary,#2563eb)] text-[var(--ipal-primary-text,#fff)] hover:bg-[var(--ipal-primary-hover,#1d4ed8)]`,\n root: `fixed inset-x-0 bottom-0 z-50 border-t p-4 shadow-lg ${surface} ${border}`,\n secondaryButton: `${radius} px-3 py-1.5 text-sm font-medium text-[var(--ipal-text,#404040)] hover:bg-[var(--ipal-hover,#f5f5f5)] dark:text-[var(--ipal-text-dark,#e5e5e5)] dark:hover:bg-[var(--ipal-hover-dark,#262626)]`,\n}\n\nconst bodyText = 'text-[var(--ipal-text,#404040)] dark:text-[var(--ipal-text-dark,#d4d4d4)]'\nconst strongText =\n 'text-[var(--ipal-text-strong,#171717)] dark:text-[var(--ipal-text-strong-dark,#f5f5f5)]'\nconst mutedText =\n 'text-[var(--ipal-text-muted,#737373)] dark:text-[var(--ipal-text-muted-dark,#a3a3a3)]'\n\nexport function CookieBanner({ classNames }: { classNames?: CookieBannerClassNames } = {}) {\n const isMounted = useIsMounted()\n const { acceptAll, decided, rejectAll, savePreferences, state, texts } = useConsentContext()\n const [showSettings, setShowSettings] = useState(false)\n const [choices, setChoices] = useState>(state)\n\n useEffect(() => {\n setChoices(state)\n }, [state])\n\n // Render nothing until mounted — avoids the React 19 hydration mismatch that\n // projects used to work around with a setTimeout ConsentWrapper. No wrapper\n // needed now.\n if (!isMounted) {return null}\n if (decided) {return null}\n\n const toggle = (cat: ConsentCategory) => {\n if (cat === 'necessary') {return}\n setChoices((prev) => ({ ...prev, [cat]: !prev[cat] }))\n }\n\n const rootClass = classNames?.root ?? defaults.root\n const primaryClass = classNames?.primaryButton ?? defaults.primaryButton\n const secondaryClass = classNames?.secondaryButton ?? defaults.secondaryButton\n\n return (\n
\n
\n {!showSettings ? (\n
\n
\n \n

\n {texts.message}\n {texts.privacyLink && (\n <>\n {' '}\n \n {texts.privacyLink.label}\n \n \n )}\n

\n
\n
\n \n \n \n
\n
\n ) : (\n
\n

\n \n {texts.settingsTitle}\n

\n
    \n {CONSENT_CATEGORIES.map((cat) => (\n
  • \n
    \n

    \n {texts.categories[cat].title}\n

    \n

    {texts.categories[cat].description}

    \n
    \n toggle(cat)}\n type=\"checkbox\"\n />\n
  • \n ))}\n
\n
\n \n \n
\n
\n )}\n
\n
\n )\n}\n"],"names":["Cookie","useEffect","useState","CONSENT_CATEGORIES","useConsentContext","useIsMounted","surface","border","radius","accent","defaults","primaryButton","root","secondaryButton","bodyText","strongText","mutedText","CookieBanner","classNames","isMounted","acceptAll","decided","rejectAll","savePreferences","state","texts","showSettings","setShowSettings","choices","setChoices","toggle","cat","prev","rootClass","primaryClass","secondaryClass","div","aria-label","className","data-ipal","role","aria-hidden","p","message","privacyLink","a","href","label","button","onClick","buttons","settings","reject","h2","settingsTitle","ul","map","li","categories","title","description","input","checked","disabled","onChange","type","back","save"],"mappings":"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"} \ No newline at end of file diff --git a/dist/modules/consent/CookieButton.js b/dist/modules/consent/CookieButton.js index 9b8ec8e..36b2d92 100644 --- a/dist/modules/consent/CookieButton.js +++ b/dist/modules/consent/CookieButton.js @@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime"; import { Cookie } from 'lucide-react'; import { useConsentContext } from './ConsentContext.js'; +import { useIsMounted } from './useIsMounted.js'; /** * Floating "cookie settings" button — lets visitors reopen the consent panel * after deciding (GDPR: withdrawing consent must be as easy as giving it). @@ -12,7 +13,13 @@ import { useConsentContext } from './ConsentContext.js'; * palette applies to both without touching either component. Pass className to * replace the styling outright. */ export function CookieButton({ className } = {}) { + const isMounted = useIsMounted(); const { decided, reopen } = useConsentContext(); + // Render nothing until mounted — prevents hydration mismatch (no project + // ConsentWrapper workaround needed). + if (!isMounted) { + return null; + } if (!decided) { return null; } diff --git a/dist/modules/consent/CookieButton.js.map b/dist/modules/consent/CookieButton.js.map index 42d2f2e..4b60a1e 100644 --- a/dist/modules/consent/CookieButton.js.map +++ b/dist/modules/consent/CookieButton.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/consent/CookieButton.tsx"],"sourcesContent":["'use client'\nimport { Cookie } from 'lucide-react'\n\nimport { useConsentContext } from './ConsentContext.js'\n\n/**\n * Floating \"cookie settings\" button — lets visitors reopen the consent panel\n * after deciding (GDPR: withdrawing consent must be as easy as giving it).\n * Hidden while the banner is showing.\n *\n * Colours follow the same CSS custom properties as CookieBanner\n * (--ipal-surface, --ipal-border, --ipal-hover, --ipal-text), so a client's\n * palette applies to both without touching either component. Pass className to\n * replace the styling outright.\n */\nexport function CookieButton({ className }: { className?: string } = {}) {\n const { decided, reopen } = useConsentContext()\n\n if (!decided) {return null}\n\n const cls =\n className ??\n 'fixed bottom-4 left-4 z-40 flex h-11 w-11 items-center justify-center rounded-full border shadow-md transition-colors ' +\n 'bg-[var(--ipal-surface,#fff)] border-[var(--ipal-border,#e5e5e5)] hover:bg-[var(--ipal-hover,#f5f5f5)] ' +\n 'dark:bg-[var(--ipal-surface-dark,#171717)] dark:border-[var(--ipal-border-dark,#262626)] dark:hover:bg-[var(--ipal-hover-dark,#262626)]'\n\n return (\n \n )\n}\n"],"names":["Cookie","useConsentContext","CookieButton","className","decided","reopen","cls","button","aria-label","data-ipal","onClick","aria-hidden"],"mappings":"AAAA;;AACA,SAASA,MAAM,QAAQ,eAAc;AAErC,SAASC,iBAAiB,QAAQ,sBAAqB;AAEvD;;;;;;;;;CASC,GACD,OAAO,SAASC,aAAa,EAAEC,SAAS,EAA0B,GAAG,CAAC,CAAC;IACrE,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGJ;IAE5B,IAAI,CAACG,SAAS;QAAC,OAAO;IAAI;IAE1B,MAAME,MACJH,aACA,2HACE,4GACA;IAEJ,qBACE,KAACI;QAAOC,cAAW;QAAkBL,WAAWG;QAAKG,aAAU;QAAgBC,SAASL;kBACtF,cAAA,KAACL;YACCW,eAAY;YACZR,WAAU;;;AAIlB"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/consent/CookieButton.tsx"],"sourcesContent":["'use client'\nimport { Cookie } from 'lucide-react'\n\nimport { useConsentContext } from './ConsentContext.js'\nimport { useIsMounted } from './useIsMounted.js'\n\n/**\n * Floating \"cookie settings\" button — lets visitors reopen the consent panel\n * after deciding (GDPR: withdrawing consent must be as easy as giving it).\n * Hidden while the banner is showing.\n *\n * Colours follow the same CSS custom properties as CookieBanner\n * (--ipal-surface, --ipal-border, --ipal-hover, --ipal-text), so a client's\n * palette applies to both without touching either component. Pass className to\n * replace the styling outright.\n */\nexport function CookieButton({ className }: { className?: string } = {}) {\n const isMounted = useIsMounted()\n const { decided, reopen } = useConsentContext()\n\n // Render nothing until mounted — prevents hydration mismatch (no project\n // ConsentWrapper workaround needed).\n if (!isMounted) {return null}\n if (!decided) {return null}\n\n const cls =\n className ??\n 'fixed bottom-4 left-4 z-40 flex h-11 w-11 items-center justify-center rounded-full border shadow-md transition-colors ' +\n 'bg-[var(--ipal-surface,#fff)] border-[var(--ipal-border,#e5e5e5)] hover:bg-[var(--ipal-hover,#f5f5f5)] ' +\n 'dark:bg-[var(--ipal-surface-dark,#171717)] dark:border-[var(--ipal-border-dark,#262626)] dark:hover:bg-[var(--ipal-hover-dark,#262626)]'\n\n return (\n \n )\n}\n"],"names":["Cookie","useConsentContext","useIsMounted","CookieButton","className","isMounted","decided","reopen","cls","button","aria-label","data-ipal","onClick","aria-hidden"],"mappings":"AAAA;;AACA,SAASA,MAAM,QAAQ,eAAc;AAErC,SAASC,iBAAiB,QAAQ,sBAAqB;AACvD,SAASC,YAAY,QAAQ,oBAAmB;AAEhD;;;;;;;;;CASC,GACD,OAAO,SAASC,aAAa,EAAEC,SAAS,EAA0B,GAAG,CAAC,CAAC;IACrE,MAAMC,YAAYH;IAClB,MAAM,EAAEI,OAAO,EAAEC,MAAM,EAAE,GAAGN;IAE5B,yEAAyE;IACzE,qCAAqC;IACrC,IAAI,CAACI,WAAW;QAAC,OAAO;IAAI;IAC5B,IAAI,CAACC,SAAS;QAAC,OAAO;IAAI;IAE1B,MAAME,MACJJ,aACA,2HACE,4GACA;IAEJ,qBACE,KAACK;QAAOC,cAAW;QAAkBN,WAAWI;QAAKG,aAAU;QAAgBC,SAASL;kBACtF,cAAA,KAACP;YACCa,eAAY;YACZT,WAAU;;;AAIlB"} \ No newline at end of file diff --git a/dist/modules/consent/index.d.ts b/dist/modules/consent/index.d.ts index 46883b4..b36f325 100644 --- a/dist/modules/consent/index.d.ts +++ b/dist/modules/consent/index.d.ts @@ -4,3 +4,4 @@ export { getConsentTexts } from './getConsentTexts.js'; export { setDefaultConsent, updateConsent } from './googleConsent.js'; export { CONSENT_COOKIE, CONSENT_MAX_AGE, CONSENT_VERSION, parseConsent, serializeConsent, } from './storage.js'; export type { ConsentTexts } from './texts.js'; +export { useIsMounted } from './useIsMounted.js'; diff --git a/dist/modules/consent/index.js b/dist/modules/consent/index.js index 4ec72b8..44a1529 100644 --- a/dist/modules/consent/index.js +++ b/dist/modules/consent/index.js @@ -5,5 +5,6 @@ export { ACCEPT_ALL_CONSENT, CONSENT_CATEGORIES, DEFAULT_CONSENT, REJECT_ALL_CON export { getConsentTexts } from './getConsentTexts.js'; export { setDefaultConsent, updateConsent } from './googleConsent.js'; export { CONSENT_COOKIE, CONSENT_MAX_AGE, CONSENT_VERSION, parseConsent, serializeConsent } from './storage.js'; +export { useIsMounted } from './useIsMounted.js'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/modules/consent/index.js.map b/dist/modules/consent/index.js.map index c041a2c..2c7a6ce 100644 --- a/dist/modules/consent/index.js.map +++ b/dist/modules/consent/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/consent/index.ts"],"sourcesContent":["// Server-safe exports (logic, types, helper). Client components (banner,\n// provider, hook) are exported separately via ./client to keep the RSC/client\n// boundary clean.\nexport {\n ACCEPT_ALL_CONSENT,\n CONSENT_CATEGORIES,\n DEFAULT_CONSENT,\n REJECT_ALL_CONSENT,\n} from './categories.js'\nexport type { ConsentCategory, ConsentState } from './categories.js'\nexport { getConsentTexts } from './getConsentTexts.js'\nexport { setDefaultConsent, updateConsent } from './googleConsent.js'\nexport {\n CONSENT_COOKIE,\n CONSENT_MAX_AGE,\n CONSENT_VERSION,\n parseConsent,\n serializeConsent,\n} from './storage.js'\nexport type { ConsentTexts } from './texts.js'\n"],"names":["ACCEPT_ALL_CONSENT","CONSENT_CATEGORIES","DEFAULT_CONSENT","REJECT_ALL_CONSENT","getConsentTexts","setDefaultConsent","updateConsent","CONSENT_COOKIE","CONSENT_MAX_AGE","CONSENT_VERSION","parseConsent","serializeConsent"],"mappings":"AAAA,yEAAyE;AACzE,8EAA8E;AAC9E,kBAAkB;AAClB,SACEA,kBAAkB,EAClBC,kBAAkB,EAClBC,eAAe,EACfC,kBAAkB,QACb,kBAAiB;AAExB,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,iBAAiB,EAAEC,aAAa,QAAQ,qBAAoB;AACrE,SACEC,cAAc,EACdC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,gBAAgB,QACX,eAAc"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/consent/index.ts"],"sourcesContent":["// Server-safe exports (logic, types, helper). Client components (banner,\n// provider, hook) are exported separately via ./client to keep the RSC/client\n// boundary clean.\nexport {\n ACCEPT_ALL_CONSENT,\n CONSENT_CATEGORIES,\n DEFAULT_CONSENT,\n REJECT_ALL_CONSENT,\n} from './categories.js'\nexport type { ConsentCategory, ConsentState } from './categories.js'\nexport { getConsentTexts } from './getConsentTexts.js'\nexport { setDefaultConsent, updateConsent } from './googleConsent.js'\nexport {\n CONSENT_COOKIE,\n CONSENT_MAX_AGE,\n CONSENT_VERSION,\n parseConsent,\n serializeConsent,\n} from './storage.js'\nexport type { ConsentTexts } from './texts.js'\nexport { useIsMounted } from './useIsMounted.js'\n"],"names":["ACCEPT_ALL_CONSENT","CONSENT_CATEGORIES","DEFAULT_CONSENT","REJECT_ALL_CONSENT","getConsentTexts","setDefaultConsent","updateConsent","CONSENT_COOKIE","CONSENT_MAX_AGE","CONSENT_VERSION","parseConsent","serializeConsent","useIsMounted"],"mappings":"AAAA,yEAAyE;AACzE,8EAA8E;AAC9E,kBAAkB;AAClB,SACEA,kBAAkB,EAClBC,kBAAkB,EAClBC,eAAe,EACfC,kBAAkB,QACb,kBAAiB;AAExB,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,iBAAiB,EAAEC,aAAa,QAAQ,qBAAoB;AACrE,SACEC,cAAc,EACdC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,gBAAgB,QACX,eAAc;AAErB,SAASC,YAAY,QAAQ,oBAAmB"} \ No newline at end of file diff --git a/dist/modules/consent/useIsMounted.d.ts b/dist/modules/consent/useIsMounted.d.ts new file mode 100644 index 0000000..a247a18 --- /dev/null +++ b/dist/modules/consent/useIsMounted.d.ts @@ -0,0 +1,8 @@ +/** + * Returns true only after the component has mounted on the client. Used to gate + * consent UI (CookieBanner, CookieButton) so it renders nothing during SSR / + * first paint — preventing the React 19 / Next hydration mismatch that projects + * were working around with their own setTimeout-based ConsentWrapper. Built into + * the components now, so no project wrapper is needed. + */ +export declare function useIsMounted(): boolean; diff --git a/dist/modules/consent/useIsMounted.js b/dist/modules/consent/useIsMounted.js new file mode 100644 index 0000000..5811873 --- /dev/null +++ b/dist/modules/consent/useIsMounted.js @@ -0,0 +1,17 @@ +'use client'; +import { useEffect, useState } from 'react'; +/** + * Returns true only after the component has mounted on the client. Used to gate + * consent UI (CookieBanner, CookieButton) so it renders nothing during SSR / + * first paint — preventing the React 19 / Next hydration mismatch that projects + * were working around with their own setTimeout-based ConsentWrapper. Built into + * the components now, so no project wrapper is needed. + */ export function useIsMounted() { + const [mounted, setMounted] = useState(false); + useEffect(()=>{ + setMounted(true); + }, []); + return mounted; +} + +//# sourceMappingURL=useIsMounted.js.map \ No newline at end of file diff --git a/dist/modules/consent/useIsMounted.js.map b/dist/modules/consent/useIsMounted.js.map new file mode 100644 index 0000000..c684728 --- /dev/null +++ b/dist/modules/consent/useIsMounted.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/consent/useIsMounted.ts"],"sourcesContent":["'use client'\nimport { useEffect, useState } from 'react'\n\n/**\n * Returns true only after the component has mounted on the client. Used to gate\n * consent UI (CookieBanner, CookieButton) so it renders nothing during SSR /\n * first paint — preventing the React 19 / Next hydration mismatch that projects\n * were working around with their own setTimeout-based ConsentWrapper. Built into\n * the components now, so no project wrapper is needed.\n */\nexport function useIsMounted(): boolean {\n const [mounted, setMounted] = useState(false)\n useEffect(() => {\n setMounted(true)\n }, [])\n return mounted\n}\n"],"names":["useEffect","useState","useIsMounted","mounted","setMounted"],"mappings":"AAAA;AACA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAE3C;;;;;;CAMC,GACD,OAAO,SAASC;IACd,MAAM,CAACC,SAASC,WAAW,GAAGH,SAAS;IACvCD,UAAU;QACRI,WAAW;IACb,GAAG,EAAE;IACL,OAAOD;AACT"} \ No newline at end of file diff --git a/dist/modules/i18n/createProxy.d.ts b/dist/modules/i18n/createProxy.d.ts new file mode 100644 index 0000000..c3b69ab --- /dev/null +++ b/dist/modules/i18n/createProxy.d.ts @@ -0,0 +1,65 @@ +import type { I18nConfig } from './types.js'; +/** Re-exported so the project's proxy.ts config uses the plugin's matcher. */ +export declare const DEFAULT_PROXY_MATCHER: string[]; +/** + * Minimal structural types — the plugin does NOT import next/server (it's a peer + * dep not present at the plugin's own build time, which would cause TS2307). + * Next's real NextRequest / NextResponse satisfy these shapes at the call site. + */ +type ProxyRequest = { + cookies: { + get: (name: string) => { + value: string; + } | undefined; + }; + headers: Headers; + nextUrl: { + clone: () => URL; + pathname: string; + search: string; + }; + url: string; +}; +type ProxyResponse = { + cookies: { + set: (name: string, value: string, opts?: Record) => void; + }; +}; +/** + * Next's NextResponse constructor, injected by the project (which has next/server + * in scope). The plugin stays free of a next/server import. + */ +type NextResponseLike = { + next: (init?: { + request?: { + headers: Headers; + }; + }) => ProxyResponse; + redirect: (url: string | URL) => ProxyResponse; +}; +type CreateProxyOptions = { + consentCategory?: 'functional' | 'necessary'; + consentCookieName?: string; + cookieName?: string; + /** Expose x-locale / x-pathname request headers to RSC. Default true. */ + exposeHeaders?: boolean; +}; +/** + * Ready-made Next 16 proxy (the former middleware). Wraps the plugin's locale + * logic AND the per-project boilerplate (NextResponse, x-locale / x-pathname + * headers, locale cookie, redirect). The project's proxy.ts becomes a few lines. + * + * `NextResponse` is INJECTED (the plugin never imports next/server — it's a peer + * dep absent at the plugin's build time). The project passes it: + * + * // proxy.ts (Next 16 — NOT middleware.ts) + * import { NextResponse } from 'next/server' + * import { createProxy, DEFAULT_PROXY_MATCHER } from '@intecion/ipal-kit' + * import { i18nConfig } from '@/i18n.config' + * export const proxy = createProxy(i18nConfig, { NextResponse }) + * export const config = { matcher: DEFAULT_PROXY_MATCHER } + */ +export declare function createProxy(config: I18nConfig, deps: { + NextResponse: NextResponseLike; +} & CreateProxyOptions): (request: ProxyRequest) => ProxyResponse; +export {}; diff --git a/dist/modules/i18n/createProxy.js b/dist/modules/i18n/createProxy.js new file mode 100644 index 0000000..9971135 --- /dev/null +++ b/dist/modules/i18n/createProxy.js @@ -0,0 +1,49 @@ +import { isValidLocale } from './helpers.js'; +import { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js'; +/** Re-exported so the project's proxy.ts config uses the plugin's matcher. */ export const DEFAULT_PROXY_MATCHER = DEFAULT_MIDDLEWARE_MATCHER; +/** + * Ready-made Next 16 proxy (the former middleware). Wraps the plugin's locale + * logic AND the per-project boilerplate (NextResponse, x-locale / x-pathname + * headers, locale cookie, redirect). The project's proxy.ts becomes a few lines. + * + * `NextResponse` is INJECTED (the plugin never imports next/server — it's a peer + * dep absent at the plugin's build time). The project passes it: + * + * // proxy.ts (Next 16 — NOT middleware.ts) + * import { NextResponse } from 'next/server' + * import { createProxy, DEFAULT_PROXY_MATCHER } from '@intecion/ipal-kit' + * import { i18nConfig } from '@/i18n.config' + * export const proxy = createProxy(i18nConfig, { NextResponse }) + * export const config = { matcher: DEFAULT_PROXY_MATCHER } + */ export function createProxy(config, deps) { + const { exposeHeaders = true, NextResponse, ...mwOptions } = deps; + const run = createLocaleMiddleware({ + config, + ...mwOptions + }); + return (request)=>{ + const result = run(request); + const requestHeaders = new Headers(request.headers); + if (exposeHeaders) { + const { pathname } = request.nextUrl; + const seg = pathname.split('/').filter(Boolean)[0] ?? ''; + const locale = isValidLocale(seg, config) ? seg : config.defaultLocale; + requestHeaders.set('x-locale', locale); + requestHeaders.set('x-pathname', pathname); + } + const response = result.type === 'redirect' ? NextResponse.redirect(new URL(result.location, request.url)) : NextResponse.next({ + request: { + headers: requestHeaders + } + }); + if (result.cookie) { + response.cookies.set(result.cookie.name, result.cookie.value, { + path: '/', + sameSite: 'lax' + }); + } + return response; + }; +} + +//# sourceMappingURL=createProxy.js.map \ No newline at end of file diff --git a/dist/modules/i18n/createProxy.js.map b/dist/modules/i18n/createProxy.js.map new file mode 100644 index 0000000..83037b1 --- /dev/null +++ b/dist/modules/i18n/createProxy.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/i18n/createProxy.ts"],"sourcesContent":["import type { I18nConfig } from './types.js'\n\nimport { isValidLocale } from './helpers.js'\nimport { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js'\n\n/** Re-exported so the project's proxy.ts config uses the plugin's matcher. */\nexport const DEFAULT_PROXY_MATCHER = DEFAULT_MIDDLEWARE_MATCHER\n\n/**\n * Minimal structural types — the plugin does NOT import next/server (it's a peer\n * dep not present at the plugin's own build time, which would cause TS2307).\n * Next's real NextRequest / NextResponse satisfy these shapes at the call site.\n */\ntype ProxyRequest = {\n cookies: { get: (name: string) => { value: string } | undefined }\n // Matches localeMiddleware's MiddlewareRequest shape; a real NextRequest\n // satisfies all of this structurally.\n headers: Headers\n nextUrl: { clone: () => URL; pathname: string; search: string }\n url: string\n}\n\ntype ProxyResponse = {\n cookies: { set: (name: string, value: string, opts?: Record) => void }\n}\n\n/**\n * Next's NextResponse constructor, injected by the project (which has next/server\n * in scope). The plugin stays free of a next/server import.\n */\ntype NextResponseLike = {\n next: (init?: { request?: { headers: Headers } }) => ProxyResponse\n redirect: (url: string | URL) => ProxyResponse\n}\n\ntype CreateProxyOptions = {\n consentCategory?: 'functional' | 'necessary'\n consentCookieName?: string\n cookieName?: string\n /** Expose x-locale / x-pathname request headers to RSC. Default true. */\n exposeHeaders?: boolean\n}\n\n/**\n * Ready-made Next 16 proxy (the former middleware). Wraps the plugin's locale\n * logic AND the per-project boilerplate (NextResponse, x-locale / x-pathname\n * headers, locale cookie, redirect). The project's proxy.ts becomes a few lines.\n *\n * `NextResponse` is INJECTED (the plugin never imports next/server — it's a peer\n * dep absent at the plugin's build time). The project passes it:\n *\n * // proxy.ts (Next 16 — NOT middleware.ts)\n * import { NextResponse } from 'next/server'\n * import { createProxy, DEFAULT_PROXY_MATCHER } from '@intecion/ipal-kit'\n * import { i18nConfig } from '@/i18n.config'\n * export const proxy = createProxy(i18nConfig, { NextResponse })\n * export const config = { matcher: DEFAULT_PROXY_MATCHER }\n */\nexport function createProxy(\n config: I18nConfig,\n deps: { NextResponse: NextResponseLike } & CreateProxyOptions,\n): (request: ProxyRequest) => ProxyResponse {\n const { exposeHeaders = true, NextResponse, ...mwOptions } = deps\n const run = createLocaleMiddleware({ config, ...mwOptions })\n\n return (request: ProxyRequest): ProxyResponse => {\n const result = run(request)\n\n const requestHeaders = new Headers(request.headers)\n if (exposeHeaders) {\n const { pathname } = request.nextUrl\n const seg = pathname.split('/').filter(Boolean)[0] ?? ''\n const locale = isValidLocale(seg, config) ? seg : config.defaultLocale\n requestHeaders.set('x-locale', locale)\n requestHeaders.set('x-pathname', pathname)\n }\n\n const response =\n result.type === 'redirect'\n ? NextResponse.redirect(new URL(result.location, request.url))\n : NextResponse.next({ request: { headers: requestHeaders } })\n\n if (result.cookie) {\n response.cookies.set(result.cookie.name, result.cookie.value, {\n path: '/',\n sameSite: 'lax',\n })\n }\n\n return response\n }\n}\n"],"names":["isValidLocale","createLocaleMiddleware","DEFAULT_MIDDLEWARE_MATCHER","DEFAULT_PROXY_MATCHER","createProxy","config","deps","exposeHeaders","NextResponse","mwOptions","run","request","result","requestHeaders","Headers","headers","pathname","nextUrl","seg","split","filter","Boolean","locale","defaultLocale","set","response","type","redirect","URL","location","url","next","cookie","cookies","name","value","path","sameSite"],"mappings":"AAEA,SAASA,aAAa,QAAQ,eAAc;AAC5C,SAASC,sBAAsB,EAAEC,0BAA0B,QAAQ,wBAAuB;AAE1F,4EAA4E,GAC5E,OAAO,MAAMC,wBAAwBD,2BAA0B;AAqC/D;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASE,YACdC,MAAkB,EAClBC,IAA6D;IAE7D,MAAM,EAAEC,gBAAgB,IAAI,EAAEC,YAAY,EAAE,GAAGC,WAAW,GAAGH;IAC7D,MAAMI,MAAMT,uBAAuB;QAAEI;QAAQ,GAAGI,SAAS;IAAC;IAE1D,OAAO,CAACE;QACN,MAAMC,SAASF,IAAIC;QAEnB,MAAME,iBAAiB,IAAIC,QAAQH,QAAQI,OAAO;QAClD,IAAIR,eAAe;YACjB,MAAM,EAAES,QAAQ,EAAE,GAAGL,QAAQM,OAAO;YACpC,MAAMC,MAAMF,SAASG,KAAK,CAAC,KAAKC,MAAM,CAACC,QAAQ,CAAC,EAAE,IAAI;YACtD,MAAMC,SAAStB,cAAckB,KAAKb,UAAUa,MAAMb,OAAOkB,aAAa;YACtEV,eAAeW,GAAG,CAAC,YAAYF;YAC/BT,eAAeW,GAAG,CAAC,cAAcR;QACnC;QAEA,MAAMS,WACJb,OAAOc,IAAI,KAAK,aACZlB,aAAamB,QAAQ,CAAC,IAAIC,IAAIhB,OAAOiB,QAAQ,EAAElB,QAAQmB,GAAG,KAC1DtB,aAAauB,IAAI,CAAC;YAAEpB,SAAS;gBAAEI,SAASF;YAAe;QAAE;QAE/D,IAAID,OAAOoB,MAAM,EAAE;YACjBP,SAASQ,OAAO,CAACT,GAAG,CAACZ,OAAOoB,MAAM,CAACE,IAAI,EAAEtB,OAAOoB,MAAM,CAACG,KAAK,EAAE;gBAC5DC,MAAM;gBACNC,UAAU;YACZ;QACF;QAEA,OAAOZ;IACT;AACF"} \ No newline at end of file diff --git a/dist/modules/i18n/index.d.ts b/dist/modules/i18n/index.d.ts index 2db9940..a8a4c11 100644 --- a/dist/modules/i18n/index.d.ts +++ b/dist/modules/i18n/index.d.ts @@ -1,3 +1,4 @@ +export { createProxy, DEFAULT_PROXY_MATCHER } from './createProxy.js'; export { getLocalizedSlugs } from './getLocalizedSlugs.js'; export { getDefaultLocale, getLocaleCodes, getLocaleDefinition, isValidLocale } from './helpers.js'; export { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js'; diff --git a/dist/modules/i18n/index.js b/dist/modules/i18n/index.js index 6dbd28a..bba2e5f 100644 --- a/dist/modules/i18n/index.js +++ b/dist/modules/i18n/index.js @@ -1,3 +1,4 @@ +export { createProxy, DEFAULT_PROXY_MATCHER } from './createProxy.js'; export { getLocalizedSlugs } from './getLocalizedSlugs.js'; export { getDefaultLocale, getLocaleCodes, getLocaleDefinition, isValidLocale } from './helpers.js'; export { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js'; diff --git a/dist/modules/i18n/index.js.map b/dist/modules/i18n/index.js.map index 9708da6..9812ae8 100644 --- a/dist/modules/i18n/index.js.map +++ b/dist/modules/i18n/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/i18n/index.ts"],"sourcesContent":["export { getLocalizedSlugs } from './getLocalizedSlugs.js'\nexport { getDefaultLocale, getLocaleCodes, getLocaleDefinition, isValidLocale } from './helpers.js'\nexport { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js'\nexport type { LocaleMiddlewareResult } from './localeMiddleware.js'\nexport { buildLocalizationConfig } from './localizationConfig.js'\nexport { buildLocalizedPath, switchLocalePath } from './localizedPath.js'\nexport type { LocalizedSlugs } from './localizedPath.js'\nexport { LOCALE_COOKIE_NAME, matchAcceptLanguage, negotiateLocale } from './negotiateLocale.js'\nexport type { I18nConfig, LocaleDefinition } from './types.js'\nexport { validateI18nConfig } from './validation.js'\n"],"names":["getLocalizedSlugs","getDefaultLocale","getLocaleCodes","getLocaleDefinition","isValidLocale","createLocaleMiddleware","DEFAULT_MIDDLEWARE_MATCHER","buildLocalizationConfig","buildLocalizedPath","switchLocalePath","LOCALE_COOKIE_NAME","matchAcceptLanguage","negotiateLocale","validateI18nConfig"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,aAAa,QAAQ,eAAc;AACnG,SAASC,sBAAsB,EAAEC,0BAA0B,QAAQ,wBAAuB;AAE1F,SAASC,uBAAuB,QAAQ,0BAAyB;AACjE,SAASC,kBAAkB,EAAEC,gBAAgB,QAAQ,qBAAoB;AAEzE,SAASC,kBAAkB,EAAEC,mBAAmB,EAAEC,eAAe,QAAQ,uBAAsB;AAE/F,SAASC,kBAAkB,QAAQ,kBAAiB"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/i18n/index.ts"],"sourcesContent":["export { createProxy, DEFAULT_PROXY_MATCHER } from './createProxy.js'\nexport { getLocalizedSlugs } from './getLocalizedSlugs.js'\nexport { getDefaultLocale, getLocaleCodes, getLocaleDefinition, isValidLocale } from './helpers.js'\nexport { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js'\nexport type { LocaleMiddlewareResult } from './localeMiddleware.js'\nexport { buildLocalizationConfig } from './localizationConfig.js'\nexport { buildLocalizedPath, switchLocalePath } from './localizedPath.js'\nexport type { LocalizedSlugs } from './localizedPath.js'\nexport { LOCALE_COOKIE_NAME, matchAcceptLanguage, negotiateLocale } from './negotiateLocale.js'\nexport type { I18nConfig, LocaleDefinition } from './types.js'\nexport { validateI18nConfig } from './validation.js'\n"],"names":["createProxy","DEFAULT_PROXY_MATCHER","getLocalizedSlugs","getDefaultLocale","getLocaleCodes","getLocaleDefinition","isValidLocale","createLocaleMiddleware","DEFAULT_MIDDLEWARE_MATCHER","buildLocalizationConfig","buildLocalizedPath","switchLocalePath","LOCALE_COOKIE_NAME","matchAcceptLanguage","negotiateLocale","validateI18nConfig"],"mappings":"AAAA,SAASA,WAAW,EAAEC,qBAAqB,QAAQ,mBAAkB;AACrE,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,aAAa,QAAQ,eAAc;AACnG,SAASC,sBAAsB,EAAEC,0BAA0B,QAAQ,wBAAuB;AAE1F,SAASC,uBAAuB,QAAQ,0BAAyB;AACjE,SAASC,kBAAkB,EAAEC,gBAAgB,QAAQ,qBAAoB;AAEzE,SAASC,kBAAkB,EAAEC,mBAAmB,EAAEC,eAAe,QAAQ,uBAAsB;AAE/F,SAASC,kBAAkB,QAAQ,kBAAiB"} \ No newline at end of file diff --git a/dist/modules/richtext/RenderRichText.d.ts b/dist/modules/richtext/RenderRichText.d.ts new file mode 100644 index 0000000..cbe916c --- /dev/null +++ b/dist/modules/richtext/RenderRichText.d.ts @@ -0,0 +1,48 @@ +import type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical'; +import type { JSXConvertersFunction } from '@payloadcms/richtext-lexical/react'; +export type RenderRichTextProps = { + /** Wrapper class (e.g. Tailwind prose classes). */ + className?: string; + /** + * Override the JSX for specific node types to apply the project's own + * styling. Receives Payload's defaultConverters; return the merged map. + * This is where a project puts its Tailwind classes per node (headings, + * paragraphs, links, …) — the design stays in the project, the parsing in + * the plugin's wrapper over Payload's official converter. + */ + converters?: JSXConvertersFunction; + /** + * Lexical editor state from a Payload richText field. Already localized — + * Payload returns the current locale's value, so NO per-locale key handling + * is needed here (unlike hand-rolled renderers that hardcode `.pl`). + */ + data: null | SerializedEditorState | undefined; +}; +/** + * Renders a Payload Lexical richText field to React — a thin wrapper over + * Payload's OFFICIAL converter (@payloadcms/richtext-lexical/react). + * + * Why not hand-roll it: parsing Lexical by hand (node.type switch, node.format + * bit flags) duplicates what Payload already does, misses node types, drifts + * on Lexical updates, and tempts shortcuts like dangerouslySetInnerHTML (XSS) + * or a hardcoded `.pl` locale. The official converter handles every node, + * stays in sync, and is safe. This is the RenderBlocks of rich text: the + * plugin owns the engine, the project owns the look via `converters`. + * + * // project — a Server Component + * import { RenderRichText } from '@intecion/ipal-kit/rsc' + * + * + * // with project styling per node: + * const converters: JSXConvertersFunction = ({ defaultConverters }) => ({ + * ...defaultConverters, + * heading: ({ node, nodesToJSX }) => { + * const children = nodesToJSX({ nodes: node.children }) + * const cls = { h2: 'text-2xl font-semibold mt-10', h3: 'text-xl mt-7' }[node.tag] ?? '' + * const Tag = node.tag as 'h1'|'h2'|'h3'|'h4' + * return {children} + * }, + * }) + * + */ +export declare function RenderRichText({ className, converters, data }: RenderRichTextProps): import("react/jsx-runtime").JSX.Element | null; diff --git a/dist/modules/richtext/RenderRichText.js b/dist/modules/richtext/RenderRichText.js new file mode 100644 index 0000000..cbf9e52 --- /dev/null +++ b/dist/modules/richtext/RenderRichText.js @@ -0,0 +1,40 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +import { RichText as PayloadRichText } from '@payloadcms/richtext-lexical/react'; +/** + * Renders a Payload Lexical richText field to React — a thin wrapper over + * Payload's OFFICIAL converter (@payloadcms/richtext-lexical/react). + * + * Why not hand-roll it: parsing Lexical by hand (node.type switch, node.format + * bit flags) duplicates what Payload already does, misses node types, drifts + * on Lexical updates, and tempts shortcuts like dangerouslySetInnerHTML (XSS) + * or a hardcoded `.pl` locale. The official converter handles every node, + * stays in sync, and is safe. This is the RenderBlocks of rich text: the + * plugin owns the engine, the project owns the look via `converters`. + * + * // project — a Server Component + * import { RenderRichText } from '@intecion/ipal-kit/rsc' + * + * + * // with project styling per node: + * const converters: JSXConvertersFunction = ({ defaultConverters }) => ({ + * ...defaultConverters, + * heading: ({ node, nodesToJSX }) => { + * const children = nodesToJSX({ nodes: node.children }) + * const cls = { h2: 'text-2xl font-semibold mt-10', h3: 'text-xl mt-7' }[node.tag] ?? '' + * const Tag = node.tag as 'h1'|'h2'|'h3'|'h4' + * return {children} + * }, + * }) + * + */ export function RenderRichText({ className, converters, data }) { + if (!data) { + return null; + } + return /*#__PURE__*/ _jsx(PayloadRichText, { + className: className, + converters: converters, + data: data + }); +} + +//# sourceMappingURL=RenderRichText.js.map \ No newline at end of file diff --git a/dist/modules/richtext/RenderRichText.js.map b/dist/modules/richtext/RenderRichText.js.map new file mode 100644 index 0000000..802ebce --- /dev/null +++ b/dist/modules/richtext/RenderRichText.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/richtext/RenderRichText.tsx"],"sourcesContent":["import type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical'\nimport type { JSXConvertersFunction } from '@payloadcms/richtext-lexical/react'\n\nimport { RichText as PayloadRichText } from '@payloadcms/richtext-lexical/react'\n\nexport type RenderRichTextProps = {\n /** Wrapper class (e.g. Tailwind prose classes). */\n className?: string\n /**\n * Override the JSX for specific node types to apply the project's own\n * styling. Receives Payload's defaultConverters; return the merged map.\n * This is where a project puts its Tailwind classes per node (headings,\n * paragraphs, links, …) — the design stays in the project, the parsing in\n * the plugin's wrapper over Payload's official converter.\n */\n converters?: JSXConvertersFunction\n /**\n * Lexical editor state from a Payload richText field. Already localized —\n * Payload returns the current locale's value, so NO per-locale key handling\n * is needed here (unlike hand-rolled renderers that hardcode `.pl`).\n */\n data: null | SerializedEditorState | undefined\n}\n\n/**\n * Renders a Payload Lexical richText field to React — a thin wrapper over\n * Payload's OFFICIAL converter (@payloadcms/richtext-lexical/react).\n *\n * Why not hand-roll it: parsing Lexical by hand (node.type switch, node.format\n * bit flags) duplicates what Payload already does, misses node types, drifts\n * on Lexical updates, and tempts shortcuts like dangerouslySetInnerHTML (XSS)\n * or a hardcoded `.pl` locale. The official converter handles every node,\n * stays in sync, and is safe. This is the RenderBlocks of rich text: the\n * plugin owns the engine, the project owns the look via `converters`.\n *\n * // project — a Server Component\n * import { RenderRichText } from '@intecion/ipal-kit/rsc'\n * \n *\n * // with project styling per node:\n * const converters: JSXConvertersFunction = ({ defaultConverters }) => ({\n * ...defaultConverters,\n * heading: ({ node, nodesToJSX }) => {\n * const children = nodesToJSX({ nodes: node.children })\n * const cls = { h2: 'text-2xl font-semibold mt-10', h3: 'text-xl mt-7' }[node.tag] ?? ''\n * const Tag = node.tag as 'h1'|'h2'|'h3'|'h4'\n * return {children}\n * },\n * })\n * \n */\nexport function RenderRichText({ className, converters, data }: RenderRichTextProps) {\n if (!data) {return null}\n return \n}\n"],"names":["RichText","PayloadRichText","RenderRichText","className","converters","data"],"mappings":";AAGA,SAASA,YAAYC,eAAe,QAAQ,qCAAoC;AAqBhF;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASC,eAAe,EAAEC,SAAS,EAAEC,UAAU,EAAEC,IAAI,EAAuB;IACjF,IAAI,CAACA,MAAM;QAAC,OAAO;IAAI;IACvB,qBAAO,KAACJ;QAAgBE,WAAWA;QAAWC,YAAYA;QAAYC,MAAMA;;AAC9E"} \ No newline at end of file diff --git a/dist/modules/richtext/index.d.ts b/dist/modules/richtext/index.d.ts new file mode 100644 index 0000000..00ca01e --- /dev/null +++ b/dist/modules/richtext/index.d.ts @@ -0,0 +1,2 @@ +export { RenderRichText } from './RenderRichText.js'; +export type { RenderRichTextProps } from './RenderRichText.js'; diff --git a/dist/modules/richtext/index.js b/dist/modules/richtext/index.js new file mode 100644 index 0000000..9a4d947 --- /dev/null +++ b/dist/modules/richtext/index.js @@ -0,0 +1,3 @@ +export { RenderRichText } from './RenderRichText.js'; + +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/modules/richtext/index.js.map b/dist/modules/richtext/index.js.map new file mode 100644 index 0000000..393d8d2 --- /dev/null +++ b/dist/modules/richtext/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/richtext/index.ts"],"sourcesContent":["export { RenderRichText } from './RenderRichText.js'\nexport type { RenderRichTextProps } from './RenderRichText.js'\n"],"names":["RenderRichText"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAqB"} \ No newline at end of file diff --git a/dist/modules/seo/buildManifest.d.ts b/dist/modules/seo/buildManifest.d.ts new file mode 100644 index 0000000..7f413c2 --- /dev/null +++ b/dist/modules/seo/buildManifest.d.ts @@ -0,0 +1,33 @@ +import type { BasePayload } from 'payload'; +import type { I18nConfig } from '../i18n/index.js'; +type ManifestIcon = { + sizes?: string; + src: string; + type?: string; +}; +type Manifest = { + background_color?: string; + display: 'standalone'; + icons: ManifestIcon[]; + name?: string; + short_name?: string; + start_url: string; + theme_color?: string; +}; +/** + * Builds a Next Web App Manifest from SiteSettings — replaces the ~50 lines of + * icon/mimeType parsing copied into every project's manifest.ts. Values come + * from the panel; missing fields are omitted (no hardcoded client data). + * + * // app/manifest.ts + * import { createManifestHandler } from '@intecion/ipal-kit' + * import { getCachedPayload } from '@/lib/content' + * import { i18nConfig } from '@/i18n.config' + * export default createManifestHandler({ getCachedPayload, config: i18nConfig }) + */ +export declare function createManifestHandler(opts: { + config: I18nConfig; + getCachedPayload: () => Promise; + settingsSlug?: string; +}): () => Promise; +export {}; diff --git a/dist/modules/seo/buildManifest.js b/dist/modules/seo/buildManifest.js new file mode 100644 index 0000000..074ac0c --- /dev/null +++ b/dist/modules/seo/buildManifest.js @@ -0,0 +1,65 @@ +import { getDefaultLocale } from '../i18n/index.js'; +/** + * Builds a Next Web App Manifest from SiteSettings — replaces the ~50 lines of + * icon/mimeType parsing copied into every project's manifest.ts. Values come + * from the panel; missing fields are omitted (no hardcoded client data). + * + * // app/manifest.ts + * import { createManifestHandler } from '@intecion/ipal-kit' + * import { getCachedPayload } from '@/lib/content' + * import { i18nConfig } from '@/i18n.config' + * export default createManifestHandler({ getCachedPayload, config: i18nConfig }) + */ export function createManifestHandler(opts) { + return async ()=>{ + const defaultLocale = getDefaultLocale(opts.config); + const payload = await opts.getCachedPayload(); + const settings = await payload.findGlobal({ + slug: opts.settingsSlug ?? 'site-settings', + depth: 1, + locale: defaultLocale + }).catch(()=>null); + const start_url = `/${defaultLocale}`; + if (!settings) { + return { + display: 'standalone', + icons: [], + start_url + }; + } + const iconSource = settings.favicon ?? settings.logo; + const icons = []; + if (iconSource?.url) { + const type = iconSource.mimeType ?? (iconSource.url.endsWith('.svg') ? 'image/svg+xml' : undefined); + const isSvg = type === 'image/svg+xml'; + const size = iconSource.width && iconSource.height ? `${iconSource.width}x${iconSource.height}` : undefined; + icons.push({ + src: iconSource.url, + ...isSvg ? { + sizes: 'any' + } : size ? { + sizes: size + } : {}, + ...type ? { + type + } : {} + }); + } + return { + ...settings.siteName ? { + name: settings.siteName, + short_name: settings.siteName + } : {}, + display: 'standalone', + start_url, + ...settings.backgroundColor ? { + background_color: settings.backgroundColor + } : {}, + ...settings.themeColor ? { + theme_color: settings.themeColor + } : {}, + icons + }; + }; +} + +//# sourceMappingURL=buildManifest.js.map \ No newline at end of file diff --git a/dist/modules/seo/buildManifest.js.map b/dist/modules/seo/buildManifest.js.map new file mode 100644 index 0000000..3347cfa --- /dev/null +++ b/dist/modules/seo/buildManifest.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/seo/buildManifest.ts"],"sourcesContent":["import type { BasePayload } from 'payload'\n\nimport type { I18nConfig } from '../i18n/index.js'\n\nimport { getDefaultLocale } from '../i18n/index.js'\n\ntype MediaLike =\n | { height?: null | number; mimeType?: null | string; url?: null | string; width?: null | number }\n | null\n | undefined\n\ntype ManifestIcon = { sizes?: string; src: string; type?: string }\n\ntype Manifest = {\n background_color?: string\n display: 'standalone'\n icons: ManifestIcon[]\n name?: string\n short_name?: string\n start_url: string\n theme_color?: string\n}\n\ntype SettingsShape = {\n backgroundColor?: null | string\n favicon?: MediaLike\n logo?: MediaLike\n siteName?: null | string\n themeColor?: null | string\n}\n\n/**\n * Builds a Next Web App Manifest from SiteSettings — replaces the ~50 lines of\n * icon/mimeType parsing copied into every project's manifest.ts. Values come\n * from the panel; missing fields are omitted (no hardcoded client data).\n *\n * // app/manifest.ts\n * import { createManifestHandler } from '@intecion/ipal-kit'\n * import { getCachedPayload } from '@/lib/content'\n * import { i18nConfig } from '@/i18n.config'\n * export default createManifestHandler({ getCachedPayload, config: i18nConfig })\n */\nexport function createManifestHandler(opts: {\n config: I18nConfig\n getCachedPayload: () => Promise\n settingsSlug?: string\n}): () => Promise {\n return async () => {\n const defaultLocale = getDefaultLocale(opts.config)\n const payload = await opts.getCachedPayload()\n const settings = (await payload\n .findGlobal({\n slug: (opts.settingsSlug ?? 'site-settings') as never,\n depth: 1,\n locale: defaultLocale as never,\n })\n .catch(() => null)) as null | SettingsShape\n\n const start_url = `/${defaultLocale}`\n if (!settings) {\n return { display: 'standalone', icons: [], start_url }\n }\n\n const iconSource = settings.favicon ?? settings.logo\n const icons: ManifestIcon[] = []\n if (iconSource?.url) {\n const type =\n iconSource.mimeType ?? (iconSource.url.endsWith('.svg') ? 'image/svg+xml' : undefined)\n const isSvg = type === 'image/svg+xml'\n const size =\n iconSource.width && iconSource.height\n ? `${iconSource.width}x${iconSource.height}`\n : undefined\n icons.push({\n src: iconSource.url,\n ...(isSvg ? { sizes: 'any' } : size ? { sizes: size } : {}),\n ...(type ? { type } : {}),\n })\n }\n\n return {\n ...(settings.siteName ? { name: settings.siteName, short_name: settings.siteName } : {}),\n display: 'standalone',\n start_url,\n ...(settings.backgroundColor ? { background_color: settings.backgroundColor } : {}),\n ...(settings.themeColor ? { theme_color: settings.themeColor } : {}),\n icons,\n }\n }\n}\n"],"names":["getDefaultLocale","createManifestHandler","opts","defaultLocale","config","payload","getCachedPayload","settings","findGlobal","slug","settingsSlug","depth","locale","catch","start_url","display","icons","iconSource","favicon","logo","url","type","mimeType","endsWith","undefined","isSvg","size","width","height","push","src","sizes","siteName","name","short_name","backgroundColor","background_color","themeColor","theme_color"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,mBAAkB;AA2BnD;;;;;;;;;;CAUC,GACD,OAAO,SAASC,sBAAsBC,IAIrC;IACC,OAAO;QACL,MAAMC,gBAAgBH,iBAAiBE,KAAKE,MAAM;QAClD,MAAMC,UAAU,MAAMH,KAAKI,gBAAgB;QAC3C,MAAMC,WAAY,MAAMF,QACrBG,UAAU,CAAC;YACVC,MAAOP,KAAKQ,YAAY,IAAI;YAC5BC,OAAO;YACPC,QAAQT;QACV,GACCU,KAAK,CAAC,IAAM;QAEf,MAAMC,YAAY,CAAC,CAAC,EAAEX,eAAe;QACrC,IAAI,CAACI,UAAU;YACb,OAAO;gBAAEQ,SAAS;gBAAcC,OAAO,EAAE;gBAAEF;YAAU;QACvD;QAEA,MAAMG,aAAaV,SAASW,OAAO,IAAIX,SAASY,IAAI;QACpD,MAAMH,QAAwB,EAAE;QAChC,IAAIC,YAAYG,KAAK;YACnB,MAAMC,OACJJ,WAAWK,QAAQ,IAAKL,CAAAA,WAAWG,GAAG,CAACG,QAAQ,CAAC,UAAU,kBAAkBC,SAAQ;YACtF,MAAMC,QAAQJ,SAAS;YACvB,MAAMK,OACJT,WAAWU,KAAK,IAAIV,WAAWW,MAAM,GACjC,GAAGX,WAAWU,KAAK,CAAC,CAAC,EAAEV,WAAWW,MAAM,EAAE,GAC1CJ;YACNR,MAAMa,IAAI,CAAC;gBACTC,KAAKb,WAAWG,GAAG;gBACnB,GAAIK,QAAQ;oBAAEM,OAAO;gBAAM,IAAIL,OAAO;oBAAEK,OAAOL;gBAAK,IAAI,CAAC,CAAC;gBAC1D,GAAIL,OAAO;oBAAEA;gBAAK,IAAI,CAAC,CAAC;YAC1B;QACF;QAEA,OAAO;YACL,GAAId,SAASyB,QAAQ,GAAG;gBAAEC,MAAM1B,SAASyB,QAAQ;gBAAEE,YAAY3B,SAASyB,QAAQ;YAAC,IAAI,CAAC,CAAC;YACvFjB,SAAS;YACTD;YACA,GAAIP,SAAS4B,eAAe,GAAG;gBAAEC,kBAAkB7B,SAAS4B,eAAe;YAAC,IAAI,CAAC,CAAC;YAClF,GAAI5B,SAAS8B,UAAU,GAAG;gBAAEC,aAAa/B,SAAS8B,UAAU;YAAC,IAAI,CAAC,CAAC;YACnErB;QACF;IACF;AACF"} \ No newline at end of file diff --git a/dist/modules/seo/index.d.ts b/dist/modules/seo/index.d.ts index 1046bc6..bcc544d 100644 --- a/dist/modules/seo/index.d.ts +++ b/dist/modules/seo/index.d.ts @@ -6,6 +6,7 @@ export { buildFaqJsonLd } from './buildFaqJsonLd.js'; export { buildIconsMetadata } from './buildIconsMetadata.js'; export { buildLlmsTxt } from './buildLlmsTxt.js'; export { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'; +export { createManifestHandler } from './buildManifest.js'; export { buildMetadata } from './buildMetadata.js'; export type { PageMetadata } from './buildMetadata.js'; export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'; @@ -26,6 +27,7 @@ export { injectAutoFillMeta } from './injectAutoFillMeta.js'; export { injectSeoTabs } from './injectSeoTabs.js'; export { readSiteMetaConfig } from './readSiteMetaConfig.js'; export type { SiteMetaConfig } from './readSiteMetaConfig.js'; +export { createLlmsTxtRoute, createSitemapRouteHandler } from './routeHandlers.js'; export { buildSeoPlugin } from './seoPluginConfig.js'; export { slugsAcrossLocales } from './slugsAcrossLocales.js'; export type { SeoMeta, SeoOption } from './types.js'; diff --git a/dist/modules/seo/index.js b/dist/modules/seo/index.js index 3be7324..1250a7e 100644 --- a/dist/modules/seo/index.js +++ b/dist/modules/seo/index.js @@ -5,6 +5,7 @@ export { buildFaqJsonLd } from './buildFaqJsonLd.js'; export { buildIconsMetadata } from './buildIconsMetadata.js'; export { buildLlmsTxt } from './buildLlmsTxt.js'; export { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'; +export { createManifestHandler } from './buildManifest.js'; export { buildMetadata } from './buildMetadata.js'; export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'; export { buildRobots } from './buildRobots.js'; @@ -20,6 +21,7 @@ export { buildHreflangAlternates } from './hreflang.js'; export { injectAutoFillMeta } from './injectAutoFillMeta.js'; export { injectSeoTabs } from './injectSeoTabs.js'; export { readSiteMetaConfig } from './readSiteMetaConfig.js'; +export { createLlmsTxtRoute, createSitemapRouteHandler } from './routeHandlers.js'; export { buildSeoPlugin } from './seoPluginConfig.js'; export { slugsAcrossLocales } from './slugsAcrossLocales.js'; export { validateFaviconField } from './validateFavicon.js'; diff --git a/dist/modules/seo/index.js.map b/dist/modules/seo/index.js.map index 7789036..d8f1f93 100644 --- a/dist/modules/seo/index.js.map +++ b/dist/modules/seo/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/seo/index.ts"],"sourcesContent":["export { buildAutoFillMetaHook } from './autoFillMeta.js'\nexport type { AutoFillMapping } from './autoFillMeta.js'\nexport { buildArticleJsonLd } from './buildArticleJsonLd.js'\nexport { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.js'\nexport { buildFaqJsonLd } from './buildFaqJsonLd.js'\nexport { buildIconsMetadata } from './buildIconsMetadata.js'\nexport { buildLlmsTxt } from './buildLlmsTxt.js'\nexport { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'\nexport { buildMetadata } from './buildMetadata.js'\nexport type { PageMetadata } from './buildMetadata.js'\nexport { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'\nexport { buildRobots } from './buildRobots.js'\nexport type { RobotsRules } from './buildRobots.js'\nexport { buildServiceJsonLd } from './buildServiceJsonLd.js'\nexport { buildSitemapEntries } from './buildSitemapEntries.js'\nexport type { SitemapEntry } from './buildSitemapEntries.js'\nexport { buildSitemapXml } from './buildSitemapXml.js'\nexport { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js'\nexport { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js'\nexport { composeTitle } from './composeTitle.js'\nexport type { TitleOrder } from './composeTitle.js'\nexport { createMetadataGenerator } from './createMetadataGenerator.js'\nexport { createPageMetadata } from './createPageMetadata.js'\nexport { buildHreflangAlternates } from './hreflang.js'\nexport { injectAutoFillMeta } from './injectAutoFillMeta.js'\nexport { injectSeoTabs } from './injectSeoTabs.js'\nexport { readSiteMetaConfig } from './readSiteMetaConfig.js'\nexport type { SiteMetaConfig } from './readSiteMetaConfig.js'\nexport { buildSeoPlugin } from './seoPluginConfig.js'\nexport { slugsAcrossLocales } from './slugsAcrossLocales.js'\nexport type { SeoMeta, SeoOption } from './types.js'\nexport { validateFaviconField } from './validateFavicon.js'\n"],"names":["buildAutoFillMetaHook","buildArticleJsonLd","buildBreadcrumbJsonLd","buildFaqJsonLd","buildIconsMetadata","buildLlmsTxt","buildLocalBusinessJsonLd","buildMetadata","buildOrganizationJsonLd","buildRobots","buildServiceJsonLd","buildSitemapEntries","buildSitemapXml","buildSiteNavigationJsonLd","buildWebSiteJsonLd","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","readSiteMetaConfig","buildSeoPlugin","slugsAcrossLocales","validateFaviconField"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oBAAmB;AAEzD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,aAAa,QAAQ,qBAAoB;AAElD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,oBAAoB,QAAQ,uBAAsB"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/seo/index.ts"],"sourcesContent":["export { buildAutoFillMetaHook } from './autoFillMeta.js'\nexport type { AutoFillMapping } from './autoFillMeta.js'\nexport { buildArticleJsonLd } from './buildArticleJsonLd.js'\nexport { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.js'\nexport { buildFaqJsonLd } from './buildFaqJsonLd.js'\nexport { buildIconsMetadata } from './buildIconsMetadata.js'\nexport { buildLlmsTxt } from './buildLlmsTxt.js'\nexport { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'\nexport { createManifestHandler } from './buildManifest.js'\nexport { buildMetadata } from './buildMetadata.js'\nexport type { PageMetadata } from './buildMetadata.js'\nexport { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'\nexport { buildRobots } from './buildRobots.js'\nexport type { RobotsRules } from './buildRobots.js'\nexport { buildServiceJsonLd } from './buildServiceJsonLd.js'\nexport { buildSitemapEntries } from './buildSitemapEntries.js'\nexport type { SitemapEntry } from './buildSitemapEntries.js'\nexport { buildSitemapXml } from './buildSitemapXml.js'\nexport { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js'\nexport { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js'\nexport { composeTitle } from './composeTitle.js'\nexport type { TitleOrder } from './composeTitle.js'\nexport { createMetadataGenerator } from './createMetadataGenerator.js'\nexport { createPageMetadata } from './createPageMetadata.js'\nexport { buildHreflangAlternates } from './hreflang.js'\nexport { injectAutoFillMeta } from './injectAutoFillMeta.js'\nexport { injectSeoTabs } from './injectSeoTabs.js'\nexport { readSiteMetaConfig } from './readSiteMetaConfig.js'\nexport type { SiteMetaConfig } from './readSiteMetaConfig.js'\nexport { createLlmsTxtRoute, createSitemapRouteHandler } from './routeHandlers.js'\nexport { buildSeoPlugin } from './seoPluginConfig.js'\nexport { slugsAcrossLocales } from './slugsAcrossLocales.js'\nexport type { SeoMeta, SeoOption } from './types.js'\nexport { validateFaviconField } from './validateFavicon.js'\n"],"names":["buildAutoFillMetaHook","buildArticleJsonLd","buildBreadcrumbJsonLd","buildFaqJsonLd","buildIconsMetadata","buildLlmsTxt","buildLocalBusinessJsonLd","createManifestHandler","buildMetadata","buildOrganizationJsonLd","buildRobots","buildServiceJsonLd","buildSitemapEntries","buildSitemapXml","buildSiteNavigationJsonLd","buildWebSiteJsonLd","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","readSiteMetaConfig","createLlmsTxtRoute","createSitemapRouteHandler","buildSeoPlugin","slugsAcrossLocales","validateFaviconField"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oBAAmB;AAEzD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,aAAa,QAAQ,qBAAoB;AAElD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,kBAAkB,EAAEC,yBAAyB,QAAQ,qBAAoB;AAClF,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,oBAAoB,QAAQ,uBAAsB"} \ No newline at end of file diff --git a/dist/modules/seo/routeHandlers.d.ts b/dist/modules/seo/routeHandlers.d.ts new file mode 100644 index 0000000..09c52b9 --- /dev/null +++ b/dist/modules/seo/routeHandlers.d.ts @@ -0,0 +1,40 @@ +import type { BasePayload } from 'payload'; +import type { I18nConfig } from '../i18n/index.js'; +import type { SitemapEntry } from './buildSitemapEntries.js'; +/** + * Ready-made Next route handler for /llms.txt. Replaces the ~60-line try/catch + * every project was copying. buildLlmsTxt already handles collections without + * drafts, so no workaround is needed here. + * + * // app/llms.txt/route.ts + * import { createLlmsTxtRoute } from '@intecion/ipal-kit' + * import { getCachedPayload } from '@/lib/content' + * import { i18nConfig } from '@/i18n.config' + * export const dynamic = 'force-dynamic' + * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig, + * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! }) + */ +export declare function createLlmsTxtRoute(opts: { + baseUrl: string; + config: I18nConfig; + getCachedPayload: () => Promise; + pagesSlug?: string; + settingsSlug?: string; +}): () => Promise; +/** + * Ready-made Next route handler for /sitemap.xml with the CSS stylesheet. + * Replaces the hand-written route in every project. Pass the project's `sitemap` + * helper (from createContentHelpers) and optionally a cssUrl. + * + * // app/sitemap.xml/route.ts + * import { createSitemapRouteHandler } from '@intecion/ipal-kit' + * import { sitemap } from '@/lib/content' + * export const dynamic = 'force-dynamic' + * export const GET = createSitemapRouteHandler(sitemap, { cssUrl: '/sitemap.css' }) + * + * Remember: if you use this, DON'T also keep app/sitemap.ts (two sitemaps + * confuse crawlers). + */ +export declare function createSitemapRouteHandler(sitemap: () => Promise, opts?: { + cssUrl?: string; +}): () => Promise; diff --git a/dist/modules/seo/routeHandlers.js b/dist/modules/seo/routeHandlers.js new file mode 100644 index 0000000..04fdfa6 --- /dev/null +++ b/dist/modules/seo/routeHandlers.js @@ -0,0 +1,81 @@ +import { buildLlmsTxt } from './buildLlmsTxt.js'; +import { buildSitemapXml } from './buildSitemapXml.js'; +/** + * Ready-made Next route handler for /llms.txt. Replaces the ~60-line try/catch + * every project was copying. buildLlmsTxt already handles collections without + * drafts, so no workaround is needed here. + * + * // app/llms.txt/route.ts + * import { createLlmsTxtRoute } from '@intecion/ipal-kit' + * import { getCachedPayload } from '@/lib/content' + * import { i18nConfig } from '@/i18n.config' + * export const dynamic = 'force-dynamic' + * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig, + * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! }) + */ export function createLlmsTxtRoute(opts) { + return async ()=>{ + try { + const payload = await opts.getCachedPayload(); + const body = await buildLlmsTxt({ + baseUrl: opts.baseUrl, + config: opts.config, + pagesSlug: opts.pagesSlug, + payload, + settingsSlug: opts.settingsSlug + }); + return new Response(body, { + headers: { + 'Content-Type': 'text/plain; charset=utf-8' + } + }); + } catch (err) { + // DB unreachable at build (container) — return a minimal valid file so the + // route doesn't 500; it fills in at runtime. No per-project try/catch. + console.warn('[ipal] createLlmsTxtRoute: could not build llms.txt:', err); + return new Response('# llms.txt\n', { + headers: { + 'Content-Type': 'text/plain; charset=utf-8' + } + }); + } + }; +} +/** + * Ready-made Next route handler for /sitemap.xml with the CSS stylesheet. + * Replaces the hand-written route in every project. Pass the project's `sitemap` + * helper (from createContentHelpers) and optionally a cssUrl. + * + * // app/sitemap.xml/route.ts + * import { createSitemapRouteHandler } from '@intecion/ipal-kit' + * import { sitemap } from '@/lib/content' + * export const dynamic = 'force-dynamic' + * export const GET = createSitemapRouteHandler(sitemap, { cssUrl: '/sitemap.css' }) + * + * Remember: if you use this, DON'T also keep app/sitemap.ts (two sitemaps + * confuse crawlers). + */ export function createSitemapRouteHandler(sitemap, opts = {}) { + return async ()=>{ + try { + const entries = await sitemap(); + const xml = buildSitemapXml(entries, { + cssUrl: opts.cssUrl + }); + return new Response(xml, { + headers: { + 'Content-Type': 'application/xml; charset=utf-8' + } + }); + } catch (err) { + console.warn('[ipal] createSitemapRouteHandler: could not build sitemap:', err); + // Valid empty urlset so the route doesn't 500 during a DB-less build. + const empty = '\n' + ''; + return new Response(empty, { + headers: { + 'Content-Type': 'application/xml; charset=utf-8' + } + }); + } + }; +} + +//# sourceMappingURL=routeHandlers.js.map \ No newline at end of file diff --git a/dist/modules/seo/routeHandlers.js.map b/dist/modules/seo/routeHandlers.js.map new file mode 100644 index 0000000..8448dd8 --- /dev/null +++ b/dist/modules/seo/routeHandlers.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/seo/routeHandlers.ts"],"sourcesContent":["import type { BasePayload } from 'payload'\n\nimport type { I18nConfig } from '../i18n/index.js'\nimport type { SitemapEntry } from './buildSitemapEntries.js'\n\nimport { buildLlmsTxt } from './buildLlmsTxt.js'\nimport { buildSitemapXml } from './buildSitemapXml.js'\n\n/**\n * Ready-made Next route handler for /llms.txt. Replaces the ~60-line try/catch\n * every project was copying. buildLlmsTxt already handles collections without\n * drafts, so no workaround is needed here.\n *\n * // app/llms.txt/route.ts\n * import { createLlmsTxtRoute } from '@intecion/ipal-kit'\n * import { getCachedPayload } from '@/lib/content'\n * import { i18nConfig } from '@/i18n.config'\n * export const dynamic = 'force-dynamic'\n * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,\n * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! })\n */\nexport function createLlmsTxtRoute(opts: {\n baseUrl: string\n config: I18nConfig\n getCachedPayload: () => Promise\n pagesSlug?: string\n settingsSlug?: string\n}): () => Promise {\n return async () => {\n try {\n const payload = await opts.getCachedPayload()\n const body = await buildLlmsTxt({\n baseUrl: opts.baseUrl,\n config: opts.config,\n pagesSlug: opts.pagesSlug,\n payload,\n settingsSlug: opts.settingsSlug,\n })\n return new Response(body, {\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n } catch (err) {\n // DB unreachable at build (container) — return a minimal valid file so the\n // route doesn't 500; it fills in at runtime. No per-project try/catch.\n console.warn('[ipal] createLlmsTxtRoute: could not build llms.txt:', err)\n return new Response('# llms.txt\\n', {\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n }\n }\n}\n\n/**\n * Ready-made Next route handler for /sitemap.xml with the CSS stylesheet.\n * Replaces the hand-written route in every project. Pass the project's `sitemap`\n * helper (from createContentHelpers) and optionally a cssUrl.\n *\n * // app/sitemap.xml/route.ts\n * import { createSitemapRouteHandler } from '@intecion/ipal-kit'\n * import { sitemap } from '@/lib/content'\n * export const dynamic = 'force-dynamic'\n * export const GET = createSitemapRouteHandler(sitemap, { cssUrl: '/sitemap.css' })\n *\n * Remember: if you use this, DON'T also keep app/sitemap.ts (two sitemaps\n * confuse crawlers).\n */\nexport function createSitemapRouteHandler(\n sitemap: () => Promise,\n opts: { cssUrl?: string } = {},\n): () => Promise {\n return async () => {\n try {\n const entries = await sitemap()\n const xml = buildSitemapXml(entries, { cssUrl: opts.cssUrl })\n return new Response(xml, {\n headers: { 'Content-Type': 'application/xml; charset=utf-8' },\n })\n } catch (err) {\n console.warn('[ipal] createSitemapRouteHandler: could not build sitemap:', err)\n // Valid empty urlset so the route doesn't 500 during a DB-less build.\n const empty =\n '\\n' +\n ''\n return new Response(empty, {\n headers: { 'Content-Type': 'application/xml; charset=utf-8' },\n })\n }\n }\n}\n"],"names":["buildLlmsTxt","buildSitemapXml","createLlmsTxtRoute","opts","payload","getCachedPayload","body","baseUrl","config","pagesSlug","settingsSlug","Response","headers","err","console","warn","createSitemapRouteHandler","sitemap","entries","xml","cssUrl","empty"],"mappings":"AAKA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,eAAe,QAAQ,uBAAsB;AAEtD;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,mBAAmBC,IAMlC;IACC,OAAO;QACL,IAAI;YACF,MAAMC,UAAU,MAAMD,KAAKE,gBAAgB;YAC3C,MAAMC,OAAO,MAAMN,aAAa;gBAC9BO,SAASJ,KAAKI,OAAO;gBACrBC,QAAQL,KAAKK,MAAM;gBACnBC,WAAWN,KAAKM,SAAS;gBACzBL;gBACAM,cAAcP,KAAKO,YAAY;YACjC;YACA,OAAO,IAAIC,SAASL,MAAM;gBACxBM,SAAS;oBAAE,gBAAgB;gBAA4B;YACzD;QACF,EAAE,OAAOC,KAAK;YACZ,2EAA2E;YAC3E,uEAAuE;YACvEC,QAAQC,IAAI,CAAC,wDAAwDF;YACrE,OAAO,IAAIF,SAAS,gBAAgB;gBAClCC,SAAS;oBAAE,gBAAgB;gBAA4B;YACzD;QACF;IACF;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASI,0BACdC,OAAsC,EACtCd,OAA4B,CAAC,CAAC;IAE9B,OAAO;QACL,IAAI;YACF,MAAMe,UAAU,MAAMD;YACtB,MAAME,MAAMlB,gBAAgBiB,SAAS;gBAAEE,QAAQjB,KAAKiB,MAAM;YAAC;YAC3D,OAAO,IAAIT,SAASQ,KAAK;gBACvBP,SAAS;oBAAE,gBAAgB;gBAAiC;YAC9D;QACF,EAAE,OAAOC,KAAK;YACZC,QAAQC,IAAI,CAAC,8DAA8DF;YAC3E,sEAAsE;YACtE,MAAMQ,QACJ,6CACA;YACF,OAAO,IAAIV,SAASU,OAAO;gBACzBT,SAAS;oBAAE,gBAAgB;gBAAiC;YAC9D;QACF;IACF;AACF"} \ No newline at end of file diff --git a/docs/richtext.md b/docs/richtext.md new file mode 100644 index 0000000..2eb3640 --- /dev/null +++ b/docs/richtext.md @@ -0,0 +1,68 @@ +# Rich text (Lexical) — RenderRichText + +Renderowanie pól `richText` (edytor Lexical) na froncie. Plugin dostarcza +`RenderRichText` — cienki wrapper nad OFICJALNYM konwerterem Payload +(`@payloadcms/richtext-lexical/react`). To RenderBlocks rich textu: plugin +dostarcza silnik, projekt dostarcza wygląd. + +> **NIGDY nie pisz własnego renderera Lexical** (switch po `node.type`, flagi +> bitowe `node.format & 1`). To powiela to, co Payload już robi, pomija typy +> węzłów, rozjeżdża się przy aktualizacjach Lexical i kusi do +> `dangerouslySetInnerHTML` (XSS) oraz hardkodu locale (`.pl`). Użyj +> RenderRichText. + +## Podstawowe użycie (RSC) + +```tsx +import { RenderRichText } from '@intecion/ipal-kit/rsc' + + +``` + +`data` to pole richText z dokumentu — JUŻ zlokalizowane (Payload zwraca wartość +bieżącego locale). Zero obsługi kluczy per język, zero hardkodu `.pl`. + +## Własne style per węzeł (converters) + +Styl zostaje w projekcie (Tailwind), parsowanie w pluginie. Nadpisujesz JSX +konkretnych węzłów przez `converters`: + +```tsx +import { RenderRichText } from '@intecion/ipal-kit/rsc' +import type { JSXConvertersFunction } from '@payloadcms/richtext-lexical/react' + +const converters: JSXConvertersFunction = ({ defaultConverters }) => ({ + ...defaultConverters, + heading: ({ node, nodesToJSX }) => { + const children = nodesToJSX({ nodes: node.children }) + const cls: Record = { + h2: 'font-display text-2xl font-semibold mt-10 mb-4', + h3: 'font-display text-xl font-semibold mt-7 mb-3', + } + const Tag = node.tag as 'h1' | 'h2' | 'h3' | 'h4' + return {children} + }, + paragraph: ({ node, nodesToJSX }) => ( +

{nodesToJSX({ nodes: node.children })}

+ ), +}) + + +``` + +Spread `defaultConverters` — nadpisujesz tylko te węzły, które chcesz. Reszta +(listy, tabele, obrazy, linki) działa z oficjalnej obsługi Payload. + +## Zależność + +Oficjalny konwerter jest częścią `@payloadcms/richtext-lexical`, które projekt +Payload już ma (to edytor). Zero dodatkowych zależności. + +## Czego to unika (vs ręczny renderer) + +- **XSS** — brak `dangerouslySetInnerHTML` +- **Hardkod locale** — brak `val.alt.pl` (dane już zlokalizowane) +- **Brakujące węzły** — oficjalny konwerter obsługuje wszystkie (zagnieżdżone + listy, upload, relacje, horizontal rule…) +- **Rozjazd przy aktualizacji** — Payload utrzymuje konwerter, nie Ty +- **`any`** — typowane (SerializedEditorState) \ No newline at end of file diff --git a/src/exports/rsc.ts b/src/exports/rsc.ts index eab8730..d3915b7 100644 --- a/src/exports/rsc.ts +++ b/src/exports/rsc.ts @@ -12,4 +12,6 @@ export type { EnhanceProps, RenderBlocksProps, } from '../modules/blocks/index.js' +export { RenderRichText } from '../modules/richtext/index.js' +export type { RenderRichTextProps } from '../modules/richtext/index.js' export { MediaPreconnect } from '../modules/storage/MediaPreconnect.js' diff --git a/src/index.ts b/src/index.ts index 1825477..479d2a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,6 +90,7 @@ export { } from './modules/i18n/index.js' export type { LocaleMiddlewareResult } from './modules/i18n/index.js' export { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './modules/i18n/index.js' +export { createProxy, DEFAULT_PROXY_MATCHER } from './modules/i18n/index.js' export { normalizeFilename, normalizeFilenameHook } from './modules/media/index.js' export { getNotificationTexts, @@ -109,9 +110,9 @@ export { } from './modules/payload/index.js' export { buildSecurityHeaders } from './modules/security/index.js' export { buildCsp } from './modules/security/index.js' + export type { BuildCspArgs } from './modules/security/index.js' export type { BuildSecurityHeadersArgs, SecurityHeader } from './modules/security/index.js' - export type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js' export { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js' export type { AutoFillMapping, RobotsRules, SitemapEntry } from './modules/seo/index.js' @@ -123,6 +124,11 @@ export { createPageMetadata, injectAutoFillMeta, } from './modules/seo/index.js' +export { + createLlmsTxtRoute, + createManifestHandler, + createSitemapRouteHandler, +} from './modules/seo/index.js' export { buildIconsMetadata, buildOrganizationJsonLd, @@ -140,8 +146,8 @@ export { buildServiceJsonLd, } from './modules/seo/index.js' export { buildArticleJsonLd } from './modules/seo/index.js' -export { buildSitemapXml } from './modules/seo/index.js' export { buildLlmsTxt } from './modules/seo/index.js' +export { buildSitemapXml } from './modules/seo/index.js' export { buildSlugField, toSlug } from './modules/slug/index.js' export { buildR2Storage } from './modules/storage/index.js' export { ipalKit } from './plugin.js' diff --git a/src/modules/consent/CookieBanner.tsx b/src/modules/consent/CookieBanner.tsx index b6242b6..1e03752 100644 --- a/src/modules/consent/CookieBanner.tsx +++ b/src/modules/consent/CookieBanner.tsx @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react' import { CONSENT_CATEGORIES, type ConsentCategory } from './categories.js' import { useConsentContext } from './ConsentContext.js' +import { useIsMounted } from './useIsMounted.js' /** * Optional class overrides — for when tokens aren't enough, e.g. turning the @@ -53,6 +54,7 @@ const mutedText = 'text-[var(--ipal-text-muted,#737373)] dark:text-[var(--ipal-text-muted-dark,#a3a3a3)]' export function CookieBanner({ classNames }: { classNames?: CookieBannerClassNames } = {}) { + const isMounted = useIsMounted() const { acceptAll, decided, rejectAll, savePreferences, state, texts } = useConsentContext() const [showSettings, setShowSettings] = useState(false) const [choices, setChoices] = useState>(state) @@ -61,6 +63,10 @@ export function CookieBanner({ classNames }: { classNames?: CookieBannerClassNam setChoices(state) }, [state]) + // Render nothing until mounted — avoids the React 19 hydration mismatch that + // projects used to work around with a setTimeout ConsentWrapper. No wrapper + // needed now. + if (!isMounted) {return null} if (decided) {return null} const toggle = (cat: ConsentCategory) => { diff --git a/src/modules/consent/CookieButton.tsx b/src/modules/consent/CookieButton.tsx index c65c507..ba5fdf8 100644 --- a/src/modules/consent/CookieButton.tsx +++ b/src/modules/consent/CookieButton.tsx @@ -2,6 +2,7 @@ import { Cookie } from 'lucide-react' import { useConsentContext } from './ConsentContext.js' +import { useIsMounted } from './useIsMounted.js' /** * Floating "cookie settings" button — lets visitors reopen the consent panel @@ -14,8 +15,12 @@ import { useConsentContext } from './ConsentContext.js' * replace the styling outright. */ export function CookieButton({ className }: { className?: string } = {}) { + const isMounted = useIsMounted() const { decided, reopen } = useConsentContext() + // Render nothing until mounted — prevents hydration mismatch (no project + // ConsentWrapper workaround needed). + if (!isMounted) {return null} if (!decided) {return null} const cls = diff --git a/src/modules/consent/index.ts b/src/modules/consent/index.ts index 043be1e..a4d19da 100644 --- a/src/modules/consent/index.ts +++ b/src/modules/consent/index.ts @@ -18,3 +18,4 @@ export { serializeConsent, } from './storage.js' export type { ConsentTexts } from './texts.js' +export { useIsMounted } from './useIsMounted.js' diff --git a/src/modules/consent/useIsMounted.ts b/src/modules/consent/useIsMounted.ts new file mode 100644 index 0000000..c5519cd --- /dev/null +++ b/src/modules/consent/useIsMounted.ts @@ -0,0 +1,17 @@ +'use client' +import { useEffect, useState } from 'react' + +/** + * Returns true only after the component has mounted on the client. Used to gate + * consent UI (CookieBanner, CookieButton) so it renders nothing during SSR / + * first paint — preventing the React 19 / Next hydration mismatch that projects + * were working around with their own setTimeout-based ConsentWrapper. Built into + * the components now, so no project wrapper is needed. + */ +export function useIsMounted(): boolean { + const [mounted, setMounted] = useState(false) + useEffect(() => { + setMounted(true) + }, []) + return mounted +} diff --git a/src/modules/i18n/createProxy.ts b/src/modules/i18n/createProxy.ts new file mode 100644 index 0000000..91964d3 --- /dev/null +++ b/src/modules/i18n/createProxy.ts @@ -0,0 +1,92 @@ +import type { I18nConfig } from './types.js' + +import { isValidLocale } from './helpers.js' +import { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js' + +/** Re-exported so the project's proxy.ts config uses the plugin's matcher. */ +export const DEFAULT_PROXY_MATCHER = DEFAULT_MIDDLEWARE_MATCHER + +/** + * Minimal structural types — the plugin does NOT import next/server (it's a peer + * dep not present at the plugin's own build time, which would cause TS2307). + * Next's real NextRequest / NextResponse satisfy these shapes at the call site. + */ +type ProxyRequest = { + cookies: { get: (name: string) => { value: string } | undefined } + // Matches localeMiddleware's MiddlewareRequest shape; a real NextRequest + // satisfies all of this structurally. + headers: Headers + nextUrl: { clone: () => URL; pathname: string; search: string } + url: string +} + +type ProxyResponse = { + cookies: { set: (name: string, value: string, opts?: Record) => void } +} + +/** + * Next's NextResponse constructor, injected by the project (which has next/server + * in scope). The plugin stays free of a next/server import. + */ +type NextResponseLike = { + next: (init?: { request?: { headers: Headers } }) => ProxyResponse + redirect: (url: string | URL) => ProxyResponse +} + +type CreateProxyOptions = { + consentCategory?: 'functional' | 'necessary' + consentCookieName?: string + cookieName?: string + /** Expose x-locale / x-pathname request headers to RSC. Default true. */ + exposeHeaders?: boolean +} + +/** + * Ready-made Next 16 proxy (the former middleware). Wraps the plugin's locale + * logic AND the per-project boilerplate (NextResponse, x-locale / x-pathname + * headers, locale cookie, redirect). The project's proxy.ts becomes a few lines. + * + * `NextResponse` is INJECTED (the plugin never imports next/server — it's a peer + * dep absent at the plugin's build time). The project passes it: + * + * // proxy.ts (Next 16 — NOT middleware.ts) + * import { NextResponse } from 'next/server' + * import { createProxy, DEFAULT_PROXY_MATCHER } from '@intecion/ipal-kit' + * import { i18nConfig } from '@/i18n.config' + * export const proxy = createProxy(i18nConfig, { NextResponse }) + * export const config = { matcher: DEFAULT_PROXY_MATCHER } + */ +export function createProxy( + config: I18nConfig, + deps: { NextResponse: NextResponseLike } & CreateProxyOptions, +): (request: ProxyRequest) => ProxyResponse { + const { exposeHeaders = true, NextResponse, ...mwOptions } = deps + const run = createLocaleMiddleware({ config, ...mwOptions }) + + return (request: ProxyRequest): ProxyResponse => { + const result = run(request) + + const requestHeaders = new Headers(request.headers) + if (exposeHeaders) { + const { pathname } = request.nextUrl + const seg = pathname.split('/').filter(Boolean)[0] ?? '' + const locale = isValidLocale(seg, config) ? seg : config.defaultLocale + requestHeaders.set('x-locale', locale) + requestHeaders.set('x-pathname', pathname) + } + + const response = + result.type === 'redirect' + ? NextResponse.redirect(new URL(result.location, request.url)) + : NextResponse.next({ request: { headers: requestHeaders } }) + + if (result.cookie) { + response.cookies.set(result.cookie.name, result.cookie.value, { + path: '/', + sameSite: 'lax', + }) + } + + return response + } +} diff --git a/src/modules/i18n/index.ts b/src/modules/i18n/index.ts index 9380ad5..6a9ac44 100644 --- a/src/modules/i18n/index.ts +++ b/src/modules/i18n/index.ts @@ -1,3 +1,4 @@ +export { createProxy, DEFAULT_PROXY_MATCHER } from './createProxy.js' export { getLocalizedSlugs } from './getLocalizedSlugs.js' export { getDefaultLocale, getLocaleCodes, getLocaleDefinition, isValidLocale } from './helpers.js' export { createLocaleMiddleware, DEFAULT_MIDDLEWARE_MATCHER } from './localeMiddleware.js' diff --git a/src/modules/richtext/RenderRichText.tsx b/src/modules/richtext/RenderRichText.tsx new file mode 100644 index 0000000..60982c0 --- /dev/null +++ b/src/modules/richtext/RenderRichText.tsx @@ -0,0 +1,55 @@ +import type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical' +import type { JSXConvertersFunction } from '@payloadcms/richtext-lexical/react' + +import { RichText as PayloadRichText } from '@payloadcms/richtext-lexical/react' + +export type RenderRichTextProps = { + /** Wrapper class (e.g. Tailwind prose classes). */ + className?: string + /** + * Override the JSX for specific node types to apply the project's own + * styling. Receives Payload's defaultConverters; return the merged map. + * This is where a project puts its Tailwind classes per node (headings, + * paragraphs, links, …) — the design stays in the project, the parsing in + * the plugin's wrapper over Payload's official converter. + */ + converters?: JSXConvertersFunction + /** + * Lexical editor state from a Payload richText field. Already localized — + * Payload returns the current locale's value, so NO per-locale key handling + * is needed here (unlike hand-rolled renderers that hardcode `.pl`). + */ + data: null | SerializedEditorState | undefined +} + +/** + * Renders a Payload Lexical richText field to React — a thin wrapper over + * Payload's OFFICIAL converter (@payloadcms/richtext-lexical/react). + * + * Why not hand-roll it: parsing Lexical by hand (node.type switch, node.format + * bit flags) duplicates what Payload already does, misses node types, drifts + * on Lexical updates, and tempts shortcuts like dangerouslySetInnerHTML (XSS) + * or a hardcoded `.pl` locale. The official converter handles every node, + * stays in sync, and is safe. This is the RenderBlocks of rich text: the + * plugin owns the engine, the project owns the look via `converters`. + * + * // project — a Server Component + * import { RenderRichText } from '@intecion/ipal-kit/rsc' + * + * + * // with project styling per node: + * const converters: JSXConvertersFunction = ({ defaultConverters }) => ({ + * ...defaultConverters, + * heading: ({ node, nodesToJSX }) => { + * const children = nodesToJSX({ nodes: node.children }) + * const cls = { h2: 'text-2xl font-semibold mt-10', h3: 'text-xl mt-7' }[node.tag] ?? '' + * const Tag = node.tag as 'h1'|'h2'|'h3'|'h4' + * return {children} + * }, + * }) + * + */ +export function RenderRichText({ className, converters, data }: RenderRichTextProps) { + if (!data) {return null} + return +} diff --git a/src/modules/richtext/index.ts b/src/modules/richtext/index.ts new file mode 100644 index 0000000..3807783 --- /dev/null +++ b/src/modules/richtext/index.ts @@ -0,0 +1,2 @@ +export { RenderRichText } from './RenderRichText.js' +export type { RenderRichTextProps } from './RenderRichText.js' diff --git a/src/modules/seo/buildManifest.ts b/src/modules/seo/buildManifest.ts new file mode 100644 index 0000000..005de51 --- /dev/null +++ b/src/modules/seo/buildManifest.ts @@ -0,0 +1,90 @@ +import type { BasePayload } from 'payload' + +import type { I18nConfig } from '../i18n/index.js' + +import { getDefaultLocale } from '../i18n/index.js' + +type MediaLike = + | { height?: null | number; mimeType?: null | string; url?: null | string; width?: null | number } + | null + | undefined + +type ManifestIcon = { sizes?: string; src: string; type?: string } + +type Manifest = { + background_color?: string + display: 'standalone' + icons: ManifestIcon[] + name?: string + short_name?: string + start_url: string + theme_color?: string +} + +type SettingsShape = { + backgroundColor?: null | string + favicon?: MediaLike + logo?: MediaLike + siteName?: null | string + themeColor?: null | string +} + +/** + * Builds a Next Web App Manifest from SiteSettings — replaces the ~50 lines of + * icon/mimeType parsing copied into every project's manifest.ts. Values come + * from the panel; missing fields are omitted (no hardcoded client data). + * + * // app/manifest.ts + * import { createManifestHandler } from '@intecion/ipal-kit' + * import { getCachedPayload } from '@/lib/content' + * import { i18nConfig } from '@/i18n.config' + * export default createManifestHandler({ getCachedPayload, config: i18nConfig }) + */ +export function createManifestHandler(opts: { + config: I18nConfig + getCachedPayload: () => Promise + settingsSlug?: string +}): () => Promise { + return async () => { + const defaultLocale = getDefaultLocale(opts.config) + const payload = await opts.getCachedPayload() + const settings = (await payload + .findGlobal({ + slug: (opts.settingsSlug ?? 'site-settings') as never, + depth: 1, + locale: defaultLocale as never, + }) + .catch(() => null)) as null | SettingsShape + + const start_url = `/${defaultLocale}` + if (!settings) { + return { display: 'standalone', icons: [], start_url } + } + + const iconSource = settings.favicon ?? settings.logo + const icons: ManifestIcon[] = [] + if (iconSource?.url) { + const type = + iconSource.mimeType ?? (iconSource.url.endsWith('.svg') ? 'image/svg+xml' : undefined) + const isSvg = type === 'image/svg+xml' + const size = + iconSource.width && iconSource.height + ? `${iconSource.width}x${iconSource.height}` + : undefined + icons.push({ + src: iconSource.url, + ...(isSvg ? { sizes: 'any' } : size ? { sizes: size } : {}), + ...(type ? { type } : {}), + }) + } + + return { + ...(settings.siteName ? { name: settings.siteName, short_name: settings.siteName } : {}), + display: 'standalone', + start_url, + ...(settings.backgroundColor ? { background_color: settings.backgroundColor } : {}), + ...(settings.themeColor ? { theme_color: settings.themeColor } : {}), + icons, + } + } +} diff --git a/src/modules/seo/index.ts b/src/modules/seo/index.ts index 8431bba..352aaa4 100644 --- a/src/modules/seo/index.ts +++ b/src/modules/seo/index.ts @@ -6,6 +6,7 @@ export { buildFaqJsonLd } from './buildFaqJsonLd.js' export { buildIconsMetadata } from './buildIconsMetadata.js' export { buildLlmsTxt } from './buildLlmsTxt.js' export { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js' +export { createManifestHandler } from './buildManifest.js' export { buildMetadata } from './buildMetadata.js' export type { PageMetadata } from './buildMetadata.js' export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js' @@ -26,6 +27,7 @@ export { injectAutoFillMeta } from './injectAutoFillMeta.js' export { injectSeoTabs } from './injectSeoTabs.js' export { readSiteMetaConfig } from './readSiteMetaConfig.js' export type { SiteMetaConfig } from './readSiteMetaConfig.js' +export { createLlmsTxtRoute, createSitemapRouteHandler } from './routeHandlers.js' export { buildSeoPlugin } from './seoPluginConfig.js' export { slugsAcrossLocales } from './slugsAcrossLocales.js' export type { SeoMeta, SeoOption } from './types.js' diff --git a/src/modules/seo/routeHandlers.ts b/src/modules/seo/routeHandlers.ts new file mode 100644 index 0000000..fa5ffd7 --- /dev/null +++ b/src/modules/seo/routeHandlers.ts @@ -0,0 +1,89 @@ +import type { BasePayload } from 'payload' + +import type { I18nConfig } from '../i18n/index.js' +import type { SitemapEntry } from './buildSitemapEntries.js' + +import { buildLlmsTxt } from './buildLlmsTxt.js' +import { buildSitemapXml } from './buildSitemapXml.js' + +/** + * Ready-made Next route handler for /llms.txt. Replaces the ~60-line try/catch + * every project was copying. buildLlmsTxt already handles collections without + * drafts, so no workaround is needed here. + * + * // app/llms.txt/route.ts + * import { createLlmsTxtRoute } from '@intecion/ipal-kit' + * import { getCachedPayload } from '@/lib/content' + * import { i18nConfig } from '@/i18n.config' + * export const dynamic = 'force-dynamic' + * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig, + * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! }) + */ +export function createLlmsTxtRoute(opts: { + baseUrl: string + config: I18nConfig + getCachedPayload: () => Promise + pagesSlug?: string + settingsSlug?: string +}): () => Promise { + return async () => { + try { + const payload = await opts.getCachedPayload() + const body = await buildLlmsTxt({ + baseUrl: opts.baseUrl, + config: opts.config, + pagesSlug: opts.pagesSlug, + payload, + settingsSlug: opts.settingsSlug, + }) + return new Response(body, { + headers: { 'Content-Type': 'text/plain; charset=utf-8' }, + }) + } catch (err) { + // DB unreachable at build (container) — return a minimal valid file so the + // route doesn't 500; it fills in at runtime. No per-project try/catch. + console.warn('[ipal] createLlmsTxtRoute: could not build llms.txt:', err) + return new Response('# llms.txt\n', { + headers: { 'Content-Type': 'text/plain; charset=utf-8' }, + }) + } + } +} + +/** + * Ready-made Next route handler for /sitemap.xml with the CSS stylesheet. + * Replaces the hand-written route in every project. Pass the project's `sitemap` + * helper (from createContentHelpers) and optionally a cssUrl. + * + * // app/sitemap.xml/route.ts + * import { createSitemapRouteHandler } from '@intecion/ipal-kit' + * import { sitemap } from '@/lib/content' + * export const dynamic = 'force-dynamic' + * export const GET = createSitemapRouteHandler(sitemap, { cssUrl: '/sitemap.css' }) + * + * Remember: if you use this, DON'T also keep app/sitemap.ts (two sitemaps + * confuse crawlers). + */ +export function createSitemapRouteHandler( + sitemap: () => Promise, + opts: { cssUrl?: string } = {}, +): () => Promise { + return async () => { + try { + const entries = await sitemap() + const xml = buildSitemapXml(entries, { cssUrl: opts.cssUrl }) + return new Response(xml, { + headers: { 'Content-Type': 'application/xml; charset=utf-8' }, + }) + } catch (err) { + console.warn('[ipal] createSitemapRouteHandler: could not build sitemap:', err) + // Valid empty urlset so the route doesn't 500 during a DB-less build. + const empty = + '\n' + + '' + return new Response(empty, { + headers: { 'Content-Type': 'application/xml; charset=utf-8' }, + }) + } + } +}