@payloadcms/plugin-seo 3.0.0-canary.8223f17 → 3.0.0-canary.852f9fc

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 (81) hide show
  1. package/dist/defaults.js.map +1 -1
  2. package/dist/exports/client.d.ts +6 -0
  3. package/dist/exports/client.d.ts.map +1 -0
  4. package/dist/exports/client.js +7 -0
  5. package/dist/exports/client.js.map +1 -0
  6. package/dist/exports/fields.d.ts +6 -0
  7. package/dist/exports/fields.d.ts.map +1 -0
  8. package/dist/exports/fields.js +7 -0
  9. package/dist/exports/fields.js.map +1 -0
  10. package/dist/exports/types.js.map +1 -1
  11. package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts +8 -0
  12. package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts.map +1 -0
  13. package/dist/fields/{MetaDescription.js → MetaDescription/MetaDescriptionComponent.js} +35 -27
  14. package/dist/fields/MetaDescription/MetaDescriptionComponent.js.map +1 -0
  15. package/dist/fields/MetaDescription/index.d.ts +12 -0
  16. package/dist/fields/MetaDescription/index.d.ts.map +1 -0
  17. package/dist/fields/MetaDescription/index.js +20 -0
  18. package/dist/fields/MetaDescription/index.js.map +1 -0
  19. package/dist/fields/MetaImage/MetaImageComponent.d.ts +8 -0
  20. package/dist/fields/MetaImage/MetaImageComponent.d.ts.map +1 -0
  21. package/dist/fields/{MetaImage.js → MetaImage/MetaImageComponent.js} +46 -30
  22. package/dist/fields/MetaImage/MetaImageComponent.js.map +1 -0
  23. package/dist/fields/MetaImage/index.d.ts +13 -0
  24. package/dist/fields/MetaImage/index.d.ts.map +1 -0
  25. package/dist/fields/MetaImage/index.js +23 -0
  26. package/dist/fields/MetaImage/index.js.map +1 -0
  27. package/dist/fields/MetaTitle/MetaTitleComponent.d.ts +9 -0
  28. package/dist/fields/MetaTitle/MetaTitleComponent.d.ts.map +1 -0
  29. package/dist/fields/{MetaTitle.js → MetaTitle/MetaTitleComponent.js} +36 -28
  30. package/dist/fields/MetaTitle/MetaTitleComponent.js.map +1 -0
  31. package/dist/fields/MetaTitle/index.d.ts +12 -0
  32. package/dist/fields/MetaTitle/index.d.ts.map +1 -0
  33. package/dist/fields/MetaTitle/index.js +20 -0
  34. package/dist/fields/MetaTitle/index.js.map +1 -0
  35. package/dist/fields/Overview/OverviewComponent.d.ts +10 -0
  36. package/dist/fields/Overview/OverviewComponent.d.ts.map +1 -0
  37. package/dist/{ui/Overview.js → fields/Overview/OverviewComponent.js} +14 -9
  38. package/dist/fields/Overview/OverviewComponent.js.map +1 -0
  39. package/dist/fields/Overview/index.d.ts +26 -0
  40. package/dist/fields/Overview/index.d.ts.map +1 -0
  41. package/dist/fields/Overview/index.js +22 -0
  42. package/dist/fields/Overview/index.js.map +1 -0
  43. package/dist/fields/Preview/PreviewComponent.d.ts +10 -0
  44. package/dist/fields/Preview/PreviewComponent.d.ts.map +1 -0
  45. package/dist/{ui/Preview.js → fields/Preview/PreviewComponent.js} +19 -13
  46. package/dist/fields/Preview/PreviewComponent.js.map +1 -0
  47. package/dist/fields/Preview/index.d.ts +24 -0
  48. package/dist/fields/Preview/index.d.ts.map +1 -0
  49. package/dist/fields/Preview/index.js +22 -0
  50. package/dist/fields/Preview/index.js.map +1 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +56 -112
  53. package/dist/index.js.map +1 -1
  54. package/dist/translations/index.d.ts +44 -0
  55. package/dist/translations/index.d.ts.map +1 -1
  56. package/dist/translations/index.js +44 -0
  57. package/dist/translations/index.js.map +1 -1
  58. package/dist/translations/it.json +22 -0
  59. package/dist/translations/ru.json +22 -0
  60. package/dist/types.d.ts +15 -10
  61. package/dist/types.d.ts.map +1 -1
  62. package/dist/types.js.map +1 -1
  63. package/dist/ui/LengthIndicator.js +1 -1
  64. package/dist/ui/LengthIndicator.js.map +1 -1
  65. package/dist/ui/Pill.js.map +1 -1
  66. package/package.json +33 -23
  67. package/dist/fields/MetaDescription.d.ts +0 -9
  68. package/dist/fields/MetaDescription.d.ts.map +0 -1
  69. package/dist/fields/MetaDescription.js.map +0 -1
  70. package/dist/fields/MetaImage.d.ts +0 -8
  71. package/dist/fields/MetaImage.d.ts.map +0 -1
  72. package/dist/fields/MetaImage.js.map +0 -1
  73. package/dist/fields/MetaTitle.d.ts +0 -9
  74. package/dist/fields/MetaTitle.d.ts.map +0 -1
  75. package/dist/fields/MetaTitle.js.map +0 -1
  76. package/dist/ui/Overview.d.ts +0 -3
  77. package/dist/ui/Overview.d.ts.map +0 -1
  78. package/dist/ui/Overview.js.map +0 -1
  79. package/dist/ui/Preview.d.ts +0 -8
  80. package/dist/ui/Preview.d.ts.map +0 -1
  81. package/dist/ui/Preview.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaults = {\n description: {\n maxLength: 150,\n minLength: 100,\n },\n title: {\n maxLength: 60,\n minLength: 50,\n },\n}\n"],"names":["defaults","description","maxLength","minLength","title"],"rangeMappings":";;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,WAAW;IACtBC,aAAa;QACXC,WAAW;QACXC,WAAW;IACb;IACAC,OAAO;QACLF,WAAW;QACXC,WAAW;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaults = {\n description: {\n maxLength: 150,\n minLength: 100,\n },\n title: {\n maxLength: 60,\n minLength: 50,\n },\n}\n"],"names":["defaults","description","maxLength","minLength","title"],"mappings":"AAAA,OAAO,MAAMA,WAAW;IACtBC,aAAa;QACXC,WAAW;QACXC,WAAW;IACb;IACAC,OAAO;QACLF,WAAW;QACXC,WAAW;IACb;AACF,EAAC"}
@@ -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"}
@@ -0,0 +1,6 @@
1
+ export { MetaDescriptionField } from '../fields/MetaDescription/index.js';
2
+ export { MetaImageField } from '../fields/MetaImage/index.js';
3
+ export { MetaTitleField } from '../fields/MetaTitle/index.js';
4
+ export { OverviewField } from '../fields/Overview/index.js';
5
+ export { PreviewField } from '../fields/Preview/index.js';
6
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/exports/fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,7 @@
1
+ export { MetaDescriptionField } from '../fields/MetaDescription/index.js';
2
+ export { MetaImageField } from '../fields/MetaImage/index.js';
3
+ export { MetaTitleField } from '../fields/MetaTitle/index.js';
4
+ export { OverviewField } from '../fields/Overview/index.js';
5
+ export { PreviewField } from '../fields/Preview/index.js';
6
+
7
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exports/fields.ts"],"sourcesContent":["export { MetaDescriptionField } from '../fields/MetaDescription/index.js'\nexport { MetaImageField } from '../fields/MetaImage/index.js'\nexport { MetaTitleField } from '../fields/MetaTitle/index.js'\nexport { OverviewField } from '../fields/Overview/index.js'\nexport { PreviewField } from '../fields/Preview/index.js'\n"],"names":["MetaDescriptionField","MetaImageField","MetaTitleField","OverviewField","PreviewField"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,YAAY,QAAQ,6BAA4B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n Meta,\n SEOPluginConfig,\n} from '../types.js'\n"],"names":[],"rangeMappings":"","mappings":"AAAA,WAOoB"}
1
+ {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n Meta,\n SEOPluginConfig,\n} from '../types.js'\n"],"names":[],"mappings":"AAAA,WAOoB"}
@@ -0,0 +1,8 @@
1
+ import type { TextareaFieldProps } from 'payload';
2
+ import React from 'react';
3
+ type MetaDescriptionProps = {
4
+ readonly hasGenerateDescriptionFn: boolean;
5
+ } & TextareaFieldProps;
6
+ export declare const MetaDescriptionComponent: React.FC<MetaDescriptionProps>;
7
+ export {};
8
+ //# sourceMappingURL=MetaDescriptionComponent.d.ts.map
@@ -0,0 +1 @@
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,CA8InE,CAAA"}
@@ -1,37 +1,37 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { FieldLabel } from '@payloadcms/ui/fields/FieldLabel';
4
- import { TextareaInput } from '@payloadcms/ui/fields/Textarea';
5
- import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
6
- import { useAllFormFields } from '@payloadcms/ui/forms/Form';
7
- import { useField } from '@payloadcms/ui/forms/useField';
8
- import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
9
- import { useLocale } from '@payloadcms/ui/providers/Locale';
10
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
3
+ import { FieldLabel, TextareaInput, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
11
4
  import React, { useCallback } from 'react';
12
- import { defaults } from '../defaults.js';
13
- import { LengthIndicator } from '../ui/LengthIndicator.js';
5
+ import { defaults } from '../../defaults.js';
6
+ import { LengthIndicator } from '../../ui/LengthIndicator.js';
14
7
  const { maxLength, minLength } = defaults.description;
15
- export const MetaDescription = (props)=>{
16
- const { CustomLabel, hasGenerateDescriptionFn, label, labelProps, path, required } = props;
8
+ export const MetaDescriptionComponent = (props)=>{
9
+ const { field: { admin: { components: { Label } }, label, required }, hasGenerateDescriptionFn, labelProps } = props;
17
10
  const { path: pathFromContext } = useFieldProps();
18
11
  const { t } = useTranslation();
19
12
  const locale = useLocale();
20
- const [fields] = useAllFormFields();
13
+ const { getData } = useForm();
21
14
  const docInfo = useDocumentInfo();
22
15
  const field = useField({
23
- path
16
+ path: pathFromContext
24
17
  });
25
18
  const { errorMessage, setValue, showError, value } = field;
26
19
  const regenerateDescription = useCallback(async ()=>{
27
- if (!hasGenerateDescriptionFn) return;
20
+ if (!hasGenerateDescriptionFn) {
21
+ return;
22
+ }
28
23
  const genDescriptionResponse = await fetch('/api/plugin-seo/generate-description', {
29
24
  body: JSON.stringify({
30
- ...docInfo,
31
- doc: {
32
- ...fields
33
- },
34
- locale: typeof locale === 'object' ? locale?.code : locale
25
+ id: docInfo.id,
26
+ slug: docInfo.slug,
27
+ doc: getData(),
28
+ docPermissions: docInfo.docPermissions,
29
+ hasPublishPermission: docInfo.hasPublishPermission,
30
+ hasSavePermission: docInfo.hasSavePermission,
31
+ initialData: docInfo.initialData,
32
+ initialState: docInfo.initialState,
33
+ locale: typeof locale === 'object' ? locale?.code : locale,
34
+ title: docInfo.title
35
35
  }),
36
36
  credentials: 'include',
37
37
  headers: {
@@ -42,11 +42,11 @@ export const MetaDescription = (props)=>{
42
42
  const { result: generatedDescription } = await genDescriptionResponse.json();
43
43
  setValue(generatedDescription || '');
44
44
  }, [
45
- fields,
46
- setValue,
47
45
  hasGenerateDescriptionFn,
46
+ docInfo,
47
+ getData,
48
48
  locale,
49
- docInfo
49
+ setValue
50
50
  ]);
51
51
  return /*#__PURE__*/ _jsxs("div", {
52
52
  style: {
@@ -63,7 +63,8 @@ export const MetaDescription = (props)=>{
63
63
  className: "plugin-seo__field",
64
64
  children: [
65
65
  /*#__PURE__*/ _jsx(FieldLabel, {
66
- CustomLabel: CustomLabel,
66
+ field: null,
67
+ Label: Label,
67
68
  label: label,
68
69
  ...labelProps || {}
69
70
  }),
@@ -71,7 +72,9 @@ export const MetaDescription = (props)=>{
71
72
  children: [
72
73
  "  —  ",
73
74
  /*#__PURE__*/ _jsx("button", {
74
- onClick: regenerateDescription,
75
+ onClick: ()=>{
76
+ void regenerateDescription();
77
+ },
75
78
  style: {
76
79
  background: 'none',
77
80
  backgroundColor: 'transparent',
@@ -113,7 +116,12 @@ export const MetaDescription = (props)=>{
113
116
  position: 'relative'
114
117
  },
115
118
  children: /*#__PURE__*/ _jsx(TextareaInput, {
116
- CustomError: errorMessage,
119
+ Error: {
120
+ type: 'client',
121
+ Component: null,
122
+ RenderedComponent: errorMessage
123
+ },
124
+ label: label,
117
125
  onChange: setValue,
118
126
  path: pathFromContext,
119
127
  required: required,
@@ -140,4 +148,4 @@ export const MetaDescription = (props)=>{
140
148
  });
141
149
  };
142
150
 
143
- //# sourceMappingURL=MetaDescription.js.map
151
+ //# sourceMappingURL=MetaDescriptionComponent.js.map
@@ -0,0 +1 @@
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) {\n return\n }\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 field={null} Label={Label} 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,IAAI,CAACc,0BAA0B;YAC7B;QACF;QAEA,MAAMa,yBAAyB,MAAMC,MAAM,wCAAwC;YACjFC,MAAMC,KAAKC,SAAS,CAAC;gBACnBC,IAAIX,QAAQW,EAAE;gBACdC,MAAMZ,QAAQY,IAAI;gBAClBC,KAAKd;gBACLe,gBAAgBd,QAAQc,cAAc;gBACtCC,sBAAsBf,QAAQe,oBAA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BACP2D,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"}
@@ -0,0 +1,12 @@
1
+ import type { TextareaField } from 'payload';
2
+ interface FieldFunctionProps {
3
+ /**
4
+ * Tell the component if the generate function is available as configured in the plugin config
5
+ */
6
+ hasGenerateFn?: boolean;
7
+ overrides?: Partial<TextareaField>;
8
+ }
9
+ type FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextareaField;
10
+ export declare const MetaDescriptionField: FieldFunction;
11
+ export {};
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;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"}
@@ -0,0 +1,20 @@
1
+ export const MetaDescriptionField = ({ hasGenerateFn = false, overrides })=>{
2
+ return {
3
+ name: 'description',
4
+ type: 'textarea',
5
+ admin: {
6
+ components: {
7
+ Field: {
8
+ clientProps: {
9
+ hasGenerateDescriptionFn: hasGenerateFn
10
+ },
11
+ path: '@payloadcms/plugin-seo/client#MetaDescriptionComponent'
12
+ }
13
+ }
14
+ },
15
+ localized: true,
16
+ ...overrides ?? {}
17
+ };
18
+ };
19
+
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,8 @@
1
+ import type { UploadFieldProps } from 'payload';
2
+ import React from 'react';
3
+ type MetaImageProps = {
4
+ readonly hasGenerateImageFn: boolean;
5
+ } & UploadFieldProps;
6
+ export declare const MetaImageComponent: React.FC<MetaImageProps>;
7
+ export {};
8
+ //# sourceMappingURL=MetaImageComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MetaImageComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAa/C,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,CAoKvD,CAAA"}
@@ -1,32 +1,36 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { FieldLabel } from '@payloadcms/ui/fields/FieldLabel';
4
- import { UploadInput } from '@payloadcms/ui/fields/Upload';
5
- import { useAllFormFields } from '@payloadcms/ui/forms/Form';
6
- import { useField } from '@payloadcms/ui/forms/useField';
7
- import { useConfig } from '@payloadcms/ui/providers/Config';
8
- import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
9
- import { useLocale } from '@payloadcms/ui/providers/Locale';
10
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
3
+ import { FieldLabel, UploadInput, useConfig, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
11
4
  import React, { useCallback } from 'react';
12
- import { Pill } from '../ui/Pill.js';
13
- export const MetaImage = (props)=>{
14
- const { CustomLabel, hasGenerateImageFn, label, labelProps, relationTo, required } = props || {};
15
- const field = useField(props);
5
+ import { Pill } from '../../ui/Pill.js';
6
+ export const MetaImageComponent = (props)=>{
7
+ const { field: { admin: { components: { Label } }, label, relationTo, required }, hasGenerateImageFn, labelProps } = props || {};
8
+ const { path: pathFromContext } = useFieldProps();
9
+ const field = useField({
10
+ ...props,
11
+ path: pathFromContext
12
+ });
16
13
  const { t } = useTranslation();
17
14
  const locale = useLocale();
18
- const [fields] = useAllFormFields();
15
+ const { getData } = useForm();
19
16
  const docInfo = useDocumentInfo();
20
17
  const { errorMessage, setValue, showError, value } = field;
21
18
  const regenerateImage = useCallback(async ()=>{
22
- if (!hasGenerateImageFn) return;
19
+ if (!hasGenerateImageFn) {
20
+ return;
21
+ }
23
22
  const genImageResponse = await fetch('/api/plugin-seo/generate-image', {
24
23
  body: JSON.stringify({
25
- ...docInfo,
26
- doc: {
27
- ...fields
28
- },
29
- 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
30
34
  }),
31
35
  credentials: 'include',
32
36
  headers: {
@@ -34,17 +38,17 @@ export const MetaImage = (props)=>{
34
38
  },
35
39
  method: 'POST'
36
40
  });
37
- const { result: generatedImage } = await genImageResponse.json();
41
+ const generatedImage = await genImageResponse.text();
38
42
  setValue(generatedImage || '');
39
43
  }, [
40
- fields,
41
- setValue,
42
44
  hasGenerateImageFn,
45
+ docInfo,
46
+ getData,
43
47
  locale,
44
- docInfo
48
+ setValue
45
49
  ]);
46
50
  const hasImage = Boolean(value);
47
- const config = useConfig();
51
+ const { config } = useConfig();
48
52
  const { collections, routes: { api } = {}, serverURL } = config;
49
53
  const collection = collections?.find((coll)=>coll.slug === relationTo) || undefined;
50
54
  return /*#__PURE__*/ _jsxs("div", {
@@ -62,7 +66,8 @@ export const MetaImage = (props)=>{
62
66
  className: "plugin-seo__field",
63
67
  children: [
64
68
  /*#__PURE__*/ _jsx(FieldLabel, {
65
- CustomLabel: CustomLabel,
69
+ field: null,
70
+ Label: Label,
66
71
  label: label,
67
72
  ...labelProps || {}
68
73
  }),
@@ -70,7 +75,9 @@ export const MetaImage = (props)=>{
70
75
  children: [
71
76
  "  —  ",
72
77
  /*#__PURE__*/ _jsx("button", {
73
- onClick: regenerateImage,
78
+ onClick: ()=>{
79
+ void regenerateImage();
80
+ },
74
81
  style: {
75
82
  background: 'none',
76
83
  backgroundColor: 'transparent',
@@ -101,19 +108,28 @@ export const MetaImage = (props)=>{
101
108
  position: 'relative'
102
109
  },
103
110
  children: /*#__PURE__*/ _jsx(UploadInput, {
104
- CustomError: errorMessage,
105
111
  api: api,
106
112
  collection: collection,
113
+ Error: {
114
+ type: 'client',
115
+ Component: null,
116
+ RenderedComponent: errorMessage
117
+ },
107
118
  filterOptions: field.filterOptions,
108
119
  label: undefined,
109
120
  onChange: (incomingImage)=>{
110
121
  if (incomingImage !== null) {
111
- const { id: incomingID } = incomingImage;
112
- setValue(incomingID);
122
+ if (typeof incomingImage === 'object') {
123
+ const { id: incomingID } = incomingImage;
124
+ setValue(incomingID);
125
+ } else {
126
+ setValue(incomingImage);
127
+ }
113
128
  } else {
114
129
  setValue(null);
115
130
  }
116
131
  },
132
+ path: field.path,
117
133
  relationTo: relationTo,
118
134
  required: required,
119
135
  serverURL: serverURL,
@@ -140,4 +156,4 @@ export const MetaImage = (props)=>{
140
156
  });
141
157
  };
142
158
 
143
- //# sourceMappingURL=MetaImage.js.map
159
+ //# sourceMappingURL=MetaImageComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { UploadFieldProps } from 'payload'\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) {\n return\n }\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 field={null} Label={Label} 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 api={api}\n collection={collection}\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n filterOptions={field.filterOptions}\n label={undefined}\n onChange={(incomingImage) => {\n if (incomingImage !== null) {\n if (typeof incomingImage === 'object') {\n const { id: incomingID } = incomingImage\n setValue(incomingID)\n } else {\n setValue(incomingImage)\n }\n } else {\n setValue(null)\n }\n }}\n path={field.path}\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;;AAKA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAA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CACrC,MAAM,EAAE/C,IAAIgD,UAAU,EAAE,GAAGD;gCAC3BxD,SAASyD;4BACX,OAAO;gCACLzD,SAASwD;4BACX;wBACF,OAAO;4BACLxD,SAAS;wBACX;oBACF;oBACAP,MAAMT,MAAMS,IAAI;oBAChBJ,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"}
@@ -0,0 +1,13 @@
1
+ import type { UploadField } from 'payload';
2
+ interface FieldFunctionProps {
3
+ /**
4
+ * Tell the component if the generate function is available as configured in the plugin config
5
+ */
6
+ hasGenerateFn?: boolean;
7
+ overrides?: Partial<UploadField>;
8
+ relationTo: string;
9
+ }
10
+ type FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UploadField;
11
+ export declare const MetaImageField: FieldFunction;
12
+ export {};
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;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"}
@@ -0,0 +1,23 @@
1
+ export const MetaImageField = ({ hasGenerateFn = false, overrides, relationTo })=>{
2
+ return {
3
+ name: 'image',
4
+ type: 'upload',
5
+ admin: {
6
+ components: {
7
+ Field: {
8
+ clientProps: {
9
+ hasGenerateImageFn: hasGenerateFn
10
+ },
11
+ path: '@payloadcms/plugin-seo/client#MetaImageComponent'
12
+ }
13
+ },
14
+ description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.'
15
+ },
16
+ label: 'Meta Image',
17
+ localized: true,
18
+ relationTo,
19
+ ...overrides ?? {}
20
+ };
21
+ };
22
+
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,9 @@
1
+ import type { TextFieldProps } from 'payload';
2
+ import React from 'react';
3
+ import '../index.scss';
4
+ type MetaTitleProps = {
5
+ readonly hasGenerateTitleFn: boolean;
6
+ } & TextFieldProps;
7
+ export declare const MetaTitleComponent: React.FC<MetaTitleProps>;
8
+ export {};
9
+ //# sourceMappingURL=MetaTitleComponent.d.ts.map
@@ -0,0 +1 @@
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,CA+IvD,CAAA"}
@@ -1,38 +1,38 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { FieldLabel } from '@payloadcms/ui/fields/FieldLabel';
4
- import { TextInput } from '@payloadcms/ui/fields/Text';
5
- import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
6
- import { useAllFormFields } from '@payloadcms/ui/forms/Form';
7
- import { useField } from '@payloadcms/ui/forms/useField';
8
- import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
9
- import { useLocale } from '@payloadcms/ui/providers/Locale';
10
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
3
+ import { FieldLabel, TextInput, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
11
4
  import React, { useCallback } from 'react';
12
- import { defaults } from '../defaults.js';
13
- import { LengthIndicator } from '../ui/LengthIndicator.js';
14
- import './index.scss';
5
+ import { defaults } from '../../defaults.js';
6
+ import { LengthIndicator } from '../../ui/LengthIndicator.js';
7
+ import '../index.scss';
15
8
  const { maxLength, minLength } = defaults.title;
16
- export const MetaTitle = (props)=>{
17
- const { CustomLabel, hasGenerateTitleFn, label, labelProps, path, required } = props || {};
9
+ export const MetaTitleComponent = (props)=>{
10
+ const { field: { admin: { components: { Label } }, label, required }, hasGenerateTitleFn, labelProps } = props || {};
18
11
  const { path: pathFromContext } = useFieldProps();
19
12
  const { t } = useTranslation();
20
13
  const field = useField({
21
- path
14
+ path: pathFromContext
22
15
  });
23
16
  const locale = useLocale();
24
- const [fields] = useAllFormFields();
17
+ const { getData } = useForm();
25
18
  const docInfo = useDocumentInfo();
26
19
  const { errorMessage, setValue, showError, value } = field;
27
20
  const regenerateTitle = useCallback(async ()=>{
28
- if (!hasGenerateTitleFn) return;
21
+ if (!hasGenerateTitleFn) {
22
+ return;
23
+ }
29
24
  const genTitleResponse = await fetch('/api/plugin-seo/generate-title', {
30
25
  body: JSON.stringify({
31
- ...docInfo,
32
- doc: {
33
- ...fields
34
- },
35
- locale: typeof locale === 'object' ? locale?.code : locale
26
+ id: docInfo.id,
27
+ slug: docInfo.slug,
28
+ doc: getData(),
29
+ docPermissions: docInfo.docPermissions,
30
+ hasPublishPermission: docInfo.hasPublishPermission,
31
+ hasSavePermission: docInfo.hasSavePermission,
32
+ initialData: docInfo.initialData,
33
+ initialState: docInfo.initialState,
34
+ locale: typeof locale === 'object' ? locale?.code : locale,
35
+ title: docInfo.title
36
36
  }),
37
37
  credentials: 'include',
38
38
  headers: {
@@ -43,11 +43,11 @@ export const MetaTitle = (props)=>{
43
43
  const { result: generatedTitle } = await genTitleResponse.json();
44
44
  setValue(generatedTitle || '');
45
45
  }, [
46
- fields,
47
- setValue,
48
46
  hasGenerateTitleFn,
47
+ docInfo,
48
+ getData,
49
49
  locale,
50
- docInfo
50
+ setValue
51
51
  ]);
52
52
  return /*#__PURE__*/ _jsxs("div", {
53
53
  style: {
@@ -64,7 +64,8 @@ export const MetaTitle = (props)=>{
64
64
  className: "plugin-seo__field",
65
65
  children: [
66
66
  /*#__PURE__*/ _jsx(FieldLabel, {
67
- CustomLabel: CustomLabel,
67
+ field: null,
68
+ Label: Label,
68
69
  label: label,
69
70
  ...labelProps || {}
70
71
  }),
@@ -72,7 +73,9 @@ export const MetaTitle = (props)=>{
72
73
  children: [
73
74
  "  —  ",
74
75
  /*#__PURE__*/ _jsx("button", {
75
- onClick: regenerateTitle,
76
+ onClick: ()=>{
77
+ void regenerateTitle();
78
+ },
76
79
  style: {
77
80
  background: 'none',
78
81
  backgroundColor: 'transparent',
@@ -115,7 +118,12 @@ export const MetaTitle = (props)=>{
115
118
  position: 'relative'
116
119
  },
117
120
  children: /*#__PURE__*/ _jsx(TextInput, {
118
- CustomError: errorMessage,
121
+ Error: {
122
+ type: 'client',
123
+ Component: null,
124
+ RenderedComponent: errorMessage
125
+ },
126
+ label: label,
119
127
  onChange: setValue,
120
128
  path: pathFromContext,
121
129
  required: required,
@@ -142,4 +150,4 @@ export const MetaTitle = (props)=>{
142
150
  });
143
151
  };
144
152
 
145
- //# sourceMappingURL=MetaTitle.js.map
153
+ //# sourceMappingURL=MetaTitleComponent.js.map