diff --git a/dist/index.d.ts b/dist/index.d.ts index e2e8d72..a5a49fb 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -21,7 +21,7 @@ export type { FormErrors, FormSubmitAction, Validator } from './modules/forms/us export { buildValidator, checked, custom, email, isEmail, maxLength, minLength, pattern, required, } from './modules/forms/validators.js'; export type { Rule } from './modules/forms/validators.js'; export { createContentHelpers } from './modules/frontend/index.js'; -export { buildPreventDeleteSystemPage, buildRevalidateHook, buildValidateUniqueRole, setPublishedAtHook, trackSlugHistoryHook, } from './modules/hooks/index.js'; +export { buildCrossLocaleFieldSync, buildPreventDeleteSystemPage, buildRevalidateHook, buildValidateUniqueRole, setPublishedAtHook, trackSlugHistoryHook, } from './modules/hooks/index.js'; export type { I18nConfig, LocaleDefinition, LocalizedSlugs } from './modules/i18n/index.js'; 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'; @@ -45,6 +45,7 @@ export type { AutoFillMapping, RobotsRules, SitemapEntry } from './modules/seo/i 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 { buildNoindexField } 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'; diff --git a/dist/index.js b/dist/index.js index e071f48..08c3410 100644 --- a/dist/index.js +++ b/dist/index.js @@ -15,7 +15,7 @@ export { buildFormsPlugin } from './modules/forms/formsPluginConfig.js'; // '@intecion/ipal-kit/client'.) export { buildValidator, checked, custom, email, isEmail, maxLength, minLength, pattern, required } from './modules/forms/validators.js'; export { createContentHelpers } from './modules/frontend/index.js'; -export { buildPreventDeleteSystemPage, buildRevalidateHook, buildValidateUniqueRole, setPublishedAtHook, trackSlugHistoryHook } from './modules/hooks/index.js'; +export { buildCrossLocaleFieldSync, 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'; @@ -30,6 +30,7 @@ export { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/ 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 { buildNoindexField } 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'; diff --git a/dist/index.js.map b/dist/index.js.map index 7bbbb36..7e6b304 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 type { FormErrors, FormSubmitAction, Validator } from './modules/forms/useForm.js'\n// Validation rules are pure — exported server-side too, for re-validating a\n// submission inside a server action. (useForm/useContactForm are client-only →\n// '@intecion/ipal-kit/client'.)\nexport {\n buildValidator,\n checked,\n custom,\n email,\n isEmail,\n maxLength,\n minLength,\n pattern,\n required,\n} from './modules/forms/validators.js'\nexport type { Rule } from './modules/forms/validators.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 { resolveLocalized } 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","buildValidator","checked","custom","email","isEmail","maxLength","minLength","pattern","required","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","resolveLocalized","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":"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"} \ 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 type { FormErrors, FormSubmitAction, Validator } from './modules/forms/useForm.js'\n// Validation rules are pure — exported server-side too, for re-validating a\n// submission inside a server action. (useForm/useContactForm are client-only →\n// '@intecion/ipal-kit/client'.)\nexport {\n buildValidator,\n checked,\n custom,\n email,\n isEmail,\n maxLength,\n minLength,\n pattern,\n required,\n} from './modules/forms/validators.js'\nexport type { Rule } from './modules/forms/validators.js'\nexport { createContentHelpers } from './modules/frontend/index.js'\nexport {\n buildCrossLocaleFieldSync,\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 { resolveLocalized } 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 { buildNoindexField } 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","buildValidator","checked","custom","email","isEmail","maxLength","minLength","pattern","required","createContentHelpers","buildCrossLocaleFieldSync","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","resolveLocalized","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","buildNoindexField","buildBreadcrumbJsonLd","buildSiteNavigationJsonLd","buildWebSiteJsonLd","buildFaqJsonLd","buildLocalBusinessJsonLd","buildServiceJsonLd","buildArticleJsonLd","buildLlmsTxt","buildSitemapXml","buildSlugField","toSlug","buildR2Storage","ipalKit"],"mappings":"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"} \ No newline at end of file diff --git a/dist/modules/hooks/buildCrossLocaleFieldSync.d.ts b/dist/modules/hooks/buildCrossLocaleFieldSync.d.ts new file mode 100644 index 0000000..b6fad30 --- /dev/null +++ b/dist/modules/hooks/buildCrossLocaleFieldSync.d.ts @@ -0,0 +1,63 @@ +import type { CollectionAfterChangeHook } from 'payload'; +import type { I18nConfig } from '../i18n/index.js'; +type BuildCrossLocaleFieldSyncArgs = { + /** + * The localized `blocks`/`array` field whose rows hold the shared fields. + * Default 'layout'. + */ + arrayField?: string; + /** + * Slug of the collection this hook is attached to — needed to re-read and + * update the other locales. (A hook can't discover its own collection.) + */ + collection: string; + config: I18nConfig; + /** + * Fields WITHIN each row that are conceptually language-independent (a shared + * media reference, an icon, a color) and should be propagated from the edited + * locale to every other locale — e.g. ['image'] or ['image', 'backgroundImage']. + * + * Only fields with a value in the source are copied: clearing a field in one + * language does NOT wipe it in the others (conservative, matches the hand- + * rolled hooks this replaces). Text and other truly-localized fields are never + * touched. + */ + fields: string[]; + /** + * Flag name set on `req` to break the update→afterChange→update loop. + * Default '_ipalSyncingCrossLocale'. Override only if two syncs run on one + * collection and must not share a guard. + */ + guardFlag?: string; +}; +/** + * Propagates language-independent fields (images, icons…) that live INSIDE a + * localized `blocks`/`array` field from the just-edited locale to every other + * configured locale. + * + * Why this exists: Payload localizes an array/blocks field as a whole, so there + * is no way to mark a single sub-field (the image) as non-localized — each + * locale keeps its own copy of every row, image included. Without this, an + * editor who picks images in Polish has to re-pick the SAME images in English, + * German, … This hook does that copy automatically. + * + * A0-safe: the locale list comes from `config`, never a hard-coded array — add + * a language in the panel and it's covered with no code change. (The hand-rolled + * versions this replaces carried a literal `['pl','en',...]` that silently + * dropped any locale not listed.) + * + * Row matching: by Payload row `id` when the same id exists in both locales + * (robust to reordering and to several blocks of the same type); otherwise it + * falls back to the positional index, but only when the block types at that + * index match — so it never writes an image into a block of a different type. + * + * // collections/Pages.ts + * import { buildCrossLocaleFieldSync } from '@intecion/ipal-kit' + * hooks: { + * afterChange: [ + * buildCrossLocaleFieldSync({ config: i18nConfig, collection: 'pages', fields: ['image'] }), + * ], + * } + */ +export declare function buildCrossLocaleFieldSync(args: BuildCrossLocaleFieldSyncArgs): CollectionAfterChangeHook; +export {}; diff --git a/dist/modules/hooks/buildCrossLocaleFieldSync.js b/dist/modules/hooks/buildCrossLocaleFieldSync.js new file mode 100644 index 0000000..33cd21e --- /dev/null +++ b/dist/modules/hooks/buildCrossLocaleFieldSync.js @@ -0,0 +1,141 @@ +import { getLocaleCodes } from '../i18n/index.js'; +/** Relationship/upload values arrive as an id or a populated object — normalize to the id. */ function toId(value) { + if (value == null) { + return null; + } + if (typeof value === 'string' || typeof value === 'number') { + return value; + } + if (typeof value === 'object' && 'id' in value) { + const id = value.id; + return typeof id === 'string' || typeof id === 'number' ? id : null; + } + return null; +} +/** + * Propagates language-independent fields (images, icons…) that live INSIDE a + * localized `blocks`/`array` field from the just-edited locale to every other + * configured locale. + * + * Why this exists: Payload localizes an array/blocks field as a whole, so there + * is no way to mark a single sub-field (the image) as non-localized — each + * locale keeps its own copy of every row, image included. Without this, an + * editor who picks images in Polish has to re-pick the SAME images in English, + * German, … This hook does that copy automatically. + * + * A0-safe: the locale list comes from `config`, never a hard-coded array — add + * a language in the panel and it's covered with no code change. (The hand-rolled + * versions this replaces carried a literal `['pl','en',...]` that silently + * dropped any locale not listed.) + * + * Row matching: by Payload row `id` when the same id exists in both locales + * (robust to reordering and to several blocks of the same type); otherwise it + * falls back to the positional index, but only when the block types at that + * index match — so it never writes an image into a block of a different type. + * + * // collections/Pages.ts + * import { buildCrossLocaleFieldSync } from '@intecion/ipal-kit' + * hooks: { + * afterChange: [ + * buildCrossLocaleFieldSync({ config: i18nConfig, collection: 'pages', fields: ['image'] }), + * ], + * } + */ export function buildCrossLocaleFieldSync(args) { + const { arrayField = 'layout', collection, config, fields, guardFlag = '_ipalSyncingCrossLocale' } = args; + return async ({ doc, req })=>{ + const reqAny = req; + // Re-entry guard: our own payload.update() below re-fires afterChange. + if (reqAny[guardFlag] || !doc?.id) { + return doc; + } + const sourceRows = doc[arrayField]; + if (!Array.isArray(sourceRows) || sourceRows.length === 0) { + return doc; + } + // Source locale = the locale being written. Fall back to the configured + // default rather than a hard-coded 'pl' when req.locale is absent. + const sourceLocale = typeof req.locale === 'string' ? req.locale : config.defaultLocale; + const otherLocales = getLocaleCodes(config).filter((l)=>l !== sourceLocale); + if (otherLocales.length === 0) { + return doc; + } // single-locale site: nothing to sync + const payload = req.payload; + reqAny[guardFlag] = true; + try { + for (const locale of otherLocales){ + let targetDoc; + try { + targetDoc = await payload.findByID({ + id: doc.id, + collection: collection, + depth: 0, + locale: locale + }); + } catch { + continue; // locale not yet created for this doc — nothing to sync into + } + const targetRows = targetDoc[arrayField]; + if (!Array.isArray(targetRows) || targetRows.length === 0) { + continue; + } + // id → row index, for robust matching across locales. + const byId = new Map(); + targetRows.forEach((row, i)=>{ + if (row?.id != null) { + byId.set(row.id, i); + } + }); + let changed = false; + sourceRows.forEach((sourceRow, idx)=>{ + if (!sourceRow) { + return; + } + // Match by id first; else positional index, but only if block types agree. + let targetRow; + if (sourceRow.id != null && byId.has(sourceRow.id)) { + targetRow = targetRows[byId.get(sourceRow.id)]; + } else { + const candidate = targetRows[idx]; + if (candidate && candidate.blockType === sourceRow.blockType) { + targetRow = candidate; + } + } + if (!targetRow) { + return; + } + for (const field of fields){ + const sourceId = toId(sourceRow[field]); + if (sourceId == null) { + continue; + } // don't propagate a cleared field + if (toId(targetRow[field]) !== sourceId) { + targetRow[field] = sourceId; + changed = true; + } + } + }); + if (changed) { + await payload.update({ + id: doc.id, + collection: collection, + data: { + [arrayField]: targetRows + }, + locale: locale, + req + }); + } + } + } catch (err) { + payload.logger?.error?.({ + err, + msg: `[ipal] cross-locale ${arrayField} sync failed` + }); + } finally{ + reqAny[guardFlag] = false; + } + return doc; + }; +} + +//# sourceMappingURL=buildCrossLocaleFieldSync.js.map \ No newline at end of file diff --git a/dist/modules/hooks/buildCrossLocaleFieldSync.js.map b/dist/modules/hooks/buildCrossLocaleFieldSync.js.map new file mode 100644 index 0000000..cd9e38b --- /dev/null +++ b/dist/modules/hooks/buildCrossLocaleFieldSync.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/hooks/buildCrossLocaleFieldSync.ts"],"sourcesContent":["import type { BasePayload, CollectionAfterChangeHook } from 'payload'\n\nimport type { I18nConfig } from '../i18n/index.js'\n\nimport { getLocaleCodes } from '../i18n/index.js'\n\ntype Row = { blockType?: string; id?: number | string } & Record\n\ntype BuildCrossLocaleFieldSyncArgs = {\n /**\n * The localized `blocks`/`array` field whose rows hold the shared fields.\n * Default 'layout'.\n */\n arrayField?: string\n /**\n * Slug of the collection this hook is attached to — needed to re-read and\n * update the other locales. (A hook can't discover its own collection.)\n */\n collection: string\n config: I18nConfig\n /**\n * Fields WITHIN each row that are conceptually language-independent (a shared\n * media reference, an icon, a color) and should be propagated from the edited\n * locale to every other locale — e.g. ['image'] or ['image', 'backgroundImage'].\n *\n * Only fields with a value in the source are copied: clearing a field in one\n * language does NOT wipe it in the others (conservative, matches the hand-\n * rolled hooks this replaces). Text and other truly-localized fields are never\n * touched.\n */\n fields: string[]\n /**\n * Flag name set on `req` to break the update→afterChange→update loop.\n * Default '_ipalSyncingCrossLocale'. Override only if two syncs run on one\n * collection and must not share a guard.\n */\n guardFlag?: string\n}\n\n/** Relationship/upload values arrive as an id or a populated object — normalize to the id. */\nfunction toId(value: unknown): null | number | string {\n if (value == null) {return null}\n if (typeof value === 'string' || typeof value === 'number') {return value}\n if (typeof value === 'object' && 'id' in (value as Record)) {\n const id = (value as Record).id\n return typeof id === 'string' || typeof id === 'number' ? id : null\n }\n return null\n}\n\n/**\n * Propagates language-independent fields (images, icons…) that live INSIDE a\n * localized `blocks`/`array` field from the just-edited locale to every other\n * configured locale.\n *\n * Why this exists: Payload localizes an array/blocks field as a whole, so there\n * is no way to mark a single sub-field (the image) as non-localized — each\n * locale keeps its own copy of every row, image included. Without this, an\n * editor who picks images in Polish has to re-pick the SAME images in English,\n * German, … This hook does that copy automatically.\n *\n * A0-safe: the locale list comes from `config`, never a hard-coded array — add\n * a language in the panel and it's covered with no code change. (The hand-rolled\n * versions this replaces carried a literal `['pl','en',...]` that silently\n * dropped any locale not listed.)\n *\n * Row matching: by Payload row `id` when the same id exists in both locales\n * (robust to reordering and to several blocks of the same type); otherwise it\n * falls back to the positional index, but only when the block types at that\n * index match — so it never writes an image into a block of a different type.\n *\n * // collections/Pages.ts\n * import { buildCrossLocaleFieldSync } from '@intecion/ipal-kit'\n * hooks: {\n * afterChange: [\n * buildCrossLocaleFieldSync({ config: i18nConfig, collection: 'pages', fields: ['image'] }),\n * ],\n * }\n */\nexport function buildCrossLocaleFieldSync(\n args: BuildCrossLocaleFieldSyncArgs,\n): CollectionAfterChangeHook {\n const {\n arrayField = 'layout',\n collection,\n config,\n fields,\n guardFlag = '_ipalSyncingCrossLocale',\n } = args\n\n return async ({ doc, req }) => {\n const reqAny = req as unknown as Record\n // Re-entry guard: our own payload.update() below re-fires afterChange.\n if (reqAny[guardFlag] || !doc?.id) {return doc}\n\n const sourceRows = (doc as Record)[arrayField]\n if (!Array.isArray(sourceRows) || sourceRows.length === 0) {return doc}\n\n // Source locale = the locale being written. Fall back to the configured\n // default rather than a hard-coded 'pl' when req.locale is absent.\n const sourceLocale = typeof req.locale === 'string' ? req.locale : config.defaultLocale\n const otherLocales = getLocaleCodes(config).filter((l) => l !== sourceLocale)\n if (otherLocales.length === 0) {return doc} // single-locale site: nothing to sync\n\n const payload = req.payload\n\n reqAny[guardFlag] = true\n try {\n for (const locale of otherLocales) {\n let targetDoc: Record\n try {\n targetDoc = (await payload.findByID({\n id: doc.id as never,\n collection: collection as never,\n depth: 0,\n locale: locale as never,\n })) as Record\n } catch {\n continue // locale not yet created for this doc — nothing to sync into\n }\n\n const targetRows = targetDoc[arrayField]\n if (!Array.isArray(targetRows) || targetRows.length === 0) {continue}\n\n // id → row index, for robust matching across locales.\n const byId = new Map()\n ;(targetRows as Row[]).forEach((row, i) => {\n if (row?.id != null) {byId.set(row.id, i)}\n })\n\n let changed = false\n\n ;(sourceRows as Row[]).forEach((sourceRow, idx) => {\n if (!sourceRow) {return}\n\n // Match by id first; else positional index, but only if block types agree.\n let targetRow: Row | undefined\n if (sourceRow.id != null && byId.has(sourceRow.id)) {\n targetRow = (targetRows as Row[])[byId.get(sourceRow.id)!]\n } else {\n const candidate = (targetRows as Row[])[idx]\n if (candidate && candidate.blockType === sourceRow.blockType) {targetRow = candidate}\n }\n if (!targetRow) {return}\n\n for (const field of fields) {\n const sourceId = toId(sourceRow[field])\n if (sourceId == null) {continue} // don't propagate a cleared field\n if (toId(targetRow[field]) !== sourceId) {\n targetRow[field] = sourceId\n changed = true\n }\n }\n })\n\n if (changed) {\n await payload.update({\n id: doc.id as never,\n collection: collection as never,\n data: { [arrayField]: targetRows } as never,\n locale: locale as never,\n req,\n })\n }\n }\n } catch (err) {\n payload.logger?.error?.({ err, msg: `[ipal] cross-locale ${arrayField} sync failed` })\n } finally {\n reqAny[guardFlag] = false\n }\n\n return doc\n }\n}\n"],"names":["getLocaleCodes","toId","value","id","buildCrossLocaleFieldSync","args","arrayField","collection","config","fields","guardFlag","doc","req","reqAny","sourceRows","Array","isArray","length","sourceLocale","locale","defaultLocale","otherLocales","filter","l","payload","targetDoc","findByID","depth","targetRows","byId","Map","forEach","row","i","set","changed","sourceRow","idx","targetRow","has","get","candidate","blockType","field","sourceId","update","data","err","logger","error","msg"],"mappings":"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"} \ No newline at end of file diff --git a/dist/modules/hooks/index.d.ts b/dist/modules/hooks/index.d.ts index 9d0dcef..56d9606 100644 --- a/dist/modules/hooks/index.d.ts +++ b/dist/modules/hooks/index.d.ts @@ -1,5 +1,6 @@ export { normalizeFilenameHook } from '../media/index.js'; export { buildAutoFillMetaHook, validateFaviconField } from '../seo/index.js'; +export { buildCrossLocaleFieldSync } from './buildCrossLocaleFieldSync.js'; export { buildRevalidateHook } from './buildRevalidateHook.js'; export { buildPreventDeleteSystemPage } from './preventDeleteSystemPage.js'; export { setPublishedAtHook } from './setPublishedAt.js'; diff --git a/dist/modules/hooks/index.js b/dist/modules/hooks/index.js index ec30fc8..fba1368 100644 --- a/dist/modules/hooks/index.js +++ b/dist/modules/hooks/index.js @@ -2,6 +2,7 @@ // żeby był jeden katalog "wszystkie hooki pluginu"). Źródło prawdy to ich moduły. export { normalizeFilenameHook } from '../media/index.js'; export { buildAutoFillMetaHook, validateFaviconField } from '../seo/index.js'; +export { buildCrossLocaleFieldSync } from './buildCrossLocaleFieldSync.js'; export { buildRevalidateHook } from './buildRevalidateHook.js'; export { buildPreventDeleteSystemPage } from './preventDeleteSystemPage.js'; export { setPublishedAtHook } from './setPublishedAt.js'; diff --git a/dist/modules/hooks/index.js.map b/dist/modules/hooks/index.js.map index 3cdfe9e..3f8b81c 100644 --- a/dist/modules/hooks/index.js.map +++ b/dist/modules/hooks/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/hooks/index.ts"],"sourcesContent":["// Re-eksport hooków domenowych (mieszkają w swoich modułach, tu dla przeglądu —\n// żeby był jeden katalog \"wszystkie hooki pluginu\"). Źródło prawdy to ich moduły.\nexport { normalizeFilenameHook } from '../media/index.js'\nexport { buildAutoFillMetaHook, validateFaviconField } from '../seo/index.js'\nexport { buildRevalidateHook } from './buildRevalidateHook.js'\nexport { buildPreventDeleteSystemPage } from './preventDeleteSystemPage.js'\nexport { setPublishedAtHook } from './setPublishedAt.js'\n\nexport { trackSlugHistoryHook } from './trackSlugHistory.js'\nexport { buildValidateUniqueRole } from './validateUniqueRole.js'\n"],"names":["normalizeFilenameHook","buildAutoFillMetaHook","validateFaviconField","buildRevalidateHook","buildPreventDeleteSystemPage","setPublishedAtHook","trackSlugHistoryHook","buildValidateUniqueRole"],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAClF,SAASA,qBAAqB,QAAQ,oBAAmB;AACzD,SAASC,qBAAqB,EAAEC,oBAAoB,QAAQ,kBAAiB;AAC7E,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,4BAA4B,QAAQ,+BAA8B;AAC3E,SAASC,kBAAkB,QAAQ,sBAAqB;AAExD,SAASC,oBAAoB,QAAQ,wBAAuB;AAC5D,SAASC,uBAAuB,QAAQ,0BAAyB"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/hooks/index.ts"],"sourcesContent":["// Re-eksport hooków domenowych (mieszkają w swoich modułach, tu dla przeglądu —\n// żeby był jeden katalog \"wszystkie hooki pluginu\"). Źródło prawdy to ich moduły.\nexport { normalizeFilenameHook } from '../media/index.js'\nexport { buildAutoFillMetaHook, validateFaviconField } from '../seo/index.js'\nexport { buildCrossLocaleFieldSync } from './buildCrossLocaleFieldSync.js'\nexport { buildRevalidateHook } from './buildRevalidateHook.js'\nexport { buildPreventDeleteSystemPage } from './preventDeleteSystemPage.js'\nexport { setPublishedAtHook } from './setPublishedAt.js'\n\nexport { trackSlugHistoryHook } from './trackSlugHistory.js'\nexport { buildValidateUniqueRole } from './validateUniqueRole.js'\n"],"names":["normalizeFilenameHook","buildAutoFillMetaHook","validateFaviconField","buildCrossLocaleFieldSync","buildRevalidateHook","buildPreventDeleteSystemPage","setPublishedAtHook","trackSlugHistoryHook","buildValidateUniqueRole"],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAClF,SAASA,qBAAqB,QAAQ,oBAAmB;AACzD,SAASC,qBAAqB,EAAEC,oBAAoB,QAAQ,kBAAiB;AAC7E,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,4BAA4B,QAAQ,+BAA8B;AAC3E,SAASC,kBAAkB,QAAQ,sBAAqB;AAExD,SAASC,oBAAoB,QAAQ,wBAAuB;AAC5D,SAASC,uBAAuB,QAAQ,0BAAyB"} \ No newline at end of file diff --git a/dist/modules/seo/buildNoindexField.d.ts b/dist/modules/seo/buildNoindexField.d.ts new file mode 100644 index 0000000..5910f4f --- /dev/null +++ b/dist/modules/seo/buildNoindexField.d.ts @@ -0,0 +1,34 @@ +import type { CheckboxField, Field } from 'payload'; +type BuildNoindexFieldArgs = { + /** Help text under the checkbox. */ + description?: string; + /** Sidebar label. Default 'Wyklucz z indeksowania (noindex)'. */ + label?: string; + /** + * Dotted path, inside the document, that the SEO read path (metadata + + * sitemap) consumes. Default 'meta.noindex' — the plugin-seo `meta` group. + * The checkbox value is mirrored here on every save, so editors toggle one + * friendly switch and the machinery reads a stable location. + */ + metaPath?: string; + /** Field name for the editor-facing checkbox. Default 'noindex'. */ + name?: string; + /** Extend/override the generated checkbox (position, access, etc.). */ + overrides?: Partial; +}; +/** + * A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the + * sitemap and metadata generators actually read). Replaces the hand-rolled + * checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …` + * glue copied into every project — no `any`, one source of truth for editors, + * one stable read location for the engine. + * + * Idempotent and order-independent: if either the checkbox OR an existing + * `meta.noindex` is set, the page ends up noindex; the two can't drift apart. + * + * // collections/Pages.ts + * import { buildNoindexField } from '@intecion/ipal-kit' + * fields: [ /* … *\/ buildNoindexField() ], + */ +export declare function buildNoindexField(args?: BuildNoindexFieldArgs): Field; +export {}; diff --git a/dist/modules/seo/buildNoindexField.js b/dist/modules/seo/buildNoindexField.js new file mode 100644 index 0000000..113b8b9 --- /dev/null +++ b/dist/modules/seo/buildNoindexField.js @@ -0,0 +1,69 @@ +/** Read a dotted path (e.g. 'meta.noindex') off a loosely-typed object. */ function readPath(obj, path) { + let cur = obj; + for (const key of path){ + if (cur == null || typeof cur !== 'object') { + return undefined; + } + cur = cur[key]; + } + return cur; +} +/** Write a dotted path, creating intermediate objects as needed. */ function writePath(obj, path, value) { + let cur = obj; + for(let i = 0; i < path.length - 1; i++){ + const key = path[i]; + const next = cur[key]; + if (next == null || typeof next !== 'object') { + cur[key] = {}; + } + cur = cur[key]; + } + cur[path[path.length - 1]] = value; +} +/** + * A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the + * sitemap and metadata generators actually read). Replaces the hand-rolled + * checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …` + * glue copied into every project — no `any`, one source of truth for editors, + * one stable read location for the engine. + * + * Idempotent and order-independent: if either the checkbox OR an existing + * `meta.noindex` is set, the page ends up noindex; the two can't drift apart. + * + * // collections/Pages.ts + * import { buildNoindexField } from '@intecion/ipal-kit' + * fields: [ /* … *\/ buildNoindexField() ], + */ export function buildNoindexField(args = {}) { + const { name = 'noindex', description = 'Zaznacz, aby wykluczyć tę podstronę z indeksowania (robots: noindex, follow) i z sitemap.xml.', label = 'Wyklucz z indeksowania (noindex)', metaPath = 'meta.noindex', overrides = {} } = args; + const segments = metaPath.split('.'); + const mirror = ({ data, value })=>{ + const shouldNoindex = Boolean(value ?? readPath(data, segments)); + if (data && typeof data === 'object') { + writePath(data, segments, shouldNoindex); + } + return shouldNoindex; + }; + const { admin: adminOverrides, hooks: hooksOverrides, ...restOverrides } = overrides; + return { + name, + type: 'checkbox', + admin: { + description, + position: 'sidebar', + ...adminOverrides + }, + defaultValue: false, + hooks: { + ...hooksOverrides, + // mirror runs first, then any project-supplied beforeChange hooks. + beforeChange: [ + mirror, + ...hooksOverrides?.beforeChange ?? [] + ] + }, + label, + ...restOverrides + }; +} + +//# sourceMappingURL=buildNoindexField.js.map \ No newline at end of file diff --git a/dist/modules/seo/buildNoindexField.js.map b/dist/modules/seo/buildNoindexField.js.map new file mode 100644 index 0000000..83129bd --- /dev/null +++ b/dist/modules/seo/buildNoindexField.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../src/modules/seo/buildNoindexField.ts"],"sourcesContent":["import type { CheckboxField, Field, FieldHook } from 'payload'\n\ntype BuildNoindexFieldArgs = {\n /** Help text under the checkbox. */\n description?: string\n /** Sidebar label. Default 'Wyklucz z indeksowania (noindex)'. */\n label?: string\n /**\n * Dotted path, inside the document, that the SEO read path (metadata +\n * sitemap) consumes. Default 'meta.noindex' — the plugin-seo `meta` group.\n * The checkbox value is mirrored here on every save, so editors toggle one\n * friendly switch and the machinery reads a stable location.\n */\n metaPath?: string\n /** Field name for the editor-facing checkbox. Default 'noindex'. */\n name?: string\n /** Extend/override the generated checkbox (position, access, etc.). */\n overrides?: Partial\n}\n\n/** Read a dotted path (e.g. 'meta.noindex') off a loosely-typed object. */\nfunction readPath(obj: null | Record | undefined, path: string[]): unknown {\n let cur: unknown = obj\n for (const key of path) {\n if (cur == null || typeof cur !== 'object') {return undefined}\n cur = (cur as Record)[key]\n }\n return cur\n}\n\n/** Write a dotted path, creating intermediate objects as needed. */\nfunction writePath(obj: Record, path: string[], value: unknown): void {\n let cur: Record = obj\n for (let i = 0; i < path.length - 1; i++) {\n const key = path[i]\n const next = cur[key]\n if (next == null || typeof next !== 'object') {cur[key] = {}}\n cur = cur[key] as Record\n }\n cur[path[path.length - 1]] = value\n}\n\n/**\n * A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the\n * sitemap and metadata generators actually read). Replaces the hand-rolled\n * checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …`\n * glue copied into every project — no `any`, one source of truth for editors,\n * one stable read location for the engine.\n *\n * Idempotent and order-independent: if either the checkbox OR an existing\n * `meta.noindex` is set, the page ends up noindex; the two can't drift apart.\n *\n * // collections/Pages.ts\n * import { buildNoindexField } from '@intecion/ipal-kit'\n * fields: [ /* … *\\/ buildNoindexField() ],\n */\nexport function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field {\n const {\n name = 'noindex',\n description = 'Zaznacz, aby wykluczyć tę podstronę z indeksowania (robots: noindex, follow) i z sitemap.xml.',\n label = 'Wyklucz z indeksowania (noindex)',\n metaPath = 'meta.noindex',\n overrides = {},\n } = args\n\n const segments = metaPath.split('.')\n\n const mirror: FieldHook = ({ data, value }) => {\n const shouldNoindex = Boolean(value ?? readPath(data as Record, segments))\n if (data && typeof data === 'object') {\n writePath(data as Record, segments, shouldNoindex)\n }\n return shouldNoindex\n }\n\n const { admin: adminOverrides, hooks: hooksOverrides, ...restOverrides } = overrides\n\n return {\n name,\n type: 'checkbox',\n admin: {\n description,\n position: 'sidebar',\n ...adminOverrides,\n },\n defaultValue: false,\n hooks: {\n ...hooksOverrides,\n // mirror runs first, then any project-supplied beforeChange hooks.\n beforeChange: [mirror, ...(hooksOverrides?.beforeChange ?? [])],\n },\n label,\n ...restOverrides,\n } as CheckboxField\n}\n"],"names":["readPath","obj","path","cur","key","undefined","writePath","value","i","length","next","buildNoindexField","args","name","description","label","metaPath","overrides","segments","split","mirror","data","shouldNoindex","Boolean","admin","adminOverrides","hooks","hooksOverrides","restOverrides","type","position","defaultValue","beforeChange"],"mappings":"AAoBA,yEAAyE,GACzE,SAASA,SAASC,GAA+C,EAAEC,IAAc;IAC/E,IAAIC,MAAeF;IACnB,KAAK,MAAMG,OAAOF,KAAM;QACtB,IAAIC,OAAO,QAAQ,OAAOA,QAAQ,UAAU;YAAC,OAAOE;QAAS;QAC7DF,MAAM,AAACA,GAA+B,CAACC,IAAI;IAC7C;IACA,OAAOD;AACT;AAEA,kEAAkE,GAClE,SAASG,UAAUL,GAA4B,EAAEC,IAAc,EAAEK,KAAc;IAC7E,IAAIJ,MAA+BF;IACnC,IAAK,IAAIO,IAAI,GAAGA,IAAIN,KAAKO,MAAM,GAAG,GAAGD,IAAK;QACxC,MAAMJ,MAAMF,IAAI,CAACM,EAAE;QACnB,MAAME,OAAOP,GAAG,CAACC,IAAI;QACrB,IAAIM,QAAQ,QAAQ,OAAOA,SAAS,UAAU;YAACP,GAAG,CAACC,IAAI,GAAG,CAAC;QAAC;QAC5DD,MAAMA,GAAG,CAACC,IAAI;IAChB;IACAD,GAAG,CAACD,IAAI,CAACA,KAAKO,MAAM,GAAG,EAAE,CAAC,GAAGF;AAC/B;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASI,kBAAkBC,OAA8B,CAAC,CAAC;IAChE,MAAM,EACJC,OAAO,SAAS,EAChBC,cAAc,+FAA+F,EAC7GC,QAAQ,kCAAkC,EAC1CC,WAAW,cAAc,EACzBC,YAAY,CAAC,CAAC,EACf,GAAGL;IAEJ,MAAMM,WAAWF,SAASG,KAAK,CAAC;IAEhC,MAAMC,SAAoB,CAAC,EAAEC,IAAI,EAAEd,KAAK,EAAE;QACxC,MAAMe,gBAAgBC,QAAQhB,SAASP,SAASqB,MAAiCH;QACjF,IAAIG,QAAQ,OAAOA,SAAS,UAAU;YACpCf,UAAUe,MAAiCH,UAAUI;QACvD;QACA,OAAOA;IACT;IAEA,MAAM,EAAEE,OAAOC,cAAc,EAAEC,OAAOC,cAAc,EAAE,GAAGC,eAAe,GAAGX;IAE3E,OAAO;QACLJ;QACAgB,MAAM;QACNL,OAAO;YACLV;YACAgB,UAAU;YACV,GAAGL,cAAc;QACnB;QACAM,cAAc;QACdL,OAAO;YACL,GAAGC,cAAc;YACjB,mEAAmE;YACnEK,cAAc;gBAACZ;mBAAYO,gBAAgBK,gBAAgB,EAAE;aAAE;QACjE;QACAjB;QACA,GAAGa,aAAa;IAClB;AACF"} \ No newline at end of file diff --git a/dist/modules/seo/index.d.ts b/dist/modules/seo/index.d.ts index b3a66b8..237d1cb 100644 --- a/dist/modules/seo/index.d.ts +++ b/dist/modules/seo/index.d.ts @@ -9,6 +9,7 @@ export { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'; export { createManifestHandler } from './buildManifest.js'; export { buildMetadata } from './buildMetadata.js'; export type { PageMetadata } from './buildMetadata.js'; +export { buildNoindexField } from './buildNoindexField.js'; export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'; export { buildRobots } from './buildRobots.js'; export type { RobotsRules } from './buildRobots.js'; diff --git a/dist/modules/seo/index.js b/dist/modules/seo/index.js index 5190d6f..4c83be4 100644 --- a/dist/modules/seo/index.js +++ b/dist/modules/seo/index.js @@ -7,6 +7,7 @@ export { buildLlmsTxt } from './buildLlmsTxt.js'; export { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js'; export { createManifestHandler } from './buildManifest.js'; export { buildMetadata } from './buildMetadata.js'; +export { buildNoindexField } from './buildNoindexField.js'; export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'; export { buildRobots } from './buildRobots.js'; export { buildServiceJsonLd } from './buildServiceJsonLd.js'; diff --git a/dist/modules/seo/index.js.map b/dist/modules/seo/index.js.map index 4a4cbb6..dc2a66b 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 { 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 { JsonLdGraph } from './JsonLdGraph.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","JsonLdGraph","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,WAAW,QAAQ,mBAAkB;AAC9C,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 +{"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 { buildNoindexField } from './buildNoindexField.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 { JsonLdGraph } from './JsonLdGraph.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","buildNoindexField","buildOrganizationJsonLd","buildRobots","buildServiceJsonLd","buildSitemapEntries","buildSitemapXml","buildSiteNavigationJsonLd","buildWebSiteJsonLd","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","JsonLdGraph","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,iBAAiB,QAAQ,yBAAwB;AAC1D,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,WAAW,QAAQ,mBAAkB;AAC9C,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/src/index.ts b/src/index.ts index 75d8778..8454028 100644 --- a/src/index.ts +++ b/src/index.ts @@ -85,6 +85,7 @@ export { export type { Rule } from './modules/forms/validators.js' export { createContentHelpers } from './modules/frontend/index.js' export { + buildCrossLocaleFieldSync, buildPreventDeleteSystemPage, buildRevalidateHook, buildValidateUniqueRole, @@ -151,6 +152,7 @@ export { buildOrganizationJsonLd, validateFaviconField, } from './modules/seo/index.js' +export { buildNoindexField } from './modules/seo/index.js' export { buildBreadcrumbJsonLd, buildSiteNavigationJsonLd, diff --git a/src/modules/hooks/buildCrossLocaleFieldSync.ts b/src/modules/hooks/buildCrossLocaleFieldSync.ts new file mode 100644 index 0000000..a3768da --- /dev/null +++ b/src/modules/hooks/buildCrossLocaleFieldSync.ts @@ -0,0 +1,174 @@ +import type { BasePayload, CollectionAfterChangeHook } from 'payload' + +import type { I18nConfig } from '../i18n/index.js' + +import { getLocaleCodes } from '../i18n/index.js' + +type Row = { blockType?: string; id?: number | string } & Record + +type BuildCrossLocaleFieldSyncArgs = { + /** + * The localized `blocks`/`array` field whose rows hold the shared fields. + * Default 'layout'. + */ + arrayField?: string + /** + * Slug of the collection this hook is attached to — needed to re-read and + * update the other locales. (A hook can't discover its own collection.) + */ + collection: string + config: I18nConfig + /** + * Fields WITHIN each row that are conceptually language-independent (a shared + * media reference, an icon, a color) and should be propagated from the edited + * locale to every other locale — e.g. ['image'] or ['image', 'backgroundImage']. + * + * Only fields with a value in the source are copied: clearing a field in one + * language does NOT wipe it in the others (conservative, matches the hand- + * rolled hooks this replaces). Text and other truly-localized fields are never + * touched. + */ + fields: string[] + /** + * Flag name set on `req` to break the update→afterChange→update loop. + * Default '_ipalSyncingCrossLocale'. Override only if two syncs run on one + * collection and must not share a guard. + */ + guardFlag?: string +} + +/** Relationship/upload values arrive as an id or a populated object — normalize to the id. */ +function toId(value: unknown): null | number | string { + if (value == null) {return null} + if (typeof value === 'string' || typeof value === 'number') {return value} + if (typeof value === 'object' && 'id' in (value as Record)) { + const id = (value as Record).id + return typeof id === 'string' || typeof id === 'number' ? id : null + } + return null +} + +/** + * Propagates language-independent fields (images, icons…) that live INSIDE a + * localized `blocks`/`array` field from the just-edited locale to every other + * configured locale. + * + * Why this exists: Payload localizes an array/blocks field as a whole, so there + * is no way to mark a single sub-field (the image) as non-localized — each + * locale keeps its own copy of every row, image included. Without this, an + * editor who picks images in Polish has to re-pick the SAME images in English, + * German, … This hook does that copy automatically. + * + * A0-safe: the locale list comes from `config`, never a hard-coded array — add + * a language in the panel and it's covered with no code change. (The hand-rolled + * versions this replaces carried a literal `['pl','en',...]` that silently + * dropped any locale not listed.) + * + * Row matching: by Payload row `id` when the same id exists in both locales + * (robust to reordering and to several blocks of the same type); otherwise it + * falls back to the positional index, but only when the block types at that + * index match — so it never writes an image into a block of a different type. + * + * // collections/Pages.ts + * import { buildCrossLocaleFieldSync } from '@intecion/ipal-kit' + * hooks: { + * afterChange: [ + * buildCrossLocaleFieldSync({ config: i18nConfig, collection: 'pages', fields: ['image'] }), + * ], + * } + */ +export function buildCrossLocaleFieldSync( + args: BuildCrossLocaleFieldSyncArgs, +): CollectionAfterChangeHook { + const { + arrayField = 'layout', + collection, + config, + fields, + guardFlag = '_ipalSyncingCrossLocale', + } = args + + return async ({ doc, req }) => { + const reqAny = req as unknown as Record + // Re-entry guard: our own payload.update() below re-fires afterChange. + if (reqAny[guardFlag] || !doc?.id) {return doc} + + const sourceRows = (doc as Record)[arrayField] + if (!Array.isArray(sourceRows) || sourceRows.length === 0) {return doc} + + // Source locale = the locale being written. Fall back to the configured + // default rather than a hard-coded 'pl' when req.locale is absent. + const sourceLocale = typeof req.locale === 'string' ? req.locale : config.defaultLocale + const otherLocales = getLocaleCodes(config).filter((l) => l !== sourceLocale) + if (otherLocales.length === 0) {return doc} // single-locale site: nothing to sync + + const payload = req.payload + + reqAny[guardFlag] = true + try { + for (const locale of otherLocales) { + let targetDoc: Record + try { + targetDoc = (await payload.findByID({ + id: doc.id as never, + collection: collection as never, + depth: 0, + locale: locale as never, + })) as Record + } catch { + continue // locale not yet created for this doc — nothing to sync into + } + + const targetRows = targetDoc[arrayField] + if (!Array.isArray(targetRows) || targetRows.length === 0) {continue} + + // id → row index, for robust matching across locales. + const byId = new Map() + ;(targetRows as Row[]).forEach((row, i) => { + if (row?.id != null) {byId.set(row.id, i)} + }) + + let changed = false + + ;(sourceRows as Row[]).forEach((sourceRow, idx) => { + if (!sourceRow) {return} + + // Match by id first; else positional index, but only if block types agree. + let targetRow: Row | undefined + if (sourceRow.id != null && byId.has(sourceRow.id)) { + targetRow = (targetRows as Row[])[byId.get(sourceRow.id)!] + } else { + const candidate = (targetRows as Row[])[idx] + if (candidate && candidate.blockType === sourceRow.blockType) {targetRow = candidate} + } + if (!targetRow) {return} + + for (const field of fields) { + const sourceId = toId(sourceRow[field]) + if (sourceId == null) {continue} // don't propagate a cleared field + if (toId(targetRow[field]) !== sourceId) { + targetRow[field] = sourceId + changed = true + } + } + }) + + if (changed) { + await payload.update({ + id: doc.id as never, + collection: collection as never, + data: { [arrayField]: targetRows } as never, + locale: locale as never, + req, + }) + } + } + } catch (err) { + payload.logger?.error?.({ err, msg: `[ipal] cross-locale ${arrayField} sync failed` }) + } finally { + reqAny[guardFlag] = false + } + + return doc + } +} diff --git a/src/modules/hooks/index.ts b/src/modules/hooks/index.ts index a950423..0766415 100644 --- a/src/modules/hooks/index.ts +++ b/src/modules/hooks/index.ts @@ -2,6 +2,7 @@ // żeby był jeden katalog "wszystkie hooki pluginu"). Źródło prawdy to ich moduły. export { normalizeFilenameHook } from '../media/index.js' export { buildAutoFillMetaHook, validateFaviconField } from '../seo/index.js' +export { buildCrossLocaleFieldSync } from './buildCrossLocaleFieldSync.js' export { buildRevalidateHook } from './buildRevalidateHook.js' export { buildPreventDeleteSystemPage } from './preventDeleteSystemPage.js' export { setPublishedAtHook } from './setPublishedAt.js' diff --git a/src/modules/seo/buildNoindexField.ts b/src/modules/seo/buildNoindexField.ts new file mode 100644 index 0000000..7582b5b --- /dev/null +++ b/src/modules/seo/buildNoindexField.ts @@ -0,0 +1,95 @@ +import type { CheckboxField, Field, FieldHook } from 'payload' + +type BuildNoindexFieldArgs = { + /** Help text under the checkbox. */ + description?: string + /** Sidebar label. Default 'Wyklucz z indeksowania (noindex)'. */ + label?: string + /** + * Dotted path, inside the document, that the SEO read path (metadata + + * sitemap) consumes. Default 'meta.noindex' — the plugin-seo `meta` group. + * The checkbox value is mirrored here on every save, so editors toggle one + * friendly switch and the machinery reads a stable location. + */ + metaPath?: string + /** Field name for the editor-facing checkbox. Default 'noindex'. */ + name?: string + /** Extend/override the generated checkbox (position, access, etc.). */ + overrides?: Partial +} + +/** Read a dotted path (e.g. 'meta.noindex') off a loosely-typed object. */ +function readPath(obj: null | Record | undefined, path: string[]): unknown { + let cur: unknown = obj + for (const key of path) { + if (cur == null || typeof cur !== 'object') {return undefined} + cur = (cur as Record)[key] + } + return cur +} + +/** Write a dotted path, creating intermediate objects as needed. */ +function writePath(obj: Record, path: string[], value: unknown): void { + let cur: Record = obj + for (let i = 0; i < path.length - 1; i++) { + const key = path[i] + const next = cur[key] + if (next == null || typeof next !== 'object') {cur[key] = {}} + cur = cur[key] as Record + } + cur[path[path.length - 1]] = value +} + +/** + * A sidebar `noindex` checkbox that mirrors into `meta.noindex` (what the + * sitemap and metadata generators actually read). Replaces the hand-rolled + * checkbox + `beforeChange` hook with its `(data as any).meta.noindex = …` + * glue copied into every project — no `any`, one source of truth for editors, + * one stable read location for the engine. + * + * Idempotent and order-independent: if either the checkbox OR an existing + * `meta.noindex` is set, the page ends up noindex; the two can't drift apart. + * + * // collections/Pages.ts + * import { buildNoindexField } from '@intecion/ipal-kit' + * fields: [ /* … *\/ buildNoindexField() ], + */ +export function buildNoindexField(args: BuildNoindexFieldArgs = {}): Field { + const { + name = 'noindex', + description = 'Zaznacz, aby wykluczyć tę podstronę z indeksowania (robots: noindex, follow) i z sitemap.xml.', + label = 'Wyklucz z indeksowania (noindex)', + metaPath = 'meta.noindex', + overrides = {}, + } = args + + const segments = metaPath.split('.') + + const mirror: FieldHook = ({ data, value }) => { + const shouldNoindex = Boolean(value ?? readPath(data as Record, segments)) + if (data && typeof data === 'object') { + writePath(data as Record, segments, shouldNoindex) + } + return shouldNoindex + } + + const { admin: adminOverrides, hooks: hooksOverrides, ...restOverrides } = overrides + + return { + name, + type: 'checkbox', + admin: { + description, + position: 'sidebar', + ...adminOverrides, + }, + defaultValue: false, + hooks: { + ...hooksOverrides, + // mirror runs first, then any project-supplied beforeChange hooks. + beforeChange: [mirror, ...(hooksOverrides?.beforeChange ?? [])], + }, + label, + ...restOverrides, + } as CheckboxField +} diff --git a/src/modules/seo/index.ts b/src/modules/seo/index.ts index dee097a..2d59909 100644 --- a/src/modules/seo/index.ts +++ b/src/modules/seo/index.ts @@ -9,6 +9,7 @@ export { buildLocalBusinessJsonLd } from './buildLocalBusinessJsonLd.js' export { createManifestHandler } from './buildManifest.js' export { buildMetadata } from './buildMetadata.js' export type { PageMetadata } from './buildMetadata.js' +export { buildNoindexField } from './buildNoindexField.js' export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js' export { buildRobots } from './buildRobots.js' export type { RobotsRules } from './buildRobots.js'