@payloadcms/plugin-seo 3.0.0-canary.95fcd13 → 3.0.0-canary.9beaa28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/exports/client.d.ts +6 -0
  2. package/dist/exports/client.d.ts.map +1 -0
  3. package/dist/exports/client.js +7 -0
  4. package/dist/exports/client.js.map +1 -0
  5. package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts +3 -4
  6. package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts.map +1 -1
  7. package/dist/fields/MetaDescription/MetaDescriptionComponent.js +19 -8
  8. package/dist/fields/MetaDescription/MetaDescriptionComponent.js.map +1 -1
  9. package/dist/fields/MetaDescription/index.d.ts.map +1 -1
  10. package/dist/fields/MetaDescription/index.js +5 -8
  11. package/dist/fields/MetaDescription/index.js.map +1 -1
  12. package/dist/fields/MetaImage/MetaImageComponent.d.ts +3 -3
  13. package/dist/fields/MetaImage/MetaImageComponent.d.ts.map +1 -1
  14. package/dist/fields/MetaImage/MetaImageComponent.js +20 -10
  15. package/dist/fields/MetaImage/MetaImageComponent.js.map +1 -1
  16. package/dist/fields/MetaImage/index.d.ts.map +1 -1
  17. package/dist/fields/MetaImage/index.js +5 -8
  18. package/dist/fields/MetaImage/index.js.map +1 -1
  19. package/dist/fields/MetaTitle/MetaTitleComponent.d.ts +3 -3
  20. package/dist/fields/MetaTitle/MetaTitleComponent.d.ts.map +1 -1
  21. package/dist/fields/MetaTitle/MetaTitleComponent.js +19 -8
  22. package/dist/fields/MetaTitle/MetaTitleComponent.js.map +1 -1
  23. package/dist/fields/MetaTitle/index.d.ts.map +1 -1
  24. package/dist/fields/MetaTitle/index.js +5 -8
  25. package/dist/fields/MetaTitle/index.js.map +1 -1
  26. package/dist/fields/Overview/index.d.ts.map +1 -1
  27. package/dist/fields/Overview/index.js +5 -8
  28. package/dist/fields/Overview/index.js.map +1 -1
  29. package/dist/fields/Preview/PreviewComponent.d.ts +3 -3
  30. package/dist/fields/Preview/PreviewComponent.d.ts.map +1 -1
  31. package/dist/fields/Preview/PreviewComponent.js +11 -6
  32. package/dist/fields/Preview/PreviewComponent.js.map +1 -1
  33. package/dist/fields/Preview/index.d.ts.map +1 -1
  34. package/dist/fields/Preview/index.js +5 -8
  35. package/dist/fields/Preview/index.js.map +1 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +39 -94
  38. package/dist/index.js.map +1 -1
  39. package/dist/types.d.ts +10 -5
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js.map +1 -1
  42. package/package.json +15 -10
@@ -0,0 +1,6 @@
1
+ export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js';
2
+ export { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js';
3
+ export { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js';
4
+ export { OverviewComponent } from '../fields/Overview/OverviewComponent.js';
5
+ export { PreviewComponent } from '../fields/Preview/PreviewComponent.js';
6
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAA;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAA"}
@@ -0,0 +1,7 @@
1
+ export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js';
2
+ export { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js';
3
+ export { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js';
4
+ export { OverviewComponent } from '../fields/Overview/OverviewComponent.js';
5
+ export { PreviewComponent } from '../fields/Preview/PreviewComponent.js';
6
+
7
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js'\nexport { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js'\nexport { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js'\nexport { OverviewComponent } from '../fields/Overview/OverviewComponent.js'\nexport { PreviewComponent } from '../fields/Preview/PreviewComponent.js'\n"],"names":["MetaDescriptionComponent","MetaImageComponent","MetaTitleComponent","OverviewComponent","PreviewComponent"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,wDAAuD;AAChG,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,iBAAiB,QAAQ,0CAAyC;AAC3E,SAASC,gBAAgB,QAAQ,wCAAuC"}
@@ -1,9 +1,8 @@
1
- import type { FormFieldBase } from 'payload';
1
+ import type { TextareaFieldProps } from 'payload';
2
2
  import React from 'react';
3
3
  type MetaDescriptionProps = {
4
- hasGenerateDescriptionFn: boolean;
5
- path: string;
6
- } & FormFieldBase;
4
+ readonly hasGenerateDescriptionFn: boolean;
5
+ } & TextareaFieldProps;
7
6
  export declare const MetaDescriptionComponent: React.FC<MetaDescriptionProps>;
8
7
  export {};
9
8
  //# sourceMappingURL=MetaDescriptionComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MetaDescriptionComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAY5C,OAAO,KAAsB,MAAM,OAAO,CAAA;AAU1C,KAAK,oBAAoB,GAAG;IAC1B,wBAAwB,EAAE,OAAO,CAAA;IACjC,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,aAAa,CAAA;AAEjB,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAsHnE,CAAA"}
1
+ {"version":3,"file":"MetaDescriptionComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAYjD,OAAO,KAAsB,MAAM,OAAO,CAAA;AAU1C,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAA;CAC3C,GAAG,kBAAkB,CAAA;AAEtB,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA4InE,CAAA"}
@@ -6,7 +6,7 @@ import { defaults } from '../../defaults.js';
6
6
  import { LengthIndicator } from '../../ui/LengthIndicator.js';
7
7
  const { maxLength, minLength } = defaults.description;
8
8
  export const MetaDescriptionComponent = (props)=>{
9
- const { CustomLabel, hasGenerateDescriptionFn, label, labelProps, required } = props;
9
+ const { field: { admin: { components: { Label } }, label, required }, hasGenerateDescriptionFn, labelProps } = props;
10
10
  const { path: pathFromContext } = useFieldProps();
11
11
  const { t } = useTranslation();
12
12
  const locale = useLocale();
@@ -20,11 +20,16 @@ export const MetaDescriptionComponent = (props)=>{
20
20
  if (!hasGenerateDescriptionFn) return;
21
21
  const genDescriptionResponse = await fetch('/api/plugin-seo/generate-description', {
22
22
  body: JSON.stringify({
23
- ...docInfo,
24
- doc: {
25
- ...getData()
26
- },
27
- locale: typeof locale === 'object' ? locale?.code : locale
23
+ id: docInfo.id,
24
+ slug: docInfo.slug,
25
+ doc: getData(),
26
+ docPermissions: docInfo.docPermissions,
27
+ hasPublishPermission: docInfo.hasPublishPermission,
28
+ hasSavePermission: docInfo.hasSavePermission,
29
+ initialData: docInfo.initialData,
30
+ initialState: docInfo.initialState,
31
+ locale: typeof locale === 'object' ? locale?.code : locale,
32
+ title: docInfo.title
28
33
  }),
29
34
  credentials: 'include',
30
35
  headers: {
@@ -56,7 +61,8 @@ export const MetaDescriptionComponent = (props)=>{
56
61
  className: "plugin-seo__field",
57
62
  children: [
58
63
  /*#__PURE__*/ _jsx(FieldLabel, {
59
- CustomLabel: CustomLabel,
64
+ Label: Label,
65
+ field: null,
60
66
  label: label,
61
67
  ...labelProps || {}
62
68
  }),
@@ -108,7 +114,12 @@ export const MetaDescriptionComponent = (props)=>{
108
114
  position: 'relative'
109
115
  },
110
116
  children: /*#__PURE__*/ _jsx(TextareaInput, {
111
- CustomError: errorMessage,
117
+ Error: {
118
+ type: 'client',
119
+ Component: null,
120
+ RenderedComponent: errorMessage
121
+ },
122
+ label: label,
112
123
  onChange: setValue,
113
124
  path: pathFromContext,
114
125
  required: required,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { FormFieldBase } from 'payload'\n\nimport {\n FieldLabel,\n TextareaInput,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateDescription } from '../../types.js'\n\nimport { defaults } from '../../defaults.js'\nimport { LengthIndicator } from '../../ui/LengthIndicator.js'\n\nconst { maxLength, minLength } = defaults.description\n\ntype MetaDescriptionProps = {\n hasGenerateDescriptionFn: boolean\n path: string\n} & FormFieldBase\n\nexport const MetaDescriptionComponent: React.FC<MetaDescriptionProps> = (props) => {\n const { CustomLabel, hasGenerateDescriptionFn, label, labelProps, required } = props\n const { path: pathFromContext } = useFieldProps()\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const field: FieldType<string> = useField({\n path: pathFromContext,\n } as Options)\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateDescription = useCallback(async () => {\n if (!hasGenerateDescriptionFn) return\n\n const genDescriptionResponse = await fetch('/api/plugin-seo/generate-description', {\n body: JSON.stringify({\n ...docInfo,\n doc: { ...getData() },\n locale: typeof locale === 'object' ? locale?.code : locale,\n } satisfies Parameters<GenerateDescription>[0]),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: generatedDescription } = await genDescriptionResponse.json()\n\n setValue(generatedDescription || '')\n }, [hasGenerateDescriptionFn, docInfo, getData, locale, setValue])\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel CustomLabel={CustomLabel} label={label} {...(labelProps || {})} />\n {hasGenerateDescriptionFn && (\n <React.Fragment>\n &nbsp; &mdash; &nbsp;\n <button\n onClick={() => {\n void regenerateDescription()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:lengthTipDescription', { maxLength, minLength })}\n <a\n href=\"https://developers.google.com/search/docs/advanced/appearance/snippet#meta-descriptions\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {t('plugin-seo:bestPractices')}\n </a>\n </div>\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <TextareaInput\n CustomError={errorMessage}\n onChange={setValue}\n path={pathFromContext}\n required={required}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <LengthIndicator maxLength={maxLength} minLength={minLength} text={value} />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","TextareaInput","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","description","MetaDescriptionComponent","props","CustomLabel","hasGenerateDescriptionFn","label","labelProps","required","path","pathFromContext","t","locale","getData","docInfo","field","errorMessage","setValue","showError","value","regenerateDescription","genDescriptionResponse","fetch","body","JSON","stringify","doc","code","credentials","headers","method","result","generatedDescription","json","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","a","href","rel","target","CustomError","onChange","alignItems","display","width","text"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,aAAa,EACbC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,eAAe,QAAQ,8BAA6B;AAE7D,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH,SAASI,WAAW;AAOrD,OAAO,MAAMC,2BAA2D,CAACC;IACvE,MAAM,EAAEC,WAAW,EAAEC,wBAAwB,EAAEC,KAAK,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGL;IAC/E,MAAM,EAAEM,MAAMC,eAAe,EAAE,GAAGnB;IAElC,MAAM,EAAEoB,CAAC,EAAE,GAAGjB;IAEd,MAAMkB,SAASnB;IACf,MAAM,EAAEoB,OAAO,EAAE,GAAGrB;IACpB,MAAMsB,UAAUzB;IAEhB,MAAM0B,QAA2BzB,SAAS;QACxCmB,MAAMC;IACR;IAEA,MAAM,EAAEM,YAAY,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGJ;IAErD,MAAMK,wBAAwBxB,YAAY;QACxC,IAAI,C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AAO;wBACLC,cAAc;oBAChB;oBACAjB,OAAOA;;;0BAGX,KAACe;gBACCC,OAAO;oBACLqB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAAC5D;oBAAgBC,WAAWA;oBAAWC,WAAWA;oBAAW2D,MAAMxC;;;;;AAI3E,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { TextareaFieldProps } from 'payload'\n\nimport {\n FieldLabel,\n TextareaInput,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateDescription } from '../../types.js'\n\nimport { defaults } from '../../defaults.js'\nimport { LengthIndicator } from '../../ui/LengthIndicator.js'\n\nconst { maxLength, minLength } = defaults.description\n\ntype MetaDescriptionProps = {\n readonly hasGenerateDescriptionFn: boolean\n} & TextareaFieldProps\n\nexport const MetaDescriptionComponent: React.FC<MetaDescriptionProps> = (props) => {\n const {\n field: {\n admin: {\n components: { Label },\n },\n label,\n required,\n },\n hasGenerateDescriptionFn,\n labelProps,\n } = props\n const { path: pathFromContext } = useFieldProps()\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const field: FieldType<string> = useField({\n path: pathFromContext,\n } as Options)\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateDescription = useCallback(async () => {\n if (!hasGenerateDescriptionFn) return\n\n const genDescriptionResponse = await fetch('/api/plugin-seo/generate-description', {\n body: JSON.stringify({\n id: docInfo.id,\n slug: docInfo.slug,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\n hasPublishPermission: docInfo.hasPublishPermission,\n hasSavePermission: docInfo.hasSavePermission,\n initialData: docInfo.initialData,\n initialState: docInfo.initialState,\n locale: typeof locale === 'object' ? locale?.code : locale,\n title: docInfo.title,\n } satisfies Omit<Parameters<GenerateDescription>[0], 'req'>),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: generatedDescription } = await genDescriptionResponse.json()\n\n setValue(generatedDescription || '')\n }, [hasGenerateDescriptionFn, docInfo, getData, locale, setValue])\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel Label={Label} field={null} label={label} {...(labelProps || {})} />\n {hasGenerateDescriptionFn && (\n <React.Fragment>\n &nbsp; &mdash; &nbsp;\n <button\n onClick={() => {\n void regenerateDescription()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:lengthTipDescription', { maxLength, minLength })}\n <a\n href=\"https://developers.google.com/search/docs/advanced/appearance/snippet#meta-descriptions\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {t('plugin-seo:bestPractices')}\n </a>\n </div>\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <TextareaInput\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n label={label}\n onChange={setValue}\n path={pathFromContext}\n required={required}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <LengthIndicator maxLength={maxLength} minLength={minLength} text={value} />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","TextareaInput","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","description","MetaDescriptionComponent","props","field","admin","components","Label","label","required","hasGenerateDescriptionFn","labelProps","path","pathFromContext","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateDescription","genDescriptionResponse","fetch","body","JSON","stringify","id","slug","doc","docPermissions","hasPublishPermission","hasSavePermission","initialData","initialState","code","title","credentials","headers","method","result","generatedDescription","json","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","a","href","rel","target","Error","Component","RenderedComponent","onChange","alignItems","display","width","text"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,aAAa,EACbC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,eAAe,QAAQ,8BAA6B;AAE7D,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH,SAASI,WAAW;AAMrD,OAAO,MAAMC,2BAA2D,CAACC;IACvE,MAAM,EACJC,OAAO,EACLC,OAAO,EACLC,YAAY,EAAEC,KAAK,EAAE,EACtB,EACDC,KAAK,EACLC,QAAQ,EACT,EACDC,wBAAwB,EACxBC,UAAU,EACX,GAAGR;IACJ,MAAM,EAAES,MAAMC,eAAe,EAAE,GAAGtB;IAElC,MAAM,EAAEuB,CAAC,EAAE,GAAGpB;IAEd,MAAMqB,SAAStB;IACf,MAAM,EAAEuB,OAAO,EAAE,GAAGxB;IACpB,MAAMyB,UAAU5B;IAEhB,MAAMe,QAA2Bd,SAAS;QACxCsB,MAAMC;IACR;IAEA,MAAM,EAAEK,YAAY,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGjB;IAErD,MAAMkB,wBAAwB1B,YAAY;QACxC,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AC4D;gCACCC,MAAK;gCACLC,KAAI;gCACJC,QAAO;0CAENjD,EAAE;;;;;;0BAIT,KAAC8B;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAAC3D;oBACC4E,OAAO;wBACLL,MAAM;wBACNM,WAAW;wBACXC,mBAAmBhD;oBACrB;oBACAV,OAAOA;oBACP2D,UAAUhD;oBACVP,MAAMC;oBACNJ,UAAUA;oBACVW,WAAWA;oBACXyB,OAAO;wBACLC,cAAc;oBAChB;oBACAzB,OAAOA;;;0BAGX,KAACuB;gBACCC,OAAO;oBACLuB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAACxE;oBAAgBC,WAAWA;oBAAWC,WAAWA;oBAAWuE,MAAMlD;;;;;AAI3E,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CACnC;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,aAAa,CAAA;AAExF,eAAO,MAAM,oBAAoB,EAAE,aAkBlC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CACnC;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,aAAa,CAAA;AAExF,eAAO,MAAM,oBAAoB,EAAE,aAiBlC,CAAA"}
@@ -1,18 +1,15 @@
1
- import { withMergedProps } from '@payloadcms/ui/shared';
2
- import { MetaDescriptionComponent } from './MetaDescriptionComponent.js';
3
1
  export const MetaDescriptionField = ({ hasGenerateFn = false, overrides })=>{
4
2
  return {
5
3
  name: 'description',
6
4
  type: 'textarea',
7
5
  admin: {
8
6
  components: {
9
- Field: withMergedProps({
10
- Component: MetaDescriptionComponent,
11
- sanitizeServerOnlyProps: true,
12
- toMergeIntoProps: {
7
+ Field: {
8
+ clientProps: {
13
9
  hasGenerateDescriptionFn: hasGenerateFn
14
- }
15
- })
10
+ },
11
+ path: '@payloadcms/plugin-seo/client#MetaDescriptionComponent'
12
+ }
16
13
  }
17
14
  },
18
15
  localized: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/MetaDescription/index.ts"],"sourcesContent":["import type { TextareaField } from 'payload'\n\nimport { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { MetaDescriptionComponent } from './MetaDescriptionComponent.js'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<TextareaField>\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextareaField\n\nexport const MetaDescriptionField: FieldFunction = ({ hasGenerateFn = false, overrides }) => {\n return {\n name: 'description',\n type: 'textarea',\n admin: {\n components: {\n Field: withMergedProps({\n Component: MetaDescriptionComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n hasGenerateDescriptionFn: hasGenerateFn,\n },\n }),\n },\n },\n localized: true,\n ...((overrides as unknown as TextareaField) ?? {}),\n }\n}\n"],"names":["withMergedProps","MetaDescriptionComponent","MetaDescriptionField","hasGenerateFn","overrides","name","type","admin","components","Field","Component","sanitizeServerOnlyProps","toMergeIntoProps","hasGenerateDescriptionFn","localized"],"mappings":"AAEA,SAASA,eAAe,QAAQ,wBAAuB;AAEvD,SAASC,wBAAwB,QAAQ,gCAA+B;AAYxE,OAAO,MAAMC,uBAAsC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAE;IACtF,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAOT,gBAAgB;oBACrBU,WAAWT;oBACXU,yBAAyB;oBACzBC,kBAAkB;wBAChBC,0BAA0BV;oBAC5B;gBACF;YACF;QACF;QACAW,WAAW;QACX,GAAI,AAACV,aAA0C,CAAC,CAAC;IACnD;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/MetaDescription/index.ts"],"sourcesContent":["import type { TextareaField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<TextareaField>\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextareaField\n\nexport const MetaDescriptionField: FieldFunction = ({ hasGenerateFn = false, overrides }) => {\n return {\n name: 'description',\n type: 'textarea',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateDescriptionFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaDescriptionComponent',\n },\n },\n },\n localized: true,\n ...((overrides as unknown as TextareaField) ?? {}),\n }\n}\n"],"names":["MetaDescriptionField","hasGenerateFn","overrides","name","type","admin","components","Field","clientProps","hasGenerateDescriptionFn","path","localized"],"mappings":"AAYA,OAAO,MAAMA,uBAAsC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAE;IACtF,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,0BAA0BR;oBAC5B;oBACAS,MAAM;gBACR;YACF;QACF;QACAC,WAAW;QACX,GAAI,AAACT,aAA0C,CAAC,CAAC;IACnD;AACF,EAAC"}
@@ -1,8 +1,8 @@
1
- import type { UploadInputProps } from '@payloadcms/ui';
1
+ import type { UploadFieldProps } from '@payloadcms/ui';
2
2
  import React from 'react';
3
3
  type MetaImageProps = {
4
- hasGenerateImageFn: boolean;
5
- } & UploadInputProps;
4
+ readonly hasGenerateImageFn: boolean;
5
+ } & UploadFieldProps;
6
6
  export declare const MetaImageComponent: React.FC<MetaImageProps>;
7
7
  export {};
8
8
  //# sourceMappingURL=MetaImageComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MetaImageComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAa1E,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,KAAK,cAAc,GAAG;IACpB,kBAAkB,EAAE,OAAO,CAAA;CAC5B,GAAG,gBAAgB,CAAA;AAEpB,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAuIvD,CAAA"}
1
+ {"version":3,"file":"MetaImageComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAa1E,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;CACrC,GAAG,gBAAgB,CAAA;AAEpB,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA6JvD,CAAA"}
@@ -4,7 +4,7 @@ import { FieldLabel, UploadInput, useConfig, useDocumentInfo, useField, useField
4
4
  import React, { useCallback } from 'react';
5
5
  import { Pill } from '../../ui/Pill.js';
6
6
  export const MetaImageComponent = (props)=>{
7
- const { CustomLabel, hasGenerateImageFn, label, labelProps, relationTo, required } = props || {};
7
+ const { field: { admin: { components: { Label } }, label, relationTo, required }, hasGenerateImageFn, labelProps } = props || {};
8
8
  const { path: pathFromContext } = useFieldProps();
9
9
  const field = useField({
10
10
  ...props,
@@ -19,11 +19,16 @@ export const MetaImageComponent = (props)=>{
19
19
  if (!hasGenerateImageFn) return;
20
20
  const genImageResponse = await fetch('/api/plugin-seo/generate-image', {
21
21
  body: JSON.stringify({
22
- ...docInfo,
23
- doc: {
24
- ...getData()
25
- },
26
- locale: typeof locale === 'object' ? locale?.code : locale
22
+ id: docInfo.id,
23
+ slug: docInfo.slug,
24
+ doc: getData(),
25
+ docPermissions: docInfo.docPermissions,
26
+ hasPublishPermission: docInfo.hasPublishPermission,
27
+ hasSavePermission: docInfo.hasSavePermission,
28
+ initialData: docInfo.initialData,
29
+ initialState: docInfo.initialState,
30
+ locale: typeof locale === 'object' ? locale?.code : locale,
31
+ title: docInfo.title
27
32
  }),
28
33
  credentials: 'include',
29
34
  headers: {
@@ -31,7 +36,7 @@ export const MetaImageComponent = (props)=>{
31
36
  },
32
37
  method: 'POST'
33
38
  });
34
- const { result: generatedImage } = await genImageResponse.json();
39
+ const generatedImage = await genImageResponse.text();
35
40
  setValue(generatedImage || '');
36
41
  }, [
37
42
  hasGenerateImageFn,
@@ -41,7 +46,7 @@ export const MetaImageComponent = (props)=>{
41
46
  setValue
42
47
  ]);
43
48
  const hasImage = Boolean(value);
44
- const config = useConfig();
49
+ const { config } = useConfig();
45
50
  const { collections, routes: { api } = {}, serverURL } = config;
46
51
  const collection = collections?.find((coll)=>coll.slug === relationTo) || undefined;
47
52
  return /*#__PURE__*/ _jsxs("div", {
@@ -59,7 +64,8 @@ export const MetaImageComponent = (props)=>{
59
64
  className: "plugin-seo__field",
60
65
  children: [
61
66
  /*#__PURE__*/ _jsx(FieldLabel, {
62
- CustomLabel: CustomLabel,
67
+ Label: Label,
68
+ field: null,
63
69
  label: label,
64
70
  ...labelProps || {}
65
71
  }),
@@ -100,7 +106,11 @@ export const MetaImageComponent = (props)=>{
100
106
  position: 'relative'
101
107
  },
102
108
  children: /*#__PURE__*/ _jsx(UploadInput, {
103
- CustomError: errorMessage,
109
+ Error: {
110
+ type: 'client',
111
+ Component: null,
112
+ RenderedComponent: errorMessage
113
+ },
104
114
  api: api,
105
115
  collection: collection,
106
116
  filterOptions: field.filterOptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options, UploadInputProps } from '@payloadcms/ui'\n\nimport {\n FieldLabel,\n UploadInput,\n useConfig,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateImage } from '../../types.js'\n\nimport { Pill } from '../../ui/Pill.js'\n\ntype MetaImageProps = {\n hasGenerateImageFn: boolean\n} & UploadInputProps\n\nexport const MetaImageComponent: React.FC<MetaImageProps> = (props) => {\n const { CustomLabel, hasGenerateImageFn, label, labelProps, relationTo, required } = props || {}\n const { path: pathFromContext } = useFieldProps()\n\n const field: FieldType<string> = useField({ ...props, path: pathFromContext } as Options)\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateImage = useCallback(async () => {\n if (!hasGenerateImageFn) return\n\n const genImageResponse = await fetch('/api/plugin-seo/generate-image', {\n body: JSON.stringify({\n ...docInfo,\n doc: { ...getData() },\n locale: typeof locale === 'object' ? locale?.code : locale,\n } satisfies Parameters<GenerateImage>[0]),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: generatedImage } = await genImageResponse.json()\n\n setValue(generatedImage || '')\n }, [hasGenerateImageFn, docInfo, getData, locale, setValue])\n\n const hasImage = Boolean(value)\n\n const config = useConfig()\n\n const { collections, routes: { api } = {}, serverURL } = config\n\n const collection = collections?.find((coll) => coll.slug === relationTo) || undefined\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel CustomLabel={CustomLabel} label={label} {...(labelProps || {})} />\n {hasGenerateImageFn && (\n <React.Fragment>\n &nbsp; &mdash; &nbsp;\n <button\n onClick={() => {\n void regenerateImage()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n {hasGenerateImageFn && (\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:imageAutoGenerationTip')}\n </div>\n )}\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <UploadInput\n CustomError={errorMessage}\n api={api}\n collection={collection}\n filterOptions={field.filterOptions}\n label={undefined}\n onChange={(incomingImage) => {\n if (incomingImage !== null) {\n const { id: incomingID } = incomingImage\n setValue(incomingID)\n } else {\n setValue(null)\n }\n }}\n relationTo={relationTo}\n required={required}\n serverURL={serverURL}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <Pill\n backgroundColor={hasImage ? 'green' : 'red'}\n color=\"white\"\n label={hasImage ? t('plugin-seo:good') : t('plugin-seo:noImage')}\n />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","UploadInput","useConfig","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","Pill","MetaImageComponent","props","CustomLabel","hasGenerateImageFn","label","labelProps","relationTo","required","path","pathFromContext","field","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateImage","genImageResponse","fetch","body","JSON","stringify","doc","code","credentials","headers","method","result","generatedImage","json","hasImage","Boolean","config","collections","routes","api","serverURL","collection","find","coll","slug","undefined","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","CustomError","filterOptions","onChange","incomingImage","id","incomingID","alignItems","display","width"],"mappings":"AAAA;;AAIA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,IAAI,QAAQ,mBAAkB;AAMvC,OAAO,MAAMC,qBAA+C,CAACC;IAC3D,MAAM,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,KAAK,EAAEC,UAAU,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGN,SAAS,CAAC;IAC/F,MAAM,EAAEO,MAAMC,eAAe,EAAE,GAAGhB;IAElC,MAAMiB,QAA2BlB,SAAS;QAAE,GAAGS,KAAK;QAAEO,MAAMC;IAAgB;IAE5E,MAAM,EAAEE,CAAC,EAAE,GAAGf;IAEd,MAAMgB,SAASjB;IACf,MAAM,EAAEkB,OAAO,EAAE,GAAGnB;IACpB,MAAMoB,UAAUvB;IAEhB,MAAM,EAAEwB,YAAY,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGR;IAErD,MAAMS,kBAAkBrB,YAAY;QAClC,IAAI,CAACK,oBAAoB;QAEzB,MAAMiB,mBAAmB,MAAMC,MAAM,kCAAkC;YACrEC,MAAMC,KAAKC,SAAS,CAAC;gBACnB,GAAGV,OAAO;gBACVW,KAAK;oBAAE,GAAGZ,SAAS;gBAAC;gBACpBD,QAAQ,OAAOA,WAAW,WAAWA,QAAQc,OAAOd;YACtD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,EAAEC,IAAIC,UAAU,EAAE,GAAGF;4BAC3BhD,SAASkD;wBACX,OAAO;4BACLlD,SAAS;wBACX;oBACF;oBACAV,YAAYA;oBACZC,UAAUA;oBACVgC,WAAWA;oBACXtB,WAAWA;oBACX6B,OAAO;wBACLC,cAAc;oBAChB;oBACA7B,OAAOA;;;0BAGX,KAAC2B;gBACCC,OAAO;oBACLqB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAACtE;oBACCuD,iBAAiBrB,WAAW,UAAU;oBACtCuB,OAAM;oBACNpD,OAAO6B,WAAWtB,EAAE,qBAAqBA,EAAE;;;;;AAKrD,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options, UploadFieldProps } from '@payloadcms/ui'\n\nimport {\n FieldLabel,\n UploadInput,\n useConfig,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateImage } from '../../types.js'\n\nimport { Pill } from '../../ui/Pill.js'\n\ntype MetaImageProps = {\n readonly hasGenerateImageFn: boolean\n} & UploadFieldProps\n\nexport const MetaImageComponent: React.FC<MetaImageProps> = (props) => {\n const {\n field: {\n admin: {\n components: { Label },\n },\n label,\n relationTo,\n required,\n },\n hasGenerateImageFn,\n labelProps,\n } = props || {}\n const { path: pathFromContext } = useFieldProps()\n\n const field: FieldType<string> = useField({ ...props, path: pathFromContext } as Options)\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateImage = useCallback(async () => {\n if (!hasGenerateImageFn) return\n\n const genImageResponse = await fetch('/api/plugin-seo/generate-image', {\n body: JSON.stringify({\n id: docInfo.id,\n slug: docInfo.slug,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\n hasPublishPermission: docInfo.hasPublishPermission,\n hasSavePermission: docInfo.hasSavePermission,\n initialData: docInfo.initialData,\n initialState: docInfo.initialState,\n locale: typeof locale === 'object' ? locale?.code : locale,\n title: docInfo.title,\n } satisfies Omit<Parameters<GenerateImage>[0], 'req'>),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const generatedImage = await genImageResponse.text()\n\n setValue(generatedImage || '')\n }, [hasGenerateImageFn, docInfo, getData, locale, setValue])\n\n const hasImage = Boolean(value)\n\n const { config } = useConfig()\n\n const { collections, routes: { api } = {}, serverURL } = config\n\n const collection = collections?.find((coll) => coll.slug === relationTo) || undefined\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel Label={Label} field={null} label={label} {...(labelProps || {})} />\n {hasGenerateImageFn && (\n <React.Fragment>\n &nbsp; &mdash; &nbsp;\n <button\n onClick={() => {\n void regenerateImage()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n {hasGenerateImageFn && (\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:imageAutoGenerationTip')}\n </div>\n )}\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <UploadInput\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n api={api}\n collection={collection}\n filterOptions={field.filterOptions}\n label={undefined}\n onChange={(incomingImage) => {\n if (incomingImage !== null) {\n const { id: incomingID } = incomingImage\n setValue(incomingID)\n } else {\n setValue(null)\n }\n }}\n relationTo={relationTo}\n required={required}\n serverURL={serverURL}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <Pill\n backgroundColor={hasImage ? 'green' : 'red'}\n color=\"white\"\n label={hasImage ? t('plugin-seo:good') : t('plugin-seo:noImage')}\n />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","UploadInput","useConfig","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","Pill","MetaImageComponent","props","field","admin","components","Label","label","relationTo","required","hasGenerateImageFn","labelProps","path","pathFromContext","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateImage","genImageResponse","fetch","body","JSON","stringify","id","slug","doc","docPermissions","hasPublishPermission","hasSavePermission","initialData","initialState","code","title","credentials","headers","method","generatedImage","text","hasImage","Boolean","config","collections","routes","api","serverURL","collection","find","coll","undefined","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","Error","Component","RenderedComponent","filterOptions","onChange","incomingImage","incomingID","alignItems","display","width"],"mappings":"AAAA;;AAIA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,IAAI,QAAQ,mBAAkB;AAMvC,OAAO,MAAMC,qBAA+C,CAACC;IAC3D,MAAM,EACJC,OAAO,EACLC,OAAO,EACLC,YAAY,EAAEC,KAAK,EAAE,EACtB,EACDC,KAAK,EACLC,UAAU,EACVC,QAAQ,EACT,EACDC,kBAAkB,EAClBC,UAAU,EACX,GAAGT,SAAS,CAAC;IACd,MAAM,EAAEU,MAAMC,eAAe,EAAE,GAAGnB;IAElC,MAAMS,QAA2BV,SAAS;QAAE,GAAGS,KAAK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;oBACdC,UAAU;gBACZ;;kCAEA,MAACH;wBAAII,WAAU;;0CACb,KAACrE;gCAAWiB,OAAOA;gCAAOH,OAAO;gCAAMI,OAAOA;gCAAQ,GAAII,cAAc,CAAC,CAAC;;4BACzED,oCACC,MAACZ,MAAM6D,QAAQ;;oCAAC;kDAEd,KAACC;wCACCC,SAAS;4CACP,KAAKvC;wCACP;wCACAiC,OAAO;4CACLO,YAAY;4CACZC,iBAAiB;4CACjBC,QAAQ;4CACRC,OAAO;4CACPC,QAAQ;4CACRC,SAAS;4CACTC,gBAAgB;wCAClB;wCACAC,MAAK;kDAEJvD,EAAE;;;;;;oBAKVJ,oCACC,KAAC4C;wBACCC,OAAO;4BACLU,OAAO;wBACT;kCAECnD,EAAE;;;;0BAIT,KAACwC;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAACnE;oBACCgF,OAAO;wBACLD,MAAM;wBACNE,WAAW;wBACXC,mBAAmBtD;oBACrB;oBACA8B,KAAKA;oBACLE,YAAYA;oBACZuB,eAAetE,MAAMsE,aAAa;oBAClClE,OAAO8C;oBACPqB,UAAU,CAACC;wBACT,IAAIA,kBAAkB,MAAM;4BAC1B,MAAM,EAAE/C,IAAIgD,UAAU,EAAE,GAAGD;4BAC3BxD,SAASyD;wBACX,OAAO;4BACLzD,SAAS;wBACX;oBACF;oBACAX,YAAYA;oBACZC,UAAUA;oBACVwC,WAAWA;oBACX7B,WAAWA;oBACXmC,OAAO;wBACLC,cAAc;oBAChB;oBACAnC,OAAOA;;;0BAGX,KAACiC;gBACCC,OAAO;oBACLsB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAAC/E;oBACC+D,iBAAiBpB,WAAW,UAAU;oBACtCsB,OAAM;oBACN1D,OAAOoC,WAAW7B,EAAE,qBAAqBA,EAAE;;;;;AAKrD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAM1C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,WAAW,CAAA;AAEtF,eAAO,MAAM,cAAc,EAAE,aAqB5B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,WAAW,CAAA;AAEtF,eAAO,MAAM,cAAc,EAAE,aAoB5B,CAAA"}
@@ -1,18 +1,15 @@
1
- import { withMergedProps } from '@payloadcms/ui/shared';
2
- import { MetaImageComponent } from './MetaImageComponent.js';
3
1
  export const MetaImageField = ({ hasGenerateFn = false, overrides, relationTo })=>{
4
2
  return {
5
3
  name: 'image',
6
4
  type: 'upload',
7
5
  admin: {
8
6
  components: {
9
- Field: withMergedProps({
10
- Component: MetaImageComponent,
11
- sanitizeServerOnlyProps: true,
12
- toMergeIntoProps: {
7
+ Field: {
8
+ clientProps: {
13
9
  hasGenerateImageFn: hasGenerateFn
14
- }
15
- })
10
+ },
11
+ path: '@payloadcms/plugin-seo/client#MetaImageComponent'
12
+ }
16
13
  },
17
14
  description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.'
18
15
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/MetaImage/index.ts"],"sourcesContent":["import type { UploadField } from 'payload'\n\nimport { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { MetaImageComponent } from './MetaImageComponent.js'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<UploadField>\n relationTo: string\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UploadField\n\nexport const MetaImageField: FieldFunction = ({ hasGenerateFn = false, overrides, relationTo }) => {\n return {\n name: 'image',\n type: 'upload',\n admin: {\n components: {\n Field: withMergedProps({\n Component: MetaImageComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n hasGenerateImageFn: hasGenerateFn,\n },\n }),\n },\n description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.',\n },\n label: 'Meta Image',\n localized: true,\n relationTo,\n ...((overrides as unknown as UploadField) ?? {}),\n }\n}\n"],"names":["withMergedProps","MetaImageComponent","MetaImageField","hasGenerateFn","overrides","relationTo","name","type","admin","components","Field","Component","sanitizeServerOnlyProps","toMergeIntoProps","hasGenerateImageFn","description","label","localized"],"mappings":"AAEA,SAASA,eAAe,QAAQ,wBAAuB;AAEvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAa5D,OAAO,MAAMC,iBAAgC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE;IAC5F,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAOV,gBAAgB;oBACrBW,WAAWV;oBACXW,yBAAyB;oBACzBC,kBAAkB;wBAChBC,oBAAoBX;oBACtB;gBACF;YACF;YACAY,aAAa;QACf;QACAC,OAAO;QACPC,WAAW;QACXZ;QACA,GAAI,AAACD,aAAwC,CAAC,CAAC;IACjD;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/MetaImage/index.ts"],"sourcesContent":["import type { UploadField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<UploadField>\n relationTo: string\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UploadField\n\nexport const MetaImageField: FieldFunction = ({ hasGenerateFn = false, overrides, relationTo }) => {\n return {\n name: 'image',\n type: 'upload',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateImageFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaImageComponent',\n },\n },\n description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.',\n },\n label: 'Meta Image',\n localized: true,\n relationTo,\n ...((overrides as unknown as UploadField) ?? {}),\n }\n}\n"],"names":["MetaImageField","hasGenerateFn","overrides","relationTo","name","type","admin","components","Field","clientProps","hasGenerateImageFn","path","description","label","localized"],"mappings":"AAaA,OAAO,MAAMA,iBAAgC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE;IAC5F,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,oBAAoBT;oBACtB;oBACAU,MAAM;gBACR;YACF;YACAC,aAAa;QACf;QACAC,OAAO;QACPC,WAAW;QACXX;QACA,GAAI,AAACD,aAAwC,CAAC,CAAC;IACjD;AACF,EAAC"}
@@ -1,9 +1,9 @@
1
- import type { FormFieldBase } from 'payload';
1
+ import type { TextFieldProps } from 'payload';
2
2
  import React from 'react';
3
3
  import '../index.scss';
4
4
  type MetaTitleProps = {
5
- hasGenerateTitleFn: boolean;
6
- } & FormFieldBase;
5
+ readonly hasGenerateTitleFn: boolean;
6
+ } & TextFieldProps;
7
7
  export declare const MetaTitleComponent: React.FC<MetaTitleProps>;
8
8
  export {};
9
9
  //# sourceMappingURL=MetaTitleComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MetaTitleComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAY5C,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,OAAO,eAAe,CAAA;AAItB,KAAK,cAAc,GAAG;IACpB,kBAAkB,EAAE,OAAO,CAAA;CAC5B,GAAG,aAAa,CAAA;AAEjB,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAuHvD,CAAA"}
1
+ {"version":3,"file":"MetaTitleComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAY7C,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,OAAO,eAAe,CAAA;AAItB,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;CACrC,GAAG,cAAc,CAAA;AAElB,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA6IvD,CAAA"}
@@ -7,7 +7,7 @@ import { LengthIndicator } from '../../ui/LengthIndicator.js';
7
7
  import '../index.scss';
8
8
  const { maxLength, minLength } = defaults.title;
9
9
  export const MetaTitleComponent = (props)=>{
10
- const { CustomLabel, hasGenerateTitleFn, label, labelProps, required } = props || {};
10
+ const { field: { admin: { components: { Label } }, label, required }, hasGenerateTitleFn, labelProps } = props || {};
11
11
  const { path: pathFromContext } = useFieldProps();
12
12
  const { t } = useTranslation();
13
13
  const field = useField({
@@ -21,11 +21,16 @@ export const MetaTitleComponent = (props)=>{
21
21
  if (!hasGenerateTitleFn) return;
22
22
  const genTitleResponse = await fetch('/api/plugin-seo/generate-title', {
23
23
  body: JSON.stringify({
24
- ...docInfo,
25
- doc: {
26
- ...getData()
27
- },
28
- locale: typeof locale === 'object' ? locale?.code : locale
24
+ id: docInfo.id,
25
+ slug: docInfo.slug,
26
+ doc: getData(),
27
+ docPermissions: docInfo.docPermissions,
28
+ hasPublishPermission: docInfo.hasPublishPermission,
29
+ hasSavePermission: docInfo.hasSavePermission,
30
+ initialData: docInfo.initialData,
31
+ initialState: docInfo.initialState,
32
+ locale: typeof locale === 'object' ? locale?.code : locale,
33
+ title: docInfo.title
29
34
  }),
30
35
  credentials: 'include',
31
36
  headers: {
@@ -57,7 +62,8 @@ export const MetaTitleComponent = (props)=>{
57
62
  className: "plugin-seo__field",
58
63
  children: [
59
64
  /*#__PURE__*/ _jsx(FieldLabel, {
60
- CustomLabel: CustomLabel,
65
+ Label: Label,
66
+ field: null,
61
67
  label: label,
62
68
  ...labelProps || {}
63
69
  }),
@@ -110,7 +116,12 @@ export const MetaTitleComponent = (props)=>{
110
116
  position: 'relative'
111
117
  },
112
118
  children: /*#__PURE__*/ _jsx(TextInput, {
113
- CustomError: errorMessage,
119
+ Error: {
120
+ type: 'client',
121
+ Component: null,
122
+ RenderedComponent: errorMessage
123
+ },
124
+ label: label,
114
125
  onChange: setValue,
115
126
  path: pathFromContext,
116
127
  required: required,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { FormFieldBase } from 'payload'\n\nimport {\n FieldLabel,\n TextInput,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateTitle } from '../../types.js'\n\nimport { defaults } from '../../defaults.js'\nimport { LengthIndicator } from '../../ui/LengthIndicator.js'\nimport '../index.scss'\n\nconst { maxLength, minLength } = defaults.title\n\ntype MetaTitleProps = {\n hasGenerateTitleFn: boolean\n} & FormFieldBase\n\nexport const MetaTitleComponent: React.FC<MetaTitleProps> = (props) => {\n const { CustomLabel, hasGenerateTitleFn, label, labelProps, required } = props || {}\n const { path: pathFromContext } = useFieldProps()\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const field: FieldType<string> = useField({\n path: pathFromContext,\n } as Options)\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateTitle = useCallback(async () => {\n if (!hasGenerateTitleFn) return\n\n const genTitleResponse = await fetch('/api/plugin-seo/generate-title', {\n body: JSON.stringify({\n ...docInfo,\n doc: { ...getData() },\n locale: typeof locale === 'object' ? locale?.code : locale,\n } satisfies Parameters<GenerateTitle>[0]),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: generatedTitle } = await genTitleResponse.json()\n\n setValue(generatedTitle || '')\n }, [hasGenerateTitleFn, docInfo, getData, locale, setValue])\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel CustomLabel={CustomLabel} label={label} {...(labelProps || {})} />\n {hasGenerateTitleFn && (\n <React.Fragment>\n &nbsp; &mdash; &nbsp;\n <button\n onClick={() => {\n void regenerateTitle()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:lengthTipTitle', { maxLength, minLength })}\n <a\n href=\"https://developers.google.com/search/docs/advanced/appearance/title-link#page-titles\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {t('plugin-seo:bestPractices')}\n </a>\n .\n </div>\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <TextInput\n CustomError={errorMessage}\n onChange={setValue}\n path={pathFromContext}\n required={required}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <LengthIndicator maxLength={maxLength} minLength={minLength} text={value} />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","TextInput","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","title","MetaTitleComponent","props","CustomLabel","hasGenerateTitleFn","label","labelProps","required","path","pathFromContext","t","field","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateTitle","genTitleResponse","fetch","body","JSON","stringify","doc","code","credentials","headers","method","result","generatedTitle","json","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","a","href","rel","target","CustomError","onChange","alignItems","display","width","text"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,OAAO,gBAAe;AAEtB,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH,SAASI,KAAK;AAM/C,OAAO,MAAMC,qBAA+C,CAACC;IAC3D,MAAM,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,KAAK,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGL,SAAS,CAAC;IACnF,MAAM,EAAEM,MAAMC,eAAe,EAAE,GAAGnB;IAElC,MAAM,EA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,EAAE,6BAA6B;gCAAEZ;gCAAWC;4BAAU;0CACvD,KAACkD;gCACCC,MAAK;gCACLC,KAAI;gCACJC,QAAO;0CAEN1C,EAAE;;4BACD;;;;;0BAIR,KAACuB;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAACjD;oBACCkE,aAAatC;oBACbuC,UAAUtC;oBACVR,MAAMC;oBACNF,UAAUA;oBACVU,WAAWA;oBACXiB,OAAO;wBACLC,cAAc;oBAChB;oBACAjB,OAAOA;;;0BAGX,KAACe;gBACCC,OAAO;oBACLqB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAAC5D;oBAAgBC,WAAWA;oBAAWC,WAAWA;oBAAW2D,MAAMxC;;;;;AAI3E,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { TextFieldProps } from 'payload'\n\nimport {\n FieldLabel,\n TextInput,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateTitle } from '../../types.js'\n\nimport { defaults } from '../../defaults.js'\nimport { LengthIndicator } from '../../ui/LengthIndicator.js'\nimport '../index.scss'\n\nconst { maxLength, minLength } = defaults.title\n\ntype MetaTitleProps = {\n readonly hasGenerateTitleFn: boolean\n} & TextFieldProps\n\nexport const MetaTitleComponent: React.FC<MetaTitleProps> = (props) => {\n const {\n field: {\n admin: {\n components: { Label },\n },\n label,\n required,\n },\n hasGenerateTitleFn,\n labelProps,\n } = props || {}\n const { path: pathFromContext } = useFieldProps()\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const field: FieldType<string> = useField({\n path: pathFromContext,\n } as Options)\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateTitle = useCallback(async () => {\n if (!hasGenerateTitleFn) return\n\n const genTitleResponse = await fetch('/api/plugin-seo/generate-title', {\n body: JSON.stringify({\n id: docInfo.id,\n slug: docInfo.slug,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\n hasPublishPermission: docInfo.hasPublishPermission,\n hasSavePermission: docInfo.hasSavePermission,\n initialData: docInfo.initialData,\n initialState: docInfo.initialState,\n locale: typeof locale === 'object' ? locale?.code : locale,\n title: docInfo.title,\n } satisfies Omit<Parameters<GenerateTitle>[0], 'req'>),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: generatedTitle } = await genTitleResponse.json()\n\n setValue(generatedTitle || '')\n }, [hasGenerateTitleFn, docInfo, getData, locale, setValue])\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel Label={Label} field={null} label={label} {...(labelProps || {})} />\n {hasGenerateTitleFn && (\n <React.Fragment>\n &nbsp; &mdash; &nbsp;\n <button\n onClick={() => {\n void regenerateTitle()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:lengthTipTitle', { maxLength, minLength })}\n <a\n href=\"https://developers.google.com/search/docs/advanced/appearance/title-link#page-titles\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {t('plugin-seo:bestPractices')}\n </a>\n .\n </div>\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <TextInput\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n label={label}\n onChange={setValue}\n path={pathFromContext}\n required={required}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <LengthIndicator maxLength={maxLength} minLength={minLength} text={value} />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","TextInput","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","title","MetaTitleComponent","props","field","admin","components","Label","label","required","hasGenerateTitleFn","labelProps","path","pathFromContext","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateTitle","genTitleResponse","fetch","body","JSON","stringify","id","slug","doc","docPermissions","hasPublishPermission","hasSavePermission","initialData","initialState","code","credentials","headers","method","result","generatedTitle","json","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","a","href","rel","target","Error","Component","RenderedComponent","onChange","alignItems","display","width","text"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,OAAO,gBAAe;AAEtB,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH,SAASI,KAAK;AAM/C,OAAO,MAAMC,qBAA+C,CAACC;IAC3D,MAAM,EACJC,OAAO,EACLC,OAAO,EACLC,YAAY,EAAEC,KAAK,EAAE,EACtB,EACDC,KAAK,EACLC,QAAQ,EACT,EACDC,kBAAkB,EAClBC,UAAU,EACX,GAAGR,SAAS,CAAC;IACd,MAAM,EAAES,MAAMC,eAAe,EAAE,GAAGtB;IA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AS;4CACP,KAAK5B;wCACP;wCACAsB,OAAO;4CACLO,YAAY;4CACZC,iBAAiB;4CACjBC,QAAQ;4CACRC,OAAO;4CACPC,QAAQ;4CACRC,SAAS;4CACTC,gBAAgB;wCAClB;wCACAC,MAAK;kDAEJ5C,EAAE;;;;;;kCAKX,MAAC6B;wBACCC,OAAO;4BACLU,OAAO;wBACT;;4BAECxC,EAAE,6BAA6B;gCAAEf;gCAAWC;4BAAU;0CACvD,KAAC2D;gCACCC,MAAK;gCACLC,KAAI;gCACJC,QAAO;0CAENhD,EAAE;;4BACD;;;;;0BAIR,KAAC6B;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAAC1D;oBACC2E,OAAO;wBACLL,MAAM;wBACNM,WAAW;wBACXC,mBAAmB/C;oBACrB;oBACAV,OAAOA;oBACP0D,UAAU/C;oBACVP,MAAMC;oBACNJ,UAAUA;oBACVW,WAAWA;oBACXwB,OAAO;wBACLC,cAAc;oBAChB;oBACAxB,OAAOA;;;0BAGX,KAACsB;gBACCC,OAAO;oBACLuB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAACvE;oBAAgBC,WAAWA;oBAAWC,WAAWA;oBAAWsE,MAAMjD;;;;;AAI3E,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAMxC,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;CAC/B;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,SAAS,CAAA;AAEpF,eAAO,MAAM,cAAc,EAAE,aAkB5B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;CAC/B;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,SAAS,CAAA;AAEpF,eAAO,MAAM,cAAc,EAAE,aAiB5B,CAAA"}
@@ -1,18 +1,15 @@
1
- import { withMergedProps } from '@payloadcms/ui/shared';
2
- import { MetaTitleComponent } from './MetaTitleComponent.js';
3
1
  export const MetaTitleField = ({ hasGenerateFn = false, overrides })=>{
4
2
  return {
5
3
  name: 'title',
6
4
  type: 'text',
7
5
  admin: {
8
6
  components: {
9
- Field: withMergedProps({
10
- Component: MetaTitleComponent,
11
- sanitizeServerOnlyProps: true,
12
- toMergeIntoProps: {
7
+ Field: {
8
+ clientProps: {
13
9
  hasGenerateTitleFn: hasGenerateFn
14
- }
15
- })
10
+ },
11
+ path: '@payloadcms/plugin-seo/client#MetaTitleComponent'
12
+ }
16
13
  }
17
14
  },
18
15
  localized: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/MetaTitle/index.ts"],"sourcesContent":["import type { TextField } from 'payload'\n\nimport { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { MetaTitleComponent } from './MetaTitleComponent.js'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<TextField>\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextField\n\nexport const MetaTitleField: FieldFunction = ({ hasGenerateFn = false, overrides }) => {\n return {\n name: 'title',\n type: 'text',\n admin: {\n components: {\n Field: withMergedProps({\n Component: MetaTitleComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n hasGenerateTitleFn: hasGenerateFn,\n },\n }),\n },\n },\n localized: true,\n ...((overrides as unknown as TextField) ?? {}),\n }\n}\n"],"names":["withMergedProps","MetaTitleComponent","MetaTitleField","hasGenerateFn","overrides","name","type","admin","components","Field","Component","sanitizeServerOnlyProps","toMergeIntoProps","hasGenerateTitleFn","localized"],"mappings":"AAEA,SAASA,eAAe,QAAQ,wBAAuB;AAEvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAY5D,OAAO,MAAMC,iBAAgC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAE;IAChF,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAOT,gBAAgB;oBACrBU,WAAWT;oBACXU,yBAAyB;oBACzBC,kBAAkB;wBAChBC,oBAAoBV;oBACtB;gBACF;YACF;QACF;QACAW,WAAW;QACX,GAAI,AAACV,aAAsC,CAAC,CAAC;IAC/C;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/MetaTitle/index.ts"],"sourcesContent":["import type { TextField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<TextField>\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextField\n\nexport const MetaTitleField: FieldFunction = ({ hasGenerateFn = false, overrides }) => {\n return {\n name: 'title',\n type: 'text',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateTitleFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaTitleComponent',\n },\n },\n },\n localized: true,\n ...((overrides as unknown as TextField) ?? {}),\n }\n}\n"],"names":["MetaTitleField","hasGenerateFn","overrides","name","type","admin","components","Field","clientProps","hasGenerateTitleFn","path","localized"],"mappings":"AAYA,OAAO,MAAMA,iBAAgC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAE;IAChF,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,oBAAoBR;oBACtB;oBACAS,MAAM;gBACR;YACF;QACF;QACAC,WAAW;QACX,GAAI,AAACT,aAAsC,CAAC,CAAC;IAC/C;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Overview/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAA;AAEnE,eAAO,MAAM,aAAa,EAAE,aAyB3B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Overview/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAA;AAEnE,eAAO,MAAM,aAAa,EAAE,aAwB3B,CAAA"}
@@ -1,20 +1,17 @@
1
- import { withMergedProps } from '@payloadcms/ui/shared';
2
- import { OverviewComponent } from './OverviewComponent.js';
3
1
  export const OverviewField = ({ descriptionPath, imagePath, overrides, titlePath })=>{
4
2
  return {
5
3
  name: 'overview',
6
4
  type: 'ui',
7
5
  admin: {
8
6
  components: {
9
- Field: withMergedProps({
10
- Component: OverviewComponent,
11
- sanitizeServerOnlyProps: true,
12
- toMergeIntoProps: {
7
+ Field: {
8
+ clientProps: {
13
9
  descriptionPath,
14
10
  imagePath,
15
11
  titlePath
16
- }
17
- })
12
+ },
13
+ path: '@payloadcms/plugin-seo/client#OverviewComponent'
14
+ }
18
15
  }
19
16
  },
20
17
  label: 'Overview',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Overview/index.tsx"],"sourcesContent":["import type { UIField } from 'payload'\n\nimport { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { OverviewComponent } from './OverviewComponent.js'\n\ninterface FieldFunctionProps {\n /**\n * Path to the description field to use for the preview\n *\n * @default 'meta.description'\n */\n descriptionPath?: string\n /**\n * Path to the image field to use for the preview\n *\n * @default 'meta.image'\n */\n imagePath?: string\n overrides?: Partial<UIField>\n /**\n * Path to the title field to use for the preview\n *\n * @default 'meta.title'\n */\n titlePath?: string\n}\n\ntype FieldFunction = ({ overrides }: FieldFunctionProps) => UIField\n\nexport const OverviewField: FieldFunction = ({\n descriptionPath,\n imagePath,\n overrides,\n titlePath,\n}) => {\n return {\n name: 'overview',\n type: 'ui',\n admin: {\n components: {\n Field: withMergedProps({\n Component: OverviewComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n descriptionPath,\n imagePath,\n titlePath,\n },\n }),\n },\n },\n label: 'Overview',\n ...((overrides as unknown as UIField) ?? {}),\n }\n}\n"],"names":["withMergedProps","OverviewComponent","OverviewField","descriptionPath","imagePath","overrides","titlePath","name","type","admin","components","Field","Component","sanitizeServerOnlyProps","toMergeIntoProps","label"],"mappings":"AAEA,SAASA,eAAe,QAAQ,wBAAuB;AAEvD,SAASC,iBAAiB,QAAQ,yBAAwB;AA0B1D,OAAO,MAAMC,gBAA+B,CAAC,EAC3CC,eAAe,EACfC,SAAS,EACTC,SAAS,EACTC,SAAS,EACV;IACC,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAOX,gBAAgB;oBACrBY,WAAWX;oBACXY,yBAAyB;oBACzBC,kBAAkB;wBAChBX;wBACAC;wBACAE;oBACF;gBACF;YACF;QACF;QACAS,OAAO;QACP,GAAI,AAACV,aAAoC,CAAC,CAAC;IAC7C;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/Overview/index.tsx"],"sourcesContent":["import type { UIField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Path to the description field to use for the preview\n *\n * @default 'meta.description'\n */\n descriptionPath?: string\n /**\n * Path to the image field to use for the preview\n *\n * @default 'meta.image'\n */\n imagePath?: string\n overrides?: Partial<UIField>\n /**\n * Path to the title field to use for the preview\n *\n * @default 'meta.title'\n */\n titlePath?: string\n}\n\ntype FieldFunction = ({ overrides }: FieldFunctionProps) => UIField\n\nexport const OverviewField: FieldFunction = ({\n descriptionPath,\n imagePath,\n overrides,\n titlePath,\n}) => {\n return {\n name: 'overview',\n type: 'ui',\n admin: {\n components: {\n Field: {\n clientProps: {\n descriptionPath,\n imagePath,\n titlePath,\n },\n path: '@payloadcms/plugin-seo/client#OverviewComponent',\n },\n },\n },\n label: 'Overview',\n ...((overrides as unknown as UIField) ?? {}),\n }\n}\n"],"names":["OverviewField","descriptionPath","imagePath","overrides","titlePath","name","type","admin","components","Field","clientProps","path","label"],"mappings":"AA0BA,OAAO,MAAMA,gBAA+B,CAAC,EAC3CC,eAAe,EACfC,SAAS,EACTC,SAAS,EACTC,SAAS,EACV;IACC,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXT;wBACAC;wBACAE;oBACF;oBACAO,MAAM;gBACR;YACF;QACF;QACAC,OAAO;QACP,GAAI,AAACT,aAAoC,CAAC,CAAC;IAC7C;AACF,EAAC"}
@@ -1,9 +1,9 @@
1
1
  import type { UIField } from 'payload';
2
2
  import React from 'react';
3
3
  type PreviewProps = {
4
- descriptionPath?: string;
5
- hasGenerateURLFn: boolean;
6
- titlePath?: string;
4
+ readonly descriptionPath?: string;
5
+ readonly hasGenerateURLFn: boolean;
6
+ readonly titlePath?: string;
7
7
  } & UIField;
8
8
  export declare const PreviewComponent: React.FC<PreviewProps>;
9
9
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"PreviewComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/Preview/PreviewComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,SAAS,CAAA;AAUjD,OAAO,KAA8B,MAAM,OAAO,CAAA;AAKlD,KAAK,YAAY,GAAG;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,OAAO,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAA;AAEX,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAuGnD,CAAA"}
1
+ {"version":3,"file":"PreviewComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/Preview/PreviewComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,SAAS,CAAA;AASjD,OAAO,KAA8B,MAAM,OAAO,CAAA;AAKlD,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAA;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B,GAAG,OAAO,CAAA;AAEX,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA+GnD,CAAA"}
@@ -2,7 +2,8 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useAllFormFields, useDocumentInfo, useForm, useLocale, useTranslation } from '@payloadcms/ui';
4
4
  import React, { useEffect, useState } from 'react';
5
- export const PreviewComponent = ({ descriptionPath: descriptionPathFromContext, hasGenerateURLFn, titlePath: titlePathFromContext })=>{
5
+ export const PreviewComponent = (props)=>{
6
+ const { descriptionPath: descriptionPathFromContext, hasGenerateURLFn, titlePath: titlePathFromContext } = props;
6
7
  const { t } = useTranslation();
7
8
  const locale = useLocale();
8
9
  const [fields] = useAllFormFields();
@@ -16,11 +17,15 @@ export const PreviewComponent = ({ descriptionPath: descriptionPathFromContext,
16
17
  const getHref = async ()=>{
17
18
  const genURLResponse = await fetch('/api/plugin-seo/generate-url', {
18
19
  body: JSON.stringify({
19
- ...docInfo,
20
- doc: {
21
- ...getData()
22
- },
23
- locale: typeof locale === 'object' ? locale?.code : locale
20
+ id: docInfo.id,
21
+ doc: getData(),
22
+ docPermissions: docInfo.docPermissions,
23
+ hasPublishPermission: docInfo.hasPublishPermission,
24
+ hasSavePermission: docInfo.hasSavePermission,
25
+ initialData: docInfo.initialData,
26
+ initialState: docInfo.initialState,
27
+ locale: typeof locale === 'object' ? locale?.code : locale,
28
+ title: docInfo.title
24
29
  }),
25
30
  credentials: 'include',
26
31
  headers: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Preview/PreviewComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FormField, UIField } from 'payload'\n\nimport {\n useAllFormFields,\n useDocumentInfo,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport { get } from 'http'\nimport React, { useEffect, useState } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateURL } from '../../types.js'\n\ntype PreviewProps = {\n descriptionPath?: string\n hasGenerateURLFn: boolean\n titlePath?: string\n} & UIField\n\nexport const PreviewComponent: React.FC<PreviewProps> = ({\n descriptionPath: descriptionPathFromContext,\n hasGenerateURLFn,\n titlePath: titlePathFromContext,\n}) => {\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const [fields] = useAllFormFields()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const descriptionPath = descriptionPathFromContext || 'meta.description'\n const titlePath = titlePathFromContext || 'meta.title'\n\n const {\n [descriptionPath]: { value: metaDescription } = {} as FormField,\n [titlePath]: { value: metaTitle } = {} as FormField,\n } = fields\n\n const [href, setHref] = useState<string>()\n\n useEffect(() => {\n const getHref = async () => {\n const genURLResponse = await fetch('/api/plugin-seo/generate-url', {\n body: JSON.stringify({\n ...docInfo,\n doc: { ...getData() },\n locale: typeof locale === 'object' ? locale?.code : locale,\n } satisfies Parameters<GenerateURL>[0]),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: newHref } = await genURLResponse.json()\n\n setHref(newHref)\n }\n\n if (hasGenerateURLFn && !href) {\n void getHref()\n }\n }, [fields, href, locale, docInfo, hasGenerateURLFn, getData])\n\n return (\n <div>\n <div>{t('plugin-seo:preview')}</div>\n <div\n style={{\n color: '#9A9A9A',\n marginBottom: '5px',\n }}\n >\n {t('plugin-seo:previewDescription')}\n </div>\n <div\n style={{\n background: 'var(--theme-elevation-50)',\n borderRadius: '5px',\n boxShadow: '0px 0px 10px rgba(0, 0, 0, 0.1)',\n maxWidth: '600px',\n padding: '20px',\n pointerEvents: 'none',\n width: '100%',\n }}\n >\n <div>\n <a\n href={href}\n style={{\n textDecoration: 'none',\n }}\n >\n {href || 'https://...'}\n </a>\n </div>\n <h4\n style={{\n margin: 0,\n }}\n >\n <a\n href=\"/\"\n style={{\n textDecoration: 'none',\n }}\n >\n {metaTitle as string}\n </a>\n </h4>\n <p\n style={{\n margin: 0,\n }}\n >\n {metaDescription as string}\n </p>\n </div>\n </div>\n )\n}\n"],"names":["useAllFormFields","useDocumentInfo","useForm","useLocale","useTranslation","React","useEffect","useState","PreviewComponent","descriptionPath","descriptionPathFromContext","hasGenerateURLFn","titlePath","titlePathFromContext","t","locale","fields","getData","docInfo","value","metaDescription","metaTitle","href","setHref","getHref","genURLResponse","fetch","body","JSON","stringify","doc","code","credentials","headers","method","result","newHref","json","div","style","color","marginBottom","background","borderRadius","boxShadow","maxWidth","padding","pointerEvents","width","a","textDecoration","h4","margin","p"],"mappings":"AAAA;;AAIA,SACEA,gBAAgB,EAChBC,eAAe,EACfC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AAEvB,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAWlD,OAAO,MAAMC,mBAA2C,CAAC,EACvDC,iBAAiBC,0BAA0B,EAC3CC,gBAAgB,EAChBC,WAAWC,oBAAoB,EAChC;IACC,MAAM,EAAEC,CAAC,EAAE,GAAGV;IAEd,MAAMW,SAASZ;IACf,MAAM,CAACa,OAAO,GAAGhB;IACjB,MAAM,EAAEiB,OAAO,EAAE,GAAGf;IACpB,MAAMgB,UAAUjB;IAEhB,MAAMQ,kBAAkBC,8BAA8B;IACtD,MAAME,YAAYC,wBAAwB;IAE1C,MAAM,EACJ,CAACJ,gBAAgB,EAAE,EAAEU,OAAOC,eAAe,EAAE,GAAG,CAAC,CAAc,EAC/D,CAACR,UAAU,EAAE,EAAEO,OAAOE,SAAS,EAAE,GAAG,CAAC,CAAc,EACpD,GAAGL;IAEJ,MAAM,CAACM,MAAMC,QAAQ,GAAGhB;IAExBD,UAAU;QACR,MAAMkB,UAAU;YACd,MAAMC,iBAAiB,MAAMC,MAAM,gCAAgC;gBACjEC,MAAMC,KAAKC,SAAS,CAAC;oBACnB,GAAGX,OAAO;oBACVY,KAAK;wBAAE,GAAGb,SAAS;oBAAC;oBACpBF,QAAQ,OAAOA,WAAW,WAAWA,QAAQgB,OAAOhB;gBACtD;gBACAiB,aAAa;gBACbC,SAAS;oBACP,gBAAgB;gBAClB;gBACAC,QAAQ;YACV;YAEA,MAAM,EAAEC,QAAQC,OAAO,EAAE,GAAG,MAAMX,eAAeY,IAAI;YAErDd,QAAQa;QACV;QAEA,IAAIzB,oBAAoB,CAACW,MAAM;YAC7B,KAAKE;QACP;IACF,GAAG;QAACR;QAAQM;QAAMP;QAAQG;QAASP;QAAkBM;KAAQ;IAE7D,qBACE,MAACqB;;0BACC,KAACA;0BAAKxB,EAAE;;0BACR,KAACwB;gBACCC,OAAO;oBACLC,OAAO;oBACPC,cAAc;gBAChB;0BAEC3B,EAAE;;0BAEL,MAACwB;gBACCC,OAAO;oBACLG,YAAY;oBACZC,cAAc;oBACdC,WAAW;oBACXC,UAAU;oBACVC,SAAS;oBACTC,eAAe;oBACfC,OAAO;gBACT;;kCAEA,KAACV;kCACC,cAAA,KAACW;4BACC3B,MAAMA;4BACNiB,OAAO;gCACLW,gBAAgB;4BAClB;sCAEC5B,QAAQ;;;kCAGb,KAAC6B;wBACCZ,OAAO;4BACLa,QAAQ;wBACV;kCAEA,cAAA,KAACH;4BACC3B,MAAK;4BACLiB,OAAO;gCACLW,gBAAgB;4BAClB;sCAEC7B;;;kCAGL,KAACgC;wBACCd,OAAO;4BACLa,QAAQ;wBACV;kCAEChC;;;;;;AAKX,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/Preview/PreviewComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FormField, UIField } from 'payload'\n\nimport {\n useAllFormFields,\n useDocumentInfo,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useEffect, useState } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateURL } from '../../types.js'\n\ntype PreviewProps = {\n readonly descriptionPath?: string\n readonly hasGenerateURLFn: boolean\n readonly titlePath?: string\n} & UIField\n\nexport const PreviewComponent: React.FC<PreviewProps> = (props) => {\n const {\n descriptionPath: descriptionPathFromContext,\n hasGenerateURLFn,\n titlePath: titlePathFromContext,\n } = props\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const [fields] = useAllFormFields()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const descriptionPath = descriptionPathFromContext || 'meta.description'\n const titlePath = titlePathFromContext || 'meta.title'\n\n const {\n [descriptionPath]: { value: metaDescription } = {} as FormField,\n [titlePath]: { value: metaTitle } = {} as FormField,\n } = fields\n\n const [href, setHref] = useState<string>()\n\n useEffect(() => {\n const getHref = async () => {\n const genURLResponse = await fetch('/api/plugin-seo/generate-url', {\n body: JSON.stringify({\n id: docInfo.id,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\n hasPublishPermission: docInfo.hasPublishPermission,\n hasSavePermission: docInfo.hasSavePermission,\n initialData: docInfo.initialData,\n initialState: docInfo.initialState,\n locale: typeof locale === 'object' ? locale?.code : locale,\n title: docInfo.title,\n } satisfies Omit<Parameters<GenerateURL>[0], 'req'>),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: newHref } = await genURLResponse.json()\n\n setHref(newHref)\n }\n\n if (hasGenerateURLFn && !href) {\n void getHref()\n }\n }, [fields, href, locale, docInfo, hasGenerateURLFn, getData])\n\n return (\n <div>\n <div>{t('plugin-seo:preview')}</div>\n <div\n style={{\n color: '#9A9A9A',\n marginBottom: '5px',\n }}\n >\n {t('plugin-seo:previewDescription')}\n </div>\n <div\n style={{\n background: 'var(--theme-elevation-50)',\n borderRadius: '5px',\n boxShadow: '0px 0px 10px rgba(0, 0, 0, 0.1)',\n maxWidth: '600px',\n padding: '20px',\n pointerEvents: 'none',\n width: '100%',\n }}\n >\n <div>\n <a\n href={href}\n style={{\n textDecoration: 'none',\n }}\n >\n {href || 'https://...'}\n </a>\n </div>\n <h4\n style={{\n margin: 0,\n }}\n >\n <a\n href=\"/\"\n style={{\n textDecoration: 'none',\n }}\n >\n {metaTitle as string}\n </a>\n </h4>\n <p\n style={{\n margin: 0,\n }}\n >\n {metaDescription as string}\n </p>\n </div>\n </div>\n )\n}\n"],"names":["useAllFormFields","useDocumentInfo","useForm","useLocale","useTranslation","React","useEffect","useState","PreviewComponent","props","descriptionPath","descriptionPathFromContext","hasGenerateURLFn","titlePath","titlePathFromContext","t","locale","fields","getData","docInfo","value","metaDescription","metaTitle","href","setHref","getHref","genURLResponse","fetch","body","JSON","stringify","id","doc","docPermissions","hasPublishPermission","hasSavePermission","initialData","initialState","code","title","credentials","headers","method","result","newHref","json","div","style","color","marginBottom","background","borderRadius","boxShadow","maxWidth","padding","pointerEvents","width","a","textDecoration","h4","margin","p"],"mappings":"AAAA;;AAIA,SACEA,gBAAgB,EAChBC,eAAe,EACfC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAWlD,OAAO,MAAMC,mBAA2C,CAACC;IACvD,MAAM,EACJC,iBAAiBC,0BAA0B,EAC3CC,gBAAgB,EAChBC,WAAWC,oBAAoB,EAChC,GAAGL;IAEJ,MAAM,EAAEM,CAAC,EAAE,GAAGX;IAEd,MAAMY,SAASb;IACf,MAAM,CAACc,OAAO,GAAGjB;IACjB,MAAM,EAAEkB,OAAO,EAAE,GAAGhB;IACpB,MAAMiB,UAAUlB;IAEhB,MAAMS,kBAAkBC,8BAA8B;IACtD,MAAME,YAAYC,wBAAwB;IAE1C,MAAM,EACJ,CAACJ,gBAAgB,EAAE,EAAEU,OAAOC,eAAe,EAAE,GAAG,CAAC,CAAc,EAC/D,CAACR,UAAU,EAAE,EAAEO,OAAOE,SAAS,EAAE,GAAG,CAAC,CAAc,EACpD,GAAGL;IAEJ,MAAM,CAACM,MAAMC,QAAQ,GAAGjB;IAExBD,UAAU;QACR,MAAMmB,UAAU;YACd,MAAMC,iBAAiB,MAAMC,MAAM,gCAAgC;gBACjEC,MAAMC,KAAKC,SAAS,CAAC;oBACnBC,IAAIZ,QAAQY,EAAE;oBACdC,KAAKd;oBACLe,gBAAgBd,QAAQc,cAAc;oBACtCC,sBAAsBf,QAAQe,oBAAoB;oBAClDC,mBAAmBhB,QAAQgB,iBAAiB;oBAC5CC,aAAajB,QAAQiB,WAAW;oBAChCC,cAAclB,QAAQkB,YAAY;oBAClCrB,QAAQ,OAAOA,WAAW,WAAWA,QAAQsB,OAAOtB;oBACpDuB,OAAOpB,QAAQoB,KAAK;gBACtB;gBACAC,aAAa;gBACbC,SAAS;oBACP,gBAAgB;gBAClB;gBACAC,QAAQ;YACV;YAEA,MAAM,EAAEC,QAAQC,OAAO,EAAE,GAAG,MAAMlB,eAAemB,IAAI;YAErDrB,QAAQoB;QACV;QAEA,IAAIhC,oBAAoB,CAACW,MAAM;YAC7B,KAAKE;QACP;IACF,GAAG;QAACR;QAAQM;QAAMP;QAAQG;QAASP;QAAkBM;KAAQ;IAE7D,qBACE,MAAC4B;;0BACC,KAACA;0BAAK/B,EAAE;;0BACR,KAAC+B;gBACCC,OAAO;oBACLC,OAAO;oBACPC,cAAc;gBAChB;0BAEClC,EAAE;;0BAEL,MAAC+B;gBACCC,OAAO;oBACLG,YAAY;oBACZC,cAAc;oBACdC,WAAW;oBACXC,UAAU;oBACVC,SAAS;oBACTC,eAAe;oBACfC,OAAO;gBACT;;kCAEA,KAACV;kCACC,cAAA,KAACW;4BACClC,MAAMA;4BACNwB,OAAO;gCACLW,gBAAgB;4BAClB;sCAECnC,QAAQ;;;kCAGb,KAACoC;wBACCZ,OAAO;4BACLa,QAAQ;wBACV;kCAEA,cAAA,KAACH;4BACClC,MAAK;4BACLwB,OAAO;gCACLW,gBAAgB;4BAClB;sCAECpC;;;kCAGL,KAACuC;wBACCd,OAAO;4BACLa,QAAQ;wBACV;kCAECvC;;;;;;AAKX,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Preview/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAA;AAElF,eAAO,MAAM,YAAY,EAAE,aAyB1B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Preview/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAA;AAElF,eAAO,MAAM,YAAY,EAAE,aAwB1B,CAAA"}
@@ -1,20 +1,17 @@
1
- import { withMergedProps } from '@payloadcms/ui/shared';
2
- import { PreviewComponent } from './PreviewComponent.js';
3
1
  export const PreviewField = ({ descriptionPath, hasGenerateFn = false, overrides, titlePath })=>{
4
2
  return {
5
3
  name: 'preview',
6
4
  type: 'ui',
7
5
  admin: {
8
6
  components: {
9
- Field: withMergedProps({
10
- Component: PreviewComponent,
11
- sanitizeServerOnlyProps: true,
12
- toMergeIntoProps: {
7
+ Field: {
8
+ clientProps: {
13
9
  descriptionPath,
14
10
  hasGenerateURLFn: hasGenerateFn,
15
11
  titlePath
16
- }
17
- })
12
+ },
13
+ path: '@payloadcms/plugin-seo/client#PreviewComponent'
14
+ }
18
15
  }
19
16
  },
20
17
  label: 'Preview',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Preview/index.tsx"],"sourcesContent":["import type { UIField } from 'payload'\n\nimport { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { PreviewComponent } from './PreviewComponent.js'\n\ninterface FieldFunctionProps {\n /**\n * Path to the description field to use for the preview\n *\n * @default 'meta.description'\n */\n descriptionPath?: string\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<UIField>\n /**\n * Path to the title field to use for the preview\n *\n * @default 'meta.title'\n */\n titlePath?: string\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UIField\n\nexport const PreviewField: FieldFunction = ({\n descriptionPath,\n hasGenerateFn = false,\n overrides,\n titlePath,\n}) => {\n return {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: withMergedProps({\n Component: PreviewComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n descriptionPath,\n hasGenerateURLFn: hasGenerateFn,\n titlePath,\n },\n }),\n },\n },\n label: 'Preview',\n ...((overrides as unknown as UIField) ?? {}),\n }\n}\n"],"names":["withMergedProps","PreviewComponent","PreviewField","descriptionPath","hasGenerateFn","overrides","titlePath","name","type","admin","components","Field","Component","sanitizeServerOnlyProps","toMergeIntoProps","hasGenerateURLFn","label"],"mappings":"AAEA,SAASA,eAAe,QAAQ,wBAAuB;AAEvD,SAASC,gBAAgB,QAAQ,wBAAuB;AAwBxD,OAAO,MAAMC,eAA8B,CAAC,EAC1CC,eAAe,EACfC,gBAAgB,KAAK,EACrBC,SAAS,EACTC,SAAS,EACV;IACC,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAOX,gBAAgB;oBACrBY,WAAWX;oBACXY,yBAAyB;oBACzBC,kBAAkB;wBAChBX;wBACAY,kBAAkBX;wBAClBE;oBACF;gBACF;YACF;QACF;QACAU,OAAO;QACP,GAAI,AAACX,aAAoC,CAAC,CAAC;IAC7C;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/Preview/index.tsx"],"sourcesContent":["import type { UIField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Path to the description field to use for the preview\n *\n * @default 'meta.description'\n */\n descriptionPath?: string\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<UIField>\n /**\n * Path to the title field to use for the preview\n *\n * @default 'meta.title'\n */\n titlePath?: string\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UIField\n\nexport const PreviewField: FieldFunction = ({\n descriptionPath,\n hasGenerateFn = false,\n overrides,\n titlePath,\n}) => {\n return {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: {\n clientProps: {\n descriptionPath,\n hasGenerateURLFn: hasGenerateFn,\n titlePath,\n },\n path: '@payloadcms/plugin-seo/client#PreviewComponent',\n },\n },\n },\n label: 'Preview',\n ...((overrides as unknown as UIField) ?? {}),\n }\n}\n"],"names":["PreviewField","descriptionPath","hasGenerateFn","overrides","titlePath","name","type","admin","components","Field","clientProps","hasGenerateURLFn","path","label"],"mappings":"AAwBA,OAAO,MAAMA,eAA8B,CAAC,EAC1CC,eAAe,EACfC,gBAAgB,KAAK,EACrBC,SAAS,EACTC,SAAS,EACV;IACC,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXT;wBACAU,kBAAkBT;wBAClBE;oBACF;oBACAQ,MAAM;gBACR;YACF;QACF;QACAC,OAAO;QACP,GAAI,AAACV,aAAoC,CAAC,CAAC;IAC7C;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2C,MAAM,SAAS,CAAA;AAM9E,OAAO,KAAK,EAKV,eAAe,EAChB,MAAM,YAAY,CAAA;AASnB,eAAO,MAAM,SAAS,iBACL,eAAe,cACrB,MAAM,KAAG,MAyRjB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAoC,MAAM,SAAS,CAAA;AAKvE,OAAO,KAAK,EAKV,eAAe,EAChB,MAAM,YAAY,CAAA;AASnB,eAAO,MAAM,SAAS,iBACL,eAAe,cACrB,MAAM,KAAG,MA+NjB,CAAA"}
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { addDataAndFileToRequest } from '@payloadcms/next/utilities';
2
- import { withMergedProps } from '@payloadcms/ui/shared';
3
2
  import { deepMergeSimple } from 'payload/shared';
4
- import { MetaDescriptionComponent } from './fields/MetaDescription/MetaDescriptionComponent.js';
5
- import { MetaImageComponent } from './fields/MetaImage/MetaImageComponent.js';
6
- import { MetaTitleComponent } from './fields/MetaTitle/MetaTitleComponent.js';
7
- import { OverviewComponent } from './fields/Overview/OverviewComponent.js';
8
- import { PreviewComponent } from './fields/Preview/PreviewComponent.js';
3
+ import { MetaDescriptionField } from './fields/MetaDescription/index.js';
4
+ import { MetaImageField } from './fields/MetaImage/index.js';
5
+ import { MetaTitleField } from './fields/MetaTitle/index.js';
6
+ import { OverviewField } from './fields/Overview/index.js';
7
+ import { PreviewField } from './fields/Preview/index.js';
9
8
  import { translations } from './translations/index.js';
10
9
  export const seoPlugin = (pluginConfig)=>(config)=>{
11
10
  const seoFields = [
@@ -13,89 +12,26 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
13
12
  name: 'meta',
14
13
  type: 'group',
15
14
  fields: [
16
- {
17
- name: 'overview',
18
- type: 'ui',
19
- admin: {
20
- components: {
21
- Field: OverviewComponent
22
- }
23
- },
24
- label: 'Overview'
25
- },
26
- {
27
- name: 'title',
28
- type: 'text',
29
- admin: {
30
- components: {
31
- Field: withMergedProps({
32
- Component: MetaTitleComponent,
33
- sanitizeServerOnlyProps: true,
34
- toMergeIntoProps: {
35
- hasGenerateTitleFn: typeof pluginConfig?.generateTitle === 'function'
36
- }
37
- })
38
- }
39
- },
40
- localized: true,
41
- ...pluginConfig?.fieldOverrides?.title ?? {}
42
- },
43
- {
44
- name: 'description',
45
- type: 'textarea',
46
- admin: {
47
- components: {
48
- Field: withMergedProps({
49
- Component: MetaDescriptionComponent,
50
- sanitizeServerOnlyProps: true,
51
- toMergeIntoProps: {
52
- hasGenerateDescriptionFn: typeof pluginConfig?.generateDescription === 'function'
53
- }
54
- })
55
- }
56
- },
57
- localized: true,
58
- ...pluginConfig?.fieldOverrides?.description ?? {}
59
- },
15
+ OverviewField({}),
16
+ MetaTitleField({
17
+ hasGenerateFn: typeof pluginConfig?.generateTitle === 'function',
18
+ overrides: pluginConfig?.fieldOverrides?.title
19
+ }),
20
+ MetaDescriptionField({
21
+ hasGenerateFn: typeof pluginConfig?.generateDescription === 'function',
22
+ overrides: pluginConfig?.fieldOverrides?.description
23
+ }),
60
24
  ...pluginConfig?.uploadsCollection ? [
61
- {
62
- name: 'image',
63
- type: 'upload',
64
- admin: {
65
- components: {
66
- Field: withMergedProps({
67
- Component: MetaImageComponent,
68
- sanitizeServerOnlyProps: true,
69
- toMergeIntoProps: {
70
- hasGenerateImageFn: typeof pluginConfig?.generateImage === 'function'
71
- }
72
- })
73
- },
74
- description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.'
75
- },
76
- label: 'Meta Image',
77
- localized: true,
78
- relationTo: pluginConfig?.uploadsCollection,
79
- ...pluginConfig?.fieldOverrides?.image ?? {}
80
- }
25
+ MetaImageField({
26
+ hasGenerateFn: typeof pluginConfig?.generateImage === 'function',
27
+ overrides: pluginConfig?.fieldOverrides?.image,
28
+ relationTo: pluginConfig.uploadsCollection
29
+ })
81
30
  ] : [],
82
31
  ...pluginConfig?.fields || [],
83
- {
84
- name: 'preview',
85
- type: 'ui',
86
- admin: {
87
- components: {
88
- Field: withMergedProps({
89
- Component: PreviewComponent,
90
- sanitizeServerOnlyProps: true,
91
- toMergeIntoProps: {
92
- hasGenerateURLFn: typeof pluginConfig?.generateURL === 'function'
93
- }
94
- })
95
- }
96
- },
97
- label: 'Preview'
98
- }
32
+ PreviewField({
33
+ hasGenerateFn: typeof pluginConfig?.generateURL === 'function'
34
+ })
99
35
  ],
100
36
  interfaceName: pluginConfig.interfaceName,
101
37
  label: 'SEO'
@@ -168,8 +104,10 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
168
104
  {
169
105
  handler: async (req)=>{
170
106
  await addDataAndFileToRequest(req);
171
- req.t;
172
- const result = pluginConfig.generateTitle ? await pluginConfig.generateTitle(req.data) : '';
107
+ const result = pluginConfig.generateTitle ? await pluginConfig.generateTitle({
108
+ ...req.data,
109
+ req
110
+ }) : '';
173
111
  return new Response(JSON.stringify({
174
112
  result
175
113
  }), {
@@ -182,7 +120,10 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
182
120
  {
183
121
  handler: async (req)=>{
184
122
  await addDataAndFileToRequest(req);
185
- const result = pluginConfig.generateDescription ? await pluginConfig.generateDescription(req.data) : '';
123
+ const result = pluginConfig.generateDescription ? await pluginConfig.generateDescription({
124
+ ...req.data,
125
+ req
126
+ }) : '';
186
127
  return new Response(JSON.stringify({
187
128
  result
188
129
  }), {
@@ -195,7 +136,10 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
195
136
  {
196
137
  handler: async (req)=>{
197
138
  await addDataAndFileToRequest(req);
198
- const result = pluginConfig.generateURL ? await pluginConfig.generateURL(req.data) : '';
139
+ const result = pluginConfig.generateURL ? await pluginConfig.generateURL({
140
+ ...req.data,
141
+ req
142
+ }) : '';
199
143
  return new Response(JSON.stringify({
200
144
  result
201
145
  }), {
@@ -208,7 +152,10 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
208
152
  {
209
153
  handler: async (req)=>{
210
154
  await addDataAndFileToRequest(req);
211
- const result = pluginConfig.generateImage ? await pluginConfig.generateImage(req.data) : '';
155
+ const result = pluginConfig.generateImage ? await pluginConfig.generateImage({
156
+ ...req.data,
157
+ req
158
+ }) : '';
212
159
  return new Response(result, {
213
160
  status: 200
214
161
  });
@@ -263,9 +210,7 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
263
210
  }) || [],
264
211
  i18n: {
265
212
  ...config.i18n,
266
- translations: {
267
- ...deepMergeSimple(translations, config.i18n?.translations)
268
- }
213
+ translations: deepMergeSimple(translations, config.i18n?.translations)
269
214
  }
270
215
  };
271
216
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx"],"sourcesContent":["import type { Config, Field, GroupField, TabsField, TextField } from 'payload'\n\nimport { addDataAndFileToRequest } from '@payloadcms/next/utilities'\nimport { withMergedProps } from '@payloadcms/ui/shared'\nimport { deepMergeSimple } from 'payload/shared'\n\nimport type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n SEOPluginConfig,\n} from './types.js'\n\nimport { MetaDescriptionComponent } from './fields/MetaDescription/MetaDescriptionComponent.js'\nimport { MetaImageComponent } from './fields/MetaImage/MetaImageComponent.js'\nimport { MetaTitleComponent } from './fields/MetaTitle/MetaTitleComponent.js'\nimport { OverviewComponent } from './fields/Overview/OverviewComponent.js'\nimport { PreviewComponent } from './fields/Preview/PreviewComponent.js'\nimport { translations } from './translations/index.js'\n\nexport const seoPlugin =\n (pluginConfig: SEOPluginConfig) =>\n (config: Config): Config => {\n const seoFields: GroupField[] = [\n {\n name: 'meta',\n type: 'group',\n fields: [\n {\n name: 'overview',\n type: 'ui',\n admin: {\n components: {\n Field: OverviewComponent,\n },\n },\n label: 'Overview',\n },\n {\n name: 'title',\n type: 'text',\n admin: {\n components: {\n Field: withMergedProps({\n Component: MetaTitleComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n hasGenerateTitleFn: typeof pluginConfig?.generateTitle === 'function',\n },\n }),\n },\n },\n localized: true,\n ...((pluginConfig?.fieldOverrides?.title as unknown as TextField) ?? {}),\n },\n {\n name: 'description',\n type: 'textarea',\n admin: {\n components: {\n Field: withMergedProps({\n Component: MetaDescriptionComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n hasGenerateDescriptionFn:\n typeof pluginConfig?.generateDescription === 'function',\n },\n }),\n },\n },\n localized: true,\n ...(pluginConfig?.fieldOverrides?.description ?? {}),\n },\n ...(pluginConfig?.uploadsCollection\n ? [\n {\n name: 'image',\n type: 'upload',\n admin: {\n components: {\n Field: withMergedProps({\n Component: MetaImageComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n hasGenerateImageFn: typeof pluginConfig?.generateImage === 'function',\n },\n }),\n },\n description:\n 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.',\n },\n label: 'Meta Image',\n localized: true,\n relationTo: pluginConfig?.uploadsCollection,\n ...(pluginConfig?.fieldOverrides?.image ?? {}),\n } as Field,\n ]\n : []),\n ...(pluginConfig?.fields || []),\n {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: withMergedProps({\n Component: PreviewComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: {\n hasGenerateURLFn: typeof pluginConfig?.generateURL === 'function',\n },\n }),\n },\n },\n label: 'Preview',\n },\n ],\n interfaceName: pluginConfig.interfaceName,\n label: 'SEO',\n },\n ]\n\n return {\n ...config,\n collections:\n config.collections?.map((collection) => {\n const { slug } = collection\n const isEnabled = pluginConfig?.collections?.includes(slug)\n\n if (isEnabled) {\n if (pluginConfig?.tabbedUI) {\n // prevent issues with auth enabled collections having an email field that shouldn't be moved to the SEO tab\n const emailField =\n (collection.auth ||\n !(typeof collection.auth === 'object' && collection.auth.disableLocalStrategy)) &&\n collection.fields?.find((field) => 'name' in field && field.name === 'email')\n const hasOnlyEmailField = collection.fields?.length === 1 && emailField\n\n const seoTabs: TabsField[] = hasOnlyEmailField\n ? [\n {\n type: 'tabs',\n tabs: [\n {\n fields: seoFields,\n label: 'SEO',\n },\n ],\n },\n ]\n : [\n {\n type: 'tabs',\n tabs: [\n // append a new tab onto the end of the tabs array, if there is one at the first index\n // if needed, create a new `Content` tab in the first index for this collection's base fields\n ...(collection?.fields?.[0]?.type === 'tabs' &&\n collection?.fields?.[0]?.tabs\n ? collection.fields[0].tabs\n : [\n {\n fields: [\n ...(emailField\n ? collection.fields.filter(\n (field) => 'name' in field && field.name !== 'email',\n )\n : collection.fields),\n ],\n label: collection?.labels?.singular || 'Content',\n },\n ]),\n {\n fields: seoFields,\n label: 'SEO',\n },\n ],\n },\n ]\n\n return {\n ...collection,\n fields: [\n ...(emailField ? [emailField] : []),\n ...seoTabs,\n ...(collection?.fields?.[0]?.type === 'tabs' ? collection.fields.slice(1) : []),\n ],\n }\n }\n\n return {\n ...collection,\n fields: [...(collection?.fields || []), ...seoFields],\n }\n }\n\n return collection\n }) || [],\n endpoints: [\n ...(config.endpoints ?? []),\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n req.t\n const result = pluginConfig.generateTitle\n ? await pluginConfig.generateTitle(\n req.data as unknown as Parameters<GenerateTitle>[0],\n )\n : ''\n return new Response(JSON.stringify({ result }), { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-title',\n },\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n const result = pluginConfig.generateDescription\n ? await pluginConfig.generateDescription(\n req.data as unknown as Parameters<GenerateDescription>[0],\n )\n : ''\n return new Response(JSON.stringify({ result }), { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-description',\n },\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n const result = pluginConfig.generateURL\n ? await pluginConfig.generateURL(req.data as unknown as Parameters<GenerateURL>[0])\n : ''\n return new Response(JSON.stringify({ result }), { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-url',\n },\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n const result = pluginConfig.generateImage\n ? await pluginConfig.generateImage(\n req.data as unknown as Parameters<GenerateImage>[0],\n )\n : ''\n return new Response(result, { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-image',\n },\n ],\n globals:\n config.globals?.map((global) => {\n const { slug } = global\n const isEnabled = pluginConfig?.globals?.includes(slug)\n\n if (isEnabled) {\n if (pluginConfig?.tabbedUI) {\n const seoTabs: TabsField[] = [\n {\n type: 'tabs',\n tabs: [\n // append a new tab onto the end of the tabs array, if there is one at the first index\n // if needed, create a new `Content` tab in the first index for this global's base fields\n ...(global?.fields?.[0].type === 'tabs' && global?.fields?.[0].tabs\n ? global.fields[0].tabs\n : [\n {\n fields: [...(global?.fields || [])],\n label: global?.label || 'Content',\n },\n ]),\n {\n fields: seoFields,\n label: 'SEO',\n },\n ],\n },\n ]\n\n return {\n ...global,\n fields: [\n ...seoTabs,\n ...(global?.fields?.[0].type === 'tabs' ? global.fields.slice(1) : []),\n ],\n }\n }\n\n return {\n ...global,\n fields: [...(global?.fields || []), ...seoFields],\n }\n }\n\n return global\n }) || [],\n i18n: {\n ...config.i18n,\n translations: {\n ...deepMergeSimple(translations, config.i18n?.translations),\n },\n },\n }\n }\n"],"names":["addDataAndFileToRequest","withMergedProps","deepMergeSimple","MetaDescriptionComponent","MetaImageComponent","MetaTitleComponent","OverviewComponent","PreviewComponent","translations","seoPlugin","pluginConfig","config","seoFields","name","type","fields","admin","components","Field","label","Component","sanitizeServerOnlyProps","toMergeIntoProps","hasGenerateTitleFn","generateTitle","localized","fieldOverrides","title","hasGenerateDescriptionFn","generateDescription","description","uploadsCollection","hasGenerateImageFn","generateImage","relationTo","image","hasGenerateURLFn","generateURL","interfaceName","collections","map","collection","slug","isEnabled","includes","tabbedUI","emailField","auth","disableLocalStrategy","find","field","hasOnlyEmailField","length","seoTabs","tabs","filter","labels","singular","slice","endpoints","handler","req","t","result","data","Response","JSON","stringify","status","method","path","globals","global","i18n"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,6BAA4B;AACpE,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,eAAe,QAAQ,iBAAgB;AAUhD,SAASC,wBAAwB,QAAQ,uDAAsD;AAC/F,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,iBAAiB,QAAQ,yCAAwC;AAC1E,SAASC,gBAAgB,QAAQ,uCAAsC;AACvE,SAASC,YAAY,QAAQ,0BAAyB;AAEtD,OAAO,MAAMC,YACX,CAACC,eACD,CAACC;QACC,MAAMC,YAA0B;YAC9B;gBACEC,MAAM;gBACNC,MAAM;gBACNC,QAAQ;oBACN;wBACEF,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLC,YAAY;gCACVC,OAAOZ;4BACT;wBACF;wBACAa,OAAO;oBACT;oBACA;wBACEN,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLC,YAAY;gCACVC,OAAOjB,gBAAgB;oCACrBmB,WAAWf;oCACXgB,yBAAyB;oCACzBC,kBAAkB;wCAChBC,oBAAoB,OAAOb,cAAcc,kBAAkB;oCAC7D;gCACF;4BACF;wBACF;wBACAC,WAAW;wBACX,GAAI,AAACf,cAAcgB,gBAAgBC,SAAkC,CAAC,CAAC;oBACzE;oBACA;wBACEd,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLC,YAAY;gCACVC,OAAOjB,gBAAgB;oCACrBmB,WAAWjB;oCACXkB,yBAAyB;oCACzBC,kBAAkB;wCAChBM,0BACE,OAAOlB,cAAcmB,wBAAwB;oCACjD;gCACF;4BACF;wBACF;wBACAJ,WAAW;wBACX,GAAIf,cAAcgB,gBAAgBI,eAAe,CAAC,CAAC;oBACrD;uBACIpB,cAAcqB,oBACd;wBACE;4BACElB,MAAM;4BACNC,MA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DAAKyD,QAAQzD,UAAU,EAAE;6CAAE;4CACnCI,OAAOqD,QAAQrD,SAAS;wCAC1B;qCACD;oCACL;wCACEJ,QAAQH;wCACRO,OAAO;oCACT;iCACD;4BACH;yBACD;wBAED,OAAO;4BACL,GAAGqD,MAAM;4BACTzD,QAAQ;mCACHsC;mCACCmB,QAAQzD,QAAQ,CAAC,EAAE,CAACD,SAAS,SAAS0D,OAAOzD,MAAM,CAAC2C,KAAK,CAAC,KAAK,EAAE;6BACtE;wBACH;oBACF;oBAEA,OAAO;wBACL,GAAGc,MAAM;wBACTzD,QAAQ;+BAAKyD,QAAQzD,UAAU,EAAE;+BAAMH;yBAAU;oBACnD;gBACF;gBAEA,OAAO4D;YACT,MAAM,EAAE;YACVC,MAAM;gBACJ,GAAG9D,OAAO8D,IAAI;gBACdjE,cAAc;oBACZ,GAAGN,gBAAgBM,cAAcG,OAAO8D,IAAI,EAAEjE,aAAa;gBAC7D;YACF;QACF;IACF,EAAC"}
1
+ {"version":3,"sources":["../src/index.tsx"],"sourcesContent":["import type { Config, GroupField, TabsField, TextField } from 'payload'\n\nimport { addDataAndFileToRequest } from '@payloadcms/next/utilities'\nimport { deepMergeSimple } from 'payload/shared'\n\nimport type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n SEOPluginConfig,\n} from './types.js'\n\nimport { MetaDescriptionField } from './fields/MetaDescription/index.js'\nimport { MetaImageField } from './fields/MetaImage/index.js'\nimport { MetaTitleField } from './fields/MetaTitle/index.js'\nimport { OverviewField } from './fields/Overview/index.js'\nimport { PreviewField } from './fields/Preview/index.js'\nimport { translations } from './translations/index.js'\n\nexport const seoPlugin =\n (pluginConfig: SEOPluginConfig) =>\n (config: Config): Config => {\n const seoFields: GroupField[] = [\n {\n name: 'meta',\n type: 'group',\n fields: [\n OverviewField({}),\n MetaTitleField({\n hasGenerateFn: typeof pluginConfig?.generateTitle === 'function',\n overrides: pluginConfig?.fieldOverrides?.title as unknown as TextField,\n }),\n MetaDescriptionField({\n hasGenerateFn: typeof pluginConfig?.generateDescription === 'function',\n overrides: pluginConfig?.fieldOverrides?.description,\n }),\n ...(pluginConfig?.uploadsCollection\n ? [\n MetaImageField({\n hasGenerateFn: typeof pluginConfig?.generateImage === 'function',\n overrides: pluginConfig?.fieldOverrides?.image,\n relationTo: pluginConfig.uploadsCollection,\n }),\n ]\n : []),\n ...(pluginConfig?.fields || []),\n PreviewField({\n hasGenerateFn: typeof pluginConfig?.generateURL === 'function',\n }),\n ],\n interfaceName: pluginConfig.interfaceName,\n label: 'SEO',\n },\n ]\n\n return {\n ...config,\n collections:\n config.collections?.map((collection) => {\n const { slug } = collection\n const isEnabled = pluginConfig?.collections?.includes(slug)\n\n if (isEnabled) {\n if (pluginConfig?.tabbedUI) {\n // prevent issues with auth enabled collections having an email field that shouldn't be moved to the SEO tab\n const emailField =\n (collection.auth ||\n !(typeof collection.auth === 'object' && collection.auth.disableLocalStrategy)) &&\n collection.fields?.find((field) => 'name' in field && field.name === 'email')\n const hasOnlyEmailField = collection.fields?.length === 1 && emailField\n\n const seoTabs: TabsField[] = hasOnlyEmailField\n ? [\n {\n type: 'tabs',\n tabs: [\n {\n fields: seoFields,\n label: 'SEO',\n },\n ],\n },\n ]\n : [\n {\n type: 'tabs',\n tabs: [\n // append a new tab onto the end of the tabs array, if there is one at the first index\n // if needed, create a new `Content` tab in the first index for this collection's base fields\n ...(collection?.fields?.[0]?.type === 'tabs' &&\n collection?.fields?.[0]?.tabs\n ? collection.fields[0].tabs\n : [\n {\n fields: [\n ...(emailField\n ? collection.fields.filter(\n (field) => 'name' in field && field.name !== 'email',\n )\n : collection.fields),\n ],\n label: collection?.labels?.singular || 'Content',\n },\n ]),\n {\n fields: seoFields,\n label: 'SEO',\n },\n ],\n },\n ]\n\n return {\n ...collection,\n fields: [\n ...(emailField ? [emailField] : []),\n ...seoTabs,\n ...(collection?.fields?.[0]?.type === 'tabs' ? collection.fields.slice(1) : []),\n ],\n }\n }\n\n return {\n ...collection,\n fields: [...(collection?.fields || []), ...seoFields],\n }\n }\n\n return collection\n }) || [],\n endpoints: [\n ...(config.endpoints ?? []),\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const result = pluginConfig.generateTitle\n ? await pluginConfig.generateTitle({\n ...req.data,\n req,\n } as unknown as Parameters<GenerateTitle>[0])\n : ''\n return new Response(JSON.stringify({ result }), { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-title',\n },\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const result = pluginConfig.generateDescription\n ? await pluginConfig.generateDescription({\n ...req.data,\n req,\n } as unknown as Parameters<GenerateDescription>[0])\n : ''\n return new Response(JSON.stringify({ result }), { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-description',\n },\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const result = pluginConfig.generateURL\n ? await pluginConfig.generateURL({\n ...req.data,\n req,\n } as unknown as Parameters<GenerateURL>[0])\n : ''\n return new Response(JSON.stringify({ result }), { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-url',\n },\n {\n handler: async (req) => {\n await addDataAndFileToRequest(req)\n\n const result = pluginConfig.generateImage\n ? await pluginConfig.generateImage({\n ...req.data,\n req,\n } as unknown as Parameters<GenerateImage>[0])\n : ''\n return new Response(result, { status: 200 })\n },\n method: 'post',\n path: '/plugin-seo/generate-image',\n },\n ],\n globals:\n config.globals?.map((global) => {\n const { slug } = global\n const isEnabled = pluginConfig?.globals?.includes(slug)\n\n if (isEnabled) {\n if (pluginConfig?.tabbedUI) {\n const seoTabs: TabsField[] = [\n {\n type: 'tabs',\n tabs: [\n // append a new tab onto the end of the tabs array, if there is one at the first index\n // if needed, create a new `Content` tab in the first index for this global's base fields\n ...(global?.fields?.[0].type === 'tabs' && global?.fields?.[0].tabs\n ? global.fields[0].tabs\n : [\n {\n fields: [...(global?.fields || [])],\n label: global?.label || 'Content',\n },\n ]),\n {\n fields: seoFields,\n label: 'SEO',\n },\n ],\n },\n ]\n\n return {\n ...global,\n fields: [\n ...seoTabs,\n ...(global?.fields?.[0].type === 'tabs' ? global.fields.slice(1) : []),\n ],\n }\n }\n\n return {\n ...global,\n fields: [...(global?.fields || []), ...seoFields],\n }\n }\n\n return global\n }) || [],\n i18n: {\n ...config.i18n,\n translations: deepMergeSimple(translations, config.i18n?.translations),\n },\n }\n }\n"],"names":["addDataAndFileToRequest","deepMergeSimple","MetaDescriptionField","MetaImageField","MetaTitleField","OverviewField","PreviewField","translations","seoPlugin","pluginConfig","config","seoFields","name","type","fields","hasGenerateFn","generateTitle","overrides","fieldOverrides","title","generateDescription","description","uploadsCollection","generateImage","image","relationTo","generateURL","interfaceName","label","collections","map","collection","slug","isEnabled","includes","tabbedUI","emailField","auth","disableLocalStrategy","find","field","hasOnlyEmailField","length","seoTabs","tabs","filter","labels","singular","slice","endpoints","handler","req","result","data","Response","JSON","stringify","status","method","path","globals","global","i18n"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,6BAA4B;AACpE,SAASC,eAAe,QAAQ,iBAAgB;AAUhD,SAASC,oBAAoB,QAAQ,oCAAmC;AACxE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,aAAa,QAAQ,6BAA4B;AAC1D,SAASC,YAAY,QAAQ,4BAA2B;AACxD,SAASC,YAAY,QAAQ,0BAAyB;AAEtD,OAAO,MAAMC,YACX,CAACC,eACD,CAACC;QACC,MAAMC,YAA0B;YAC9B;gBACEC,MAAM;gBACNC,MAAM;gBACNC,QAAQ;oBACNT,cAAc,CAAC;oBACfD,eAAe;wBACbW,eAAe,OAAON,cAAcO,kBAAkB;wBACtDC,WAAWR,cAAcS,gBAAgBC;oBAC3C;oBACAjB,qBAAqB;wBACnBa,eAAe,OAAON,cAAcW,wBAAwB;wBAC5DH,WAAWR,cAAcS,gBAAgBG;oBAC3C;uBACIZ,cAAca,oBACd;wBACEnB,eAAe;4BACbY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,KAAK,CAAC,KAAK,EAAE;6BACtE;wBACH;oBACF;oBAEA,OAAO;wBACL,GAAGa,MAAM;wBACT/C,QAAQ;+BAAK+C,QAAQ/C,UAAU,EAAE;+BAAMH;yBAAU;oBACnD;gBACF;gBAEA,OAAOkD;YACT,MAAM,EAAE;YACVC,MAAM;gBACJ,GAAGpD,OAAOoD,IAAI;gBACdvD,cAAcN,gBAAgBM,cAAcG,OAAOoD,IAAI,EAAEvD;YAC3D;QACF;IACF,EAAC"}
package/dist/types.d.ts CHANGED
@@ -1,21 +1,26 @@
1
1
  import type { DocumentInfoContext } from '@payloadcms/ui';
2
- import type { Field, TextField, TextareaField, UploadField } from 'payload';
2
+ import type { Field, PayloadRequest, TextField, TextareaField, UploadField } from 'payload';
3
+ export type PartialDocumentInfoContext = Pick<DocumentInfoContext, 'docPermissions' | 'hasPublishPermission' | 'hasSavePermission' | 'id' | 'initialData' | 'initialState' | 'preferencesKey' | 'publishedDoc' | 'slug' | 'title' | 'versionsCount'>;
3
4
  export type GenerateTitle<T = any> = (args: {
4
5
  doc: T;
5
6
  locale?: string;
6
- } & DocumentInfoContext) => Promise<string> | string;
7
+ req: PayloadRequest;
8
+ } & PartialDocumentInfoContext) => Promise<string> | string;
7
9
  export type GenerateDescription<T = any> = (args: {
8
10
  doc: T;
9
11
  locale?: string;
10
- } & DocumentInfoContext) => Promise<string> | string;
12
+ req: PayloadRequest;
13
+ } & PartialDocumentInfoContext) => Promise<string> | string;
11
14
  export type GenerateImage<T = any> = (args: {
12
15
  doc: T;
13
16
  locale?: string;
14
- } & DocumentInfoContext) => Promise<string> | string;
17
+ req: PayloadRequest;
18
+ } & PartialDocumentInfoContext) => Promise<string> | string;
15
19
  export type GenerateURL<T = any> = (args: {
16
20
  doc: T;
17
21
  locale?: string;
18
- } & DocumentInfoContext) => Promise<string> | string;
22
+ req: PayloadRequest;
23
+ } & PartialDocumentInfoContext) => Promise<string> | string;
19
24
  export type SEOPluginConfig = {
20
25
  collections?: string[];
21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E,aAAa,CAAA;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,IAAI,GAAG;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { DocumentInfoContext } from '@payloadcms/ui'\nimport type { Field, TextField, TextareaField, UploadField } from 'payload'\n\nexport type GenerateTitle<T = any> = (\n args: { doc: T; locale?: string } & DocumentInfoContext,\n) => Promise<string> | string\n\nexport type GenerateDescription<T = any> = (\n args: {\n doc: T\n locale?: string\n } & DocumentInfoContext,\n) => Promise<string> | string\n\nexport type GenerateImage<T = any> = (\n args: { doc: T; locale?: string } & DocumentInfoContext,\n) => Promise<string> | string\n\nexport type GenerateURL<T = any> = (\n args: { doc: T; locale?: string } & DocumentInfoContext,\n) => Promise<string> | string\n\nexport type SEOPluginConfig = {\n collections?: string[]\n fieldOverrides?: {\n description?: Partial<TextareaField>\n image?: Partial<UploadField>\n title?: Partial<TextField>\n }\n fields?: Field[]\n generateDescription?: GenerateDescription\n generateImage?: GenerateImage\n generateTitle?: GenerateTitle\n generateURL?: GenerateURL\n globals?: string[]\n interfaceName?: string\n tabbedUI?: boolean\n uploadsCollection?: string\n}\n\nexport type Meta = {\n description?: string\n image?: any // TODO: type this\n keywords?: string\n title?: string\n}\n"],"names":[],"mappings":"AAwCA,WAKC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { DocumentInfoContext } from '@payloadcms/ui'\nimport type { Field, PayloadRequest, TextField, TextareaField, UploadField } from 'payload'\n\nexport type PartialDocumentInfoContext = Pick<\n DocumentInfoContext,\n | 'docPermissions'\n | 'hasPublishPermission'\n | 'hasSavePermission'\n | 'id'\n | 'initialData'\n | 'initialState'\n | 'preferencesKey'\n | 'publishedDoc'\n | 'slug'\n | 'title'\n | 'versionsCount'\n>\n\nexport type GenerateTitle<T = any> = (\n args: { doc: T; locale?: string; req: PayloadRequest } & PartialDocumentInfoContext,\n) => Promise<string> | string\n\nexport type GenerateDescription<T = any> = (\n args: {\n doc: T\n locale?: string\n req: PayloadRequest\n } & PartialDocumentInfoContext,\n) => Promise<string> | string\n\nexport type GenerateImage<T = any> = (\n args: { doc: T; locale?: string; req: PayloadRequest } & PartialDocumentInfoContext,\n) => Promise<string> | string\n\nexport type GenerateURL<T = any> = (\n args: { doc: T; locale?: string; req: PayloadRequest } & PartialDocumentInfoContext,\n) => Promise<string> | string\n\nexport type SEOPluginConfig = {\n collections?: string[]\n fieldOverrides?: {\n description?: Partial<TextareaField>\n image?: Partial<UploadField>\n title?: Partial<TextField>\n }\n fields?: Field[]\n generateDescription?: GenerateDescription\n generateImage?: GenerateImage\n generateTitle?: GenerateTitle\n generateURL?: GenerateURL\n globals?: string[]\n interfaceName?: string\n tabbedUI?: boolean\n uploadsCollection?: string\n}\n\nexport type Meta = {\n description?: string\n image?: any // TODO: type this\n keywords?: string\n title?: string\n}\n"],"names":[],"mappings":"AAwDA,WAKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-seo",
3
- "version": "3.0.0-canary.95fcd13",
3
+ "version": "3.0.0-canary.9beaa28",
4
4
  "description": "SEO plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -34,6 +34,11 @@
34
34
  "import": "./dist/exports/fields.js",
35
35
  "types": "./dist/exports/fields.d.ts",
36
36
  "default": "./dist/exports/fields.js"
37
+ },
38
+ "./client": {
39
+ "import": "./dist/exports/client.js",
40
+ "types": "./dist/exports/client.d.ts",
41
+ "default": "./dist/exports/client.js"
37
42
  }
38
43
  },
39
44
  "main": "./dist/index.js",
@@ -45,17 +50,17 @@
45
50
  "@types/react": "npm:types-react@19.0.0-rc.0",
46
51
  "@types/react-dom": "npm:types-react-dom@19.0.0-rc.0",
47
52
  "@payloadcms/eslint-config": "3.0.0-beta.59",
48
- "@payloadcms/translations": "3.0.0-canary.95fcd13",
49
- "@payloadcms/next": "3.0.0-canary.95fcd13",
50
- "@payloadcms/ui": "3.0.0-canary.95fcd13",
51
- "payload": "3.0.0-canary.95fcd13"
53
+ "@payloadcms/next": "3.0.0-canary.9beaa28",
54
+ "@payloadcms/translations": "3.0.0-canary.9beaa28",
55
+ "@payloadcms/ui": "3.0.0-canary.9beaa28",
56
+ "payload": "3.0.0-canary.9beaa28"
52
57
  },
53
58
  "peerDependencies": {
54
- "react": "^19.0.0 || ^19.0.0-rc-6230622a1a-20240610",
55
- "react-dom": "^19.0.0 || ^19.0.0-rc-6230622a1a-20240610",
56
- "@payloadcms/translations": "3.0.0-canary.95fcd13",
57
- "@payloadcms/ui": "3.0.0-canary.95fcd13",
58
- "payload": "3.0.0-canary.95fcd13"
59
+ "react": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801",
60
+ "react-dom": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801",
61
+ "@payloadcms/translations": "3.0.0-canary.9beaa28",
62
+ "@payloadcms/ui": "3.0.0-canary.9beaa28",
63
+ "payload": "3.0.0-canary.9beaa28"
59
64
  },
60
65
  "publishConfig": {
61
66
  "registry": "https://registry.npmjs.org/"