@payloadcms/plugin-seo 3.0.0-canary.f6e77b8 → 3.0.0-canary.f83d96a

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 (40) hide show
  1. package/dist/defaults.js.map +1 -1
  2. package/dist/exports/types.js.map +1 -1
  3. package/dist/fields/MetaDescription.d.ts +1 -1
  4. package/dist/fields/MetaDescription.d.ts.map +1 -1
  5. package/dist/fields/MetaDescription.js +94 -74
  6. package/dist/fields/MetaDescription.js.map +1 -1
  7. package/dist/fields/MetaImage.d.ts +1 -1
  8. package/dist/fields/MetaImage.d.ts.map +1 -1
  9. package/dist/fields/MetaImage.js +95 -79
  10. package/dist/fields/MetaImage.js.map +1 -1
  11. package/dist/fields/MetaTitle.d.ts +1 -1
  12. package/dist/fields/MetaTitle.d.ts.map +1 -1
  13. package/dist/fields/MetaTitle.js +95 -74
  14. package/dist/fields/MetaTitle.js.map +1 -1
  15. package/dist/fields/index.scss +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +26 -14
  19. package/dist/index.js.map +1 -1
  20. package/dist/translations/index.d.ts +25 -0
  21. package/dist/translations/index.d.ts.map +1 -1
  22. package/dist/translations/index.js +22 -0
  23. package/dist/translations/index.js.map +1 -1
  24. package/dist/translations/ru.json +22 -0
  25. package/dist/types.d.ts +6 -6
  26. package/dist/types.d.ts.map +1 -1
  27. package/dist/types.js.map +1 -1
  28. package/dist/ui/LengthIndicator.d.ts.map +1 -1
  29. package/dist/ui/LengthIndicator.js +62 -41
  30. package/dist/ui/LengthIndicator.js.map +1 -1
  31. package/dist/ui/Overview.d.ts.map +1 -1
  32. package/dist/ui/Overview.js +11 -8
  33. package/dist/ui/Overview.js.map +1 -1
  34. package/dist/ui/Pill.js +7 -3
  35. package/dist/ui/Pill.js.map +1 -1
  36. package/dist/ui/Preview.d.ts +1 -1
  37. package/dist/ui/Preview.d.ts.map +1 -1
  38. package/dist/ui/Preview.js +60 -40
  39. package/dist/ui/Preview.js.map +1 -1
  40. package/package.json +24 -18
@@ -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"}
@@ -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"}
@@ -1,4 +1,4 @@
1
- import type { FormFieldBase } from '@payloadcms/ui/fields/shared';
1
+ import type { FormFieldBase } from '@payloadcms/ui';
2
2
  import React from 'react';
3
3
  type MetaDescriptionProps = FormFieldBase & {
4
4
  hasGenerateDescriptionFn: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"MetaDescription.d.ts","sourceRoot":"","sources":["../../src/fields/MetaDescription.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAWjE,OAAO,KAAsB,MAAM,OAAO,CAAA;AAU1C,KAAK,oBAAoB,GAAG,aAAa,GAAG;IAC1C,wBAAwB,EAAE,OAAO,CAAA;IACjC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAoH1D,CAAA"}
1
+ {"version":3,"file":"MetaDescription.d.ts","sourceRoot":"","sources":["../../src/fields/MetaDescription.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,aAAa,EAAW,MAAM,gBAAgB,CAAA;AAYvE,OAAO,KAAsB,MAAM,OAAO,CAAA;AAW1C,KAAK,oBAAoB,GAAG,aAAa,GAAG;IAC1C,wBAAwB,EAAE,OAAO,CAAA;IACjC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAoH1D,CAAA"}
@@ -1,12 +1,6 @@
1
1
  'use client';
2
- import { TextareaInput } from '@payloadcms/ui/fields/Textarea';
3
- import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel';
4
- import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
5
- import { useAllFormFields } from '@payloadcms/ui/forms/Form';
6
- import { useField } from '@payloadcms/ui/forms/useField';
7
- import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
8
- import { useLocale } from '@payloadcms/ui/providers/Locale';
9
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldLabel, TextareaInput, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
10
4
  import React, { useCallback } from 'react';
11
5
  import { defaults } from '../defaults.js';
12
6
  import { LengthIndicator } from '../ui/LengthIndicator.js';
@@ -16,7 +10,7 @@ export const MetaDescription = (props)=>{
16
10
  const { path: pathFromContext } = useFieldProps();
17
11
  const { t } = useTranslation();
18
12
  const locale = useLocale();
19
- const [fields] = useAllFormFields();
13
+ const { getData } = useForm();
20
14
  const docInfo = useDocumentInfo();
21
15
  const field = useField({
22
16
  path
@@ -28,7 +22,7 @@ export const MetaDescription = (props)=>{
28
22
  body: JSON.stringify({
29
23
  ...docInfo,
30
24
  doc: {
31
- ...fields
25
+ ...getData()
32
26
  },
33
27
  locale: typeof locale === 'object' ? locale?.code : locale
34
28
  }),
@@ -41,76 +35,102 @@ export const MetaDescription = (props)=>{
41
35
  const { result: generatedDescription } = await genDescriptionResponse.json();
42
36
  setValue(generatedDescription || '');
43
37
  }, [
44
- fields,
45
- setValue,
46
38
  hasGenerateDescriptionFn,
39
+ docInfo,
40
+ getData,
47
41
  locale,
48
- docInfo
42
+ setValue
49
43
  ]);
50
- return /*#__PURE__*/ React.createElement("div", {
44
+ return /*#__PURE__*/ _jsxs("div", {
51
45
  style: {
52
46
  marginBottom: '20px'
53
- }
54
- }, /*#__PURE__*/ React.createElement("div", {
55
- style: {
56
- marginBottom: '5px',
57
- position: 'relative'
58
- }
59
- }, /*#__PURE__*/ React.createElement("div", {
60
- className: "plugin-seo__field"
61
- }, /*#__PURE__*/ React.createElement(FieldLabel, {
62
- CustomLabel: CustomLabel,
63
- label: label,
64
- ...labelProps || {}
65
- }), hasGenerateDescriptionFn && /*#__PURE__*/ React.createElement(React.Fragment, null, "  —  ", /*#__PURE__*/ React.createElement("button", {
66
- onClick: regenerateDescription,
67
- style: {
68
- background: 'none',
69
- backgroundColor: 'transparent',
70
- border: 'none',
71
- color: 'currentcolor',
72
- cursor: 'pointer',
73
- padding: 0,
74
- textDecoration: 'underline'
75
47
  },
76
- type: "button"
77
- }, t('plugin-seo:autoGenerate')))), /*#__PURE__*/ React.createElement("div", {
78
- style: {
79
- color: '#9A9A9A'
80
- }
81
- }, t('plugin-seo:lengthTipDescription', {
82
- maxLength,
83
- minLength
84
- }), /*#__PURE__*/ React.createElement("a", {
85
- href: "https://developers.google.com/search/docs/advanced/appearance/snippet#meta-descriptions",
86
- rel: "noopener noreferrer",
87
- target: "_blank"
88
- }, t('plugin-seo:bestPractices')))), /*#__PURE__*/ React.createElement("div", {
89
- style: {
90
- marginBottom: '10px',
91
- position: 'relative'
92
- }
93
- }, /*#__PURE__*/ React.createElement(TextareaInput, {
94
- CustomError: errorMessage,
95
- onChange: setValue,
96
- path: pathFromContext,
97
- required: required,
98
- showError: showError,
99
- style: {
100
- marginBottom: 0
101
- },
102
- value: value
103
- })), /*#__PURE__*/ React.createElement("div", {
104
- style: {
105
- alignItems: 'center',
106
- display: 'flex',
107
- width: '100%'
108
- }
109
- }, /*#__PURE__*/ React.createElement(LengthIndicator, {
110
- maxLength: maxLength,
111
- minLength: minLength,
112
- text: value
113
- })));
48
+ children: [
49
+ /*#__PURE__*/ _jsxs("div", {
50
+ style: {
51
+ marginBottom: '5px',
52
+ position: 'relative'
53
+ },
54
+ children: [
55
+ /*#__PURE__*/ _jsxs("div", {
56
+ className: "plugin-seo__field",
57
+ children: [
58
+ /*#__PURE__*/ _jsx(FieldLabel, {
59
+ CustomLabel: CustomLabel,
60
+ label: label,
61
+ ...labelProps || {}
62
+ }),
63
+ hasGenerateDescriptionFn && /*#__PURE__*/ _jsxs(React.Fragment, {
64
+ children: [
65
+ "  —  ",
66
+ /*#__PURE__*/ _jsx("button", {
67
+ onClick: regenerateDescription,
68
+ style: {
69
+ background: 'none',
70
+ backgroundColor: 'transparent',
71
+ border: 'none',
72
+ color: 'currentcolor',
73
+ cursor: 'pointer',
74
+ padding: 0,
75
+ textDecoration: 'underline'
76
+ },
77
+ type: "button",
78
+ children: t('plugin-seo:autoGenerate')
79
+ })
80
+ ]
81
+ })
82
+ ]
83
+ }),
84
+ /*#__PURE__*/ _jsxs("div", {
85
+ style: {
86
+ color: '#9A9A9A'
87
+ },
88
+ children: [
89
+ t('plugin-seo:lengthTipDescription', {
90
+ maxLength,
91
+ minLength
92
+ }),
93
+ /*#__PURE__*/ _jsx("a", {
94
+ href: "https://developers.google.com/search/docs/advanced/appearance/snippet#meta-descriptions",
95
+ rel: "noopener noreferrer",
96
+ target: "_blank",
97
+ children: t('plugin-seo:bestPractices')
98
+ })
99
+ ]
100
+ })
101
+ ]
102
+ }),
103
+ /*#__PURE__*/ _jsx("div", {
104
+ style: {
105
+ marginBottom: '10px',
106
+ position: 'relative'
107
+ },
108
+ children: /*#__PURE__*/ _jsx(TextareaInput, {
109
+ CustomError: errorMessage,
110
+ onChange: setValue,
111
+ path: pathFromContext,
112
+ required: required,
113
+ showError: showError,
114
+ style: {
115
+ marginBottom: 0
116
+ },
117
+ value: value
118
+ })
119
+ }),
120
+ /*#__PURE__*/ _jsx("div", {
121
+ style: {
122
+ alignItems: 'center',
123
+ display: 'flex',
124
+ width: '100%'
125
+ },
126
+ children: /*#__PURE__*/ _jsx(LengthIndicator, {
127
+ maxLength: maxLength,
128
+ minLength: minLength,
129
+ text: value
130
+ })
131
+ })
132
+ ]
133
+ });
114
134
  };
115
135
 
116
136
  //# sourceMappingURL=MetaDescription.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fields/MetaDescription.tsx"],"sourcesContent":["'use client'\n\nimport type { FormFieldBase } from '@payloadcms/ui/fields/shared'\nimport type { FieldType, Options } from '@payloadcms/ui/forms/useField'\n\nimport { TextareaInput } from '@payloadcms/ui/fields/Textarea'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form'\nimport { useField } from '@payloadcms/ui/forms/useField'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { useLocale } from '@payloadcms/ui/providers/Locale'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport React, { useCallback } from 'react'\n\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\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\ntype MetaDescriptionProps = FormFieldBase & {\n hasGenerateDescriptionFn: boolean\n path: string\n}\n\nexport const MetaDescription: React.FC<MetaDescriptionProps> = (props) => {\n const { CustomLabel, hasGenerateDescriptionFn, label, labelProps, path, required } = props\n const { path: pathFromContext } = useFieldProps()\n\n const { t } = useTranslation()\n\n const locale = useLocale()\n const [fields] = useAllFormFields()\n const docInfo = useDocumentInfo()\n\n const field: FieldType<string> = useField({\n path,\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: { ...fields },\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 }, [fields, setValue, hasGenerateDescriptionFn, locale, docInfo])\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={regenerateDescription}\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":["TextareaInput","FieldLabel","useFieldProps","useAllFormFields","useField","useDocumentInfo","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","description","MetaDescription","props","CustomLabel","hasGenerateDescriptionFn","label","labelProps","path","required","pathFromContext","t","locale","fields","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAKA,SAASA,aAAa,QAAQ,iCAAgC;AAC9D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,SAAS,QAAQ,kCAAiC;A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;QAAII,WAAU;qBACb,oBAAClD;QAAWgB,aAAaA;QAAaE,OAAOA;QAAQ,GAAIC,cAAc,CAAC,CAAC;QACxEF,0CACC,oBAACV,MAAM4C,QAAQ,QAAC,uBAEd,oBAACC;QACCC,SAASrB;QACTe,OAAO;YACLO,YAAY;YACZC,iBAAiB;YACjBC,QAAQ;YACRC,OAAO;YACPC,QAAQ;YACRC,SAAS;YACTC,gBAAgB;QAClB;QACAC,MAAK;OAEJtC,EAAE,6CAKX,oBAACuB;QACCC,OAAO;YACLU,OAAO;QACT;OAEClC,EAAE,mCAAmC;QAAEZ;QAAWC;IAAU,kBAC7D,oBAACkD;QACCC,MAAK;QACLC,KAAI;QACJC,QAAO;OAEN1C,EAAE,8CAIT,oBAACuB;QACCC,OAAO;YACLC,cAAc;YACdC,UAAU;QACZ;qBAEA,oBAAClD;QACCmE,aAAatC;QACbuC,UAAUtC;QACVT,MAAME;QACND,UAAUA;QACVS,WAAWA;QACXiB,OAAO;YACLC,cAAc;QAChB;QACAjB,OAAOA;uBAGX,oBAACe;QACCC,OAAO;YACLqB,YAAY;YACZC,SAAS;YACTC,OAAO;QACT;qBAEA,oBAAC5D;QAAgBC,WAAWA;QAAWC,WAAWA;QAAW2D,MAAMxC;;AAI3E,EAAC"}
1
+ {"version":3,"sources":["../../src/fields/MetaDescription.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, FormFieldBase, Options } from '@payloadcms/ui'\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\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\ntype MetaDescriptionProps = FormFieldBase & {\n hasGenerateDescriptionFn: boolean\n path: string\n}\n\nexport const MetaDescription: React.FC<MetaDescriptionProps> = (props) => {\n const { CustomLabel, hasGenerateDescriptionFn, label, labelProps, path, 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,\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={regenerateDescription}\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","MetaDescription","props","CustomLabel","hasGenerateDescriptionFn","label","labelProps","path","required","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;;AAIA,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,iBAAgB;AACzC,SAASC,eAAe,QAAQ,2BAA0B;AAE1D,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH,SAASI,WAAW;AAQrD,OAAO,MAAMC,kBAAkD,CAACC;IAC9D,MAAM,EAAEC,WAAW,EAAEC,wBAAwB,EAAEC,KAAK,EAAEC,UAAU,EAAEC,IAAI,EAAEC,QAAQ,EAAE,GAAGN;IACrF,MAAM,EAAEK,MAAME,eAAe,EAAE,GAAGnB;IAElC,MAAM,EAAEoB,CAAC,EAAE,GAAGjB;IAEd,MAAMkB,SAASnB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CACLC,KAAI;gCACJC,QAAO;0CAEN1C,EAAE;;;;;;0BAIT,KAACuB;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAACjD;oBACCkE,aAAatC;oBACbuC,UAAUtC;oBACVT,MAAME;oBACND,UAAUA;oBACVS,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,4 +1,4 @@
1
- import type { UploadInputProps } from '@payloadcms/ui/fields/Upload';
1
+ import type { UploadInputProps } from '@payloadcms/ui';
2
2
  import React from 'react';
3
3
  type MetaImageProps = UploadInputProps & {
4
4
  hasGenerateImageFn: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"MetaImage.d.ts","sourceRoot":"","sources":["../../src/fields/MetaImage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAWpE,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,KAAK,cAAc,GAAG,gBAAgB,GAAG;IACvC,kBAAkB,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAoI9C,CAAA"}
1
+ {"version":3,"file":"MetaImage.d.ts","sourceRoot":"","sources":["../../src/fields/MetaImage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAY1E,OAAO,KAAsB,MAAM,OAAO,CAAA;AAQ1C,KAAK,cAAc,GAAG,gBAAgB,GAAG;IACvC,kBAAkB,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAoI9C,CAAA"}
@@ -1,12 +1,6 @@
1
1
  'use client';
2
- import { UploadInput } from '@payloadcms/ui/fields/Upload';
3
- import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel';
4
- import { useAllFormFields } from '@payloadcms/ui/forms/Form';
5
- import { useField } from '@payloadcms/ui/forms/useField';
6
- import { useConfig } from '@payloadcms/ui/providers/Config';
7
- import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
8
- import { useLocale } from '@payloadcms/ui/providers/Locale';
9
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldLabel, UploadInput, useConfig, useDocumentInfo, useField, useForm, useLocale, useTranslation } from '@payloadcms/ui';
10
4
  import React, { useCallback } from 'react';
11
5
  import { Pill } from '../ui/Pill.js';
12
6
  export const MetaImage = (props)=>{
@@ -14,7 +8,7 @@ export const MetaImage = (props)=>{
14
8
  const field = useField(props);
15
9
  const { t } = useTranslation();
16
10
  const locale = useLocale();
17
- const [fields] = useAllFormFields();
11
+ const { getData } = useForm();
18
12
  const docInfo = useDocumentInfo();
19
13
  const { errorMessage, setValue, showError, value } = field;
20
14
  const regenerateImage = useCallback(async ()=>{
@@ -23,7 +17,7 @@ export const MetaImage = (props)=>{
23
17
  body: JSON.stringify({
24
18
  ...docInfo,
25
19
  doc: {
26
- ...fields
20
+ ...getData()
27
21
  },
28
22
  locale: typeof locale === 'object' ? locale?.code : locale
29
23
  }),
@@ -36,85 +30,107 @@ export const MetaImage = (props)=>{
36
30
  const { result: generatedImage } = await genImageResponse.json();
37
31
  setValue(generatedImage || '');
38
32
  }, [
39
- fields,
40
- setValue,
41
33
  hasGenerateImageFn,
34
+ docInfo,
35
+ getData,
42
36
  locale,
43
- docInfo
37
+ setValue
44
38
  ]);
45
39
  const hasImage = Boolean(value);
46
40
  const config = useConfig();
47
41
  const { collections, routes: { api } = {}, serverURL } = config;
48
42
  const collection = collections?.find((coll)=>coll.slug === relationTo) || undefined;
49
- return /*#__PURE__*/ React.createElement("div", {
43
+ return /*#__PURE__*/ _jsxs("div", {
50
44
  style: {
51
45
  marginBottom: '20px'
52
- }
53
- }, /*#__PURE__*/ React.createElement("div", {
54
- style: {
55
- marginBottom: '5px',
56
- position: 'relative'
57
- }
58
- }, /*#__PURE__*/ React.createElement("div", {
59
- className: "plugin-seo__field"
60
- }, /*#__PURE__*/ React.createElement(FieldLabel, {
61
- CustomLabel: CustomLabel,
62
- label: label,
63
- ...labelProps || {}
64
- }), hasGenerateImageFn && /*#__PURE__*/ React.createElement(React.Fragment, null, "  —  ", /*#__PURE__*/ React.createElement("button", {
65
- onClick: regenerateImage,
66
- style: {
67
- background: 'none',
68
- backgroundColor: 'transparent',
69
- border: 'none',
70
- color: 'currentcolor',
71
- cursor: 'pointer',
72
- padding: 0,
73
- textDecoration: 'underline'
74
- },
75
- type: "button"
76
- }, t('plugin-seo:autoGenerate')))), hasGenerateImageFn && /*#__PURE__*/ React.createElement("div", {
77
- style: {
78
- color: '#9A9A9A'
79
- }
80
- }, t('plugin-seo:imageAutoGenerationTip'))), /*#__PURE__*/ React.createElement("div", {
81
- style: {
82
- marginBottom: '10px',
83
- position: 'relative'
84
- }
85
- }, /*#__PURE__*/ React.createElement(UploadInput, {
86
- CustomError: errorMessage,
87
- api: api,
88
- collection: collection,
89
- filterOptions: {},
90
- label: undefined,
91
- onChange: (incomingImage)=>{
92
- if (incomingImage !== null) {
93
- const { id: incomingID } = incomingImage;
94
- setValue(incomingID);
95
- } else {
96
- setValue(null);
97
- }
98
- },
99
- relationTo: relationTo,
100
- required: required,
101
- serverURL: serverURL,
102
- showError: showError,
103
- style: {
104
- marginBottom: 0
105
46
  },
106
- value: value
107
- })), /*#__PURE__*/ React.createElement("div", {
108
- style: {
109
- alignItems: 'center',
110
- display: 'flex',
111
- width: '100%'
112
- }
113
- }, /*#__PURE__*/ React.createElement(Pill, {
114
- backgroundColor: hasImage ? 'green' : 'red',
115
- color: "white",
116
- label: hasImage ? t('plugin-seo:good') : t('plugin-seo:noImage')
117
- })));
47
+ children: [
48
+ /*#__PURE__*/ _jsxs("div", {
49
+ style: {
50
+ marginBottom: '5px',
51
+ position: 'relative'
52
+ },
53
+ children: [
54
+ /*#__PURE__*/ _jsxs("div", {
55
+ className: "plugin-seo__field",
56
+ children: [
57
+ /*#__PURE__*/ _jsx(FieldLabel, {
58
+ CustomLabel: CustomLabel,
59
+ label: label,
60
+ ...labelProps || {}
61
+ }),
62
+ hasGenerateImageFn && /*#__PURE__*/ _jsxs(React.Fragment, {
63
+ children: [
64
+ "  —  ",
65
+ /*#__PURE__*/ _jsx("button", {
66
+ onClick: regenerateImage,
67
+ style: {
68
+ background: 'none',
69
+ backgroundColor: 'transparent',
70
+ border: 'none',
71
+ color: 'currentcolor',
72
+ cursor: 'pointer',
73
+ padding: 0,
74
+ textDecoration: 'underline'
75
+ },
76
+ type: "button",
77
+ children: t('plugin-seo:autoGenerate')
78
+ })
79
+ ]
80
+ })
81
+ ]
82
+ }),
83
+ hasGenerateImageFn && /*#__PURE__*/ _jsx("div", {
84
+ style: {
85
+ color: '#9A9A9A'
86
+ },
87
+ children: t('plugin-seo:imageAutoGenerationTip')
88
+ })
89
+ ]
90
+ }),
91
+ /*#__PURE__*/ _jsx("div", {
92
+ style: {
93
+ marginBottom: '10px',
94
+ position: 'relative'
95
+ },
96
+ children: /*#__PURE__*/ _jsx(UploadInput, {
97
+ CustomError: errorMessage,
98
+ api: api,
99
+ collection: collection,
100
+ filterOptions: field.filterOptions,
101
+ label: undefined,
102
+ onChange: (incomingImage)=>{
103
+ if (incomingImage !== null) {
104
+ const { id: incomingID } = incomingImage;
105
+ setValue(incomingID);
106
+ } else {
107
+ setValue(null);
108
+ }
109
+ },
110
+ relationTo: relationTo,
111
+ required: required,
112
+ serverURL: serverURL,
113
+ showError: showError,
114
+ style: {
115
+ marginBottom: 0
116
+ },
117
+ value: value
118
+ })
119
+ }),
120
+ /*#__PURE__*/ _jsx("div", {
121
+ style: {
122
+ alignItems: 'center',
123
+ display: 'flex',
124
+ width: '100%'
125
+ },
126
+ children: /*#__PURE__*/ _jsx(Pill, {
127
+ backgroundColor: hasImage ? 'green' : 'red',
128
+ color: "white",
129
+ label: hasImage ? t('plugin-seo:good') : t('plugin-seo:noImage')
130
+ })
131
+ })
132
+ ]
133
+ });
118
134
  };
119
135
 
120
136
  //# sourceMappingURL=MetaImage.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fields/MetaImage.tsx"],"sourcesContent":["'use client'\n\nimport type { UploadInputProps } from '@payloadcms/ui/fields/Upload'\nimport type { FieldType, Options } from '@payloadcms/ui/forms/useField'\n\nimport { UploadInput } from '@payloadcms/ui/fields/Upload'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form'\nimport { useField } from '@payloadcms/ui/forms/useField'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { useLocale } from '@payloadcms/ui/providers/Locale'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport React, { useCallback } from 'react'\n\nimport type { GenerateImage } from '../types.js'\n\nimport { Pill } from '../ui/Pill.js'\n\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\ntype MetaImageProps = UploadInputProps & {\n hasGenerateImageFn: boolean\n}\n\nexport const MetaImage: React.FC<MetaImageProps> = (props) => {\n const { CustomLabel, hasGenerateImageFn, label, labelProps, relationTo, required } = props || {}\n\n const field: FieldType<string> = useField(props as Options)\n\n const { t } = useTranslation()\n\n const locale = useLocale()\n const [fields] = useAllFormFields()\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: { ...fields },\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 }, [fields, setValue, hasGenerateImageFn, locale, docInfo])\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={regenerateImage}\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={{}}\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":["UploadInput","FieldLabel","useAllFormFields","useField","useConfig","useDocumentInfo","useLocale","useTranslation","React","useCallback","Pill","MetaImage","props","CustomLabel","hasGenerateImageFn","label","labelProps","relationTo","required","field","t","locale","fields","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAKA,SAASA,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAI1C,SAASC,IAAI,QAAQ,gBAAe;AAOpC,OAAO,MAAMC,YAAsC,CAACC;IAClD,MAAM,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,KAAK,EAAEC,UAAU,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGN,SAAS,CAAC;IAE/F,MAAMO,QAA2BhB,SAASS;IAE1C,MAAM,EAAEQ,CAAC,EAAE,GAAGb;IAEd,MAAMc,SAASf;IACf,MAAM,CAACgB,OAAO,GAAGpB;I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,oCACC,oBAACwC;QACCC,OAAO;YACLU,OAAO;QACT;OAEC7C,EAAE,sDAIT,oBAACkC;QACCC,OAAO;YACLC,cAAc;YACdC,UAAU;QACZ;qBAEA,oBAACzD;QACCsE,aAAa9C;QACbuB,KAAKA;QACLE,YAAYA;QACZsB,eAAe,CAAC;QAChBxD,OAAOsC;QACPmB,UAAU,CAACC;YACT,IAAIA,kBAAkB,MAAM;gBAC1B,MAAM,EAAEC,IAAIC,UAAU,EAAE,GAAGF;gBAC3BhD,SAASkD;YACX,OAAO;gBACLlD,SAAS;YACX;QACF;QACAR,YAAYA;QACZC,UAAUA;QACV8B,WAAWA;QACXtB,WAAWA;QACX6B,OAAO;YACLC,cAAc;QAChB;QACA7B,OAAOA;uBAGX,oBAAC2B;QACCC,OAAO;YACLqB,YAAY;YACZC,SAAS;YACTC,OAAO;QACT;qBAEA,oBAACpE;QACCqD,iBAAiBrB,WAAW,UAAU;QACtCuB,OAAM;QACNlD,OAAO2B,WAAWtB,EAAE,qBAAqBA,EAAE;;AAKrD,EAAC"}
1
+ {"version":3,"sources":["../../src/fields/MetaImage.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 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\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\ntype MetaImageProps = UploadInputProps & {\n hasGenerateImageFn: boolean\n}\n\nexport const MetaImage: React.FC<MetaImageProps> = (props) => {\n const { CustomLabel, hasGenerateImageFn, label, labelProps, relationTo, required } = props || {}\n\n const field: FieldType<string> = useField(props 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={regenerateImage}\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","useForm","useLocale","useTranslation","React","useCallback","Pill","MetaImage","props","CustomLabel","hasGenerateImageFn","label","labelProps","relationTo","required","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,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,IAAI,QAAQ,gBAAe;AAOpC,OAAO,MAAMC,YAAsC,CAACC;IAClD,MAAM,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,KAAK,EAAEC,UAAU,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGN,SAAS,CAAC;IAE/F,MAAMO,QAA2Bf,SAASQ;IAE1C,MAAM,EAAEQ,CAAC,EAAE,GAAGb;IAEd,MAAMc,SAASf;IACf,MAAM,EAAEgB,OAAO,EAAE,GAAGjB;IACpB,MAAMkB,UAAUpB;IAEhB,MAAM,EAAEqB,YAAY,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGR;IAErD,MAAMS,kBAAkB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;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAACxD;oBACCqE,aAAa9C;oBACbuB,KAAKA;oBACLE,YAAYA;oBACZsB,eAAepD,MAAMoD,aAAa;oBAClCxD,OAAOsC;oBACPmB,UAAU,CAACC;wBACT,IAAIA,kBAAkB,MAAM;4BAC1B,MAAM,EAAEC,IAAIC,UAAU,EAAE,GAAGF;4BAC3BhD,SAASkD;wBACX,OAAO;4BACLlD,SAAS;wBACX;oBACF;oBACAR,YAAYA;oBACZC,UAAUA;oBACV8B,WAAWA;oBACXtB,WAAWA;oBACX6B,OAAO;wBACLC,cAAc;oBAChB;oBACA7B,OAAOA;;;0BAGX,KAAC2B;gBACCC,OAAO;oBACLqB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAACpE;oBACCqD,iBAAiBrB,WAAW,UAAU;oBACtCuB,OAAM;oBACNlD,OAAO2B,WAAWtB,EAAE,qBAAqBA,EAAE;;;;;AAKrD,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { FormFieldBase } from '@payloadcms/ui/fields/shared';
1
+ import type { FormFieldBase } from '@payloadcms/ui';
2
2
  import React from 'react';
3
3
  import './index.scss';
4
4
  type MetaTitleProps = FormFieldBase & {
@@ -1 +1 @@
1
- {"version":3,"file":"MetaTitle.d.ts","sourceRoot":"","sources":["../../src/fields/MetaTitle.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAYjE,OAAO,KAAsB,MAAM,OAAO,CAAA;AAM1C,OAAO,cAAc,CAAA;AAKrB,KAAK,cAAc,GAAG,aAAa,GAAG;IACpC,kBAAkB,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAqH9C,CAAA"}
1
+ {"version":3,"file":"MetaTitle.d.ts","sourceRoot":"","sources":["../../src/fields/MetaTitle.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,aAAa,EAAW,MAAM,gBAAgB,CAAA;AAYvE,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,OAAO,cAAc,CAAA;AAKrB,KAAK,cAAc,GAAG,aAAa,GAAG;IACpC,kBAAkB,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAqH9C,CAAA"}