@payloadcms/plugin-seo 3.0.0-canary.6041f49 → 3.0.0-canary.6d0dfea

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 (84) hide show
  1. package/dist/defaults.js.map +1 -1
  2. package/dist/exports/fields.d.ts +6 -0
  3. package/dist/exports/fields.d.ts.map +1 -0
  4. package/dist/exports/fields.js +7 -0
  5. package/dist/exports/fields.js.map +1 -0
  6. package/dist/exports/types.js.map +1 -1
  7. package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts +9 -0
  8. package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts.map +1 -0
  9. package/dist/fields/MetaDescription/MetaDescriptionComponent.js +136 -0
  10. package/dist/fields/MetaDescription/MetaDescriptionComponent.js.map +1 -0
  11. package/dist/fields/MetaDescription/index.d.ts +12 -0
  12. package/dist/fields/MetaDescription/index.d.ts.map +1 -0
  13. package/dist/fields/MetaDescription/index.js +23 -0
  14. package/dist/fields/MetaDescription/index.js.map +1 -0
  15. package/dist/fields/MetaImage/MetaImageComponent.d.ts +8 -0
  16. package/dist/fields/MetaImage/MetaImageComponent.d.ts.map +1 -0
  17. package/dist/fields/MetaImage/MetaImageComponent.js +140 -0
  18. package/dist/fields/MetaImage/MetaImageComponent.js.map +1 -0
  19. package/dist/fields/MetaImage/index.d.ts +13 -0
  20. package/dist/fields/MetaImage/index.d.ts.map +1 -0
  21. package/dist/fields/MetaImage/index.js +26 -0
  22. package/dist/fields/MetaImage/index.js.map +1 -0
  23. package/dist/fields/MetaTitle/MetaTitleComponent.d.ts +9 -0
  24. package/dist/fields/MetaTitle/MetaTitleComponent.d.ts.map +1 -0
  25. package/dist/fields/MetaTitle/MetaTitleComponent.js +138 -0
  26. package/dist/fields/MetaTitle/MetaTitleComponent.js.map +1 -0
  27. package/dist/fields/MetaTitle/index.d.ts +12 -0
  28. package/dist/fields/MetaTitle/index.d.ts.map +1 -0
  29. package/dist/fields/MetaTitle/index.js +23 -0
  30. package/dist/fields/MetaTitle/index.js.map +1 -0
  31. package/dist/fields/Overview/OverviewComponent.d.ts +10 -0
  32. package/dist/fields/Overview/OverviewComponent.d.ts.map +1 -0
  33. package/dist/{ui/Overview.js → fields/Overview/OverviewComponent.js} +18 -12
  34. package/dist/fields/Overview/OverviewComponent.js.map +1 -0
  35. package/dist/fields/Overview/index.d.ts +26 -0
  36. package/dist/fields/Overview/index.d.ts.map +1 -0
  37. package/dist/fields/Overview/index.js +25 -0
  38. package/dist/fields/Overview/index.js.map +1 -0
  39. package/dist/fields/Preview/PreviewComponent.d.ts +10 -0
  40. package/dist/fields/Preview/PreviewComponent.d.ts.map +1 -0
  41. package/dist/fields/Preview/PreviewComponent.js +101 -0
  42. package/dist/fields/Preview/PreviewComponent.js.map +1 -0
  43. package/dist/fields/Preview/index.d.ts +24 -0
  44. package/dist/fields/Preview/index.d.ts.map +1 -0
  45. package/dist/fields/Preview/index.js +25 -0
  46. package/dist/fields/Preview/index.js.map +1 -0
  47. package/dist/fields/index.scss +1 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +41 -41
  51. package/dist/index.js.map +1 -1
  52. package/dist/translations/index.d.ts +25 -0
  53. package/dist/translations/index.d.ts.map +1 -1
  54. package/dist/translations/index.js +22 -0
  55. package/dist/translations/index.js.map +1 -1
  56. package/dist/translations/ru.json +22 -0
  57. package/dist/types.d.ts +10 -10
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/types.js.map +1 -1
  60. package/dist/ui/LengthIndicator.d.ts.map +1 -1
  61. package/dist/ui/LengthIndicator.js +62 -41
  62. package/dist/ui/LengthIndicator.js.map +1 -1
  63. package/dist/ui/Pill.js +7 -3
  64. package/dist/ui/Pill.js.map +1 -1
  65. package/package.json +30 -19
  66. package/dist/fields/MetaDescription.d.ts +0 -9
  67. package/dist/fields/MetaDescription.d.ts.map +0 -1
  68. package/dist/fields/MetaDescription.js +0 -116
  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 +0 -120
  73. package/dist/fields/MetaImage.js.map +0 -1
  74. package/dist/fields/MetaTitle.d.ts +0 -9
  75. package/dist/fields/MetaTitle.d.ts.map +0 -1
  76. package/dist/fields/MetaTitle.js +0 -117
  77. package/dist/fields/MetaTitle.js.map +0 -1
  78. package/dist/ui/Overview.d.ts +0 -3
  79. package/dist/ui/Overview.d.ts.map +0 -1
  80. package/dist/ui/Overview.js.map +0 -1
  81. package/dist/ui/Preview.d.ts +0 -8
  82. package/dist/ui/Preview.d.ts.map +0 -1
  83. package/dist/ui/Preview.js +0 -79
  84. 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 { 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,9 @@
1
+ import type { FormFieldBase } from '@payloadcms/ui';
2
+ import React from 'react';
3
+ type MetaDescriptionProps = {
4
+ hasGenerateDescriptionFn: boolean;
5
+ path: string;
6
+ } & FormFieldBase;
7
+ export declare const MetaDescriptionComponent: React.FC<MetaDescriptionProps>;
8
+ export {};
9
+ //# sourceMappingURL=MetaDescriptionComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MetaDescriptionComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,aAAa,EAAW,MAAM,gBAAgB,CAAA;AAYvE,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,CAoHnE,CAAA"}
@@ -0,0 +1,136 @@
1
+ 'use client';
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';
4
+ import React, { useCallback } from 'react';
5
+ import { defaults } from '../../defaults.js';
6
+ import { LengthIndicator } from '../../ui/LengthIndicator.js';
7
+ const { maxLength, minLength } = defaults.description;
8
+ export const MetaDescriptionComponent = (props)=>{
9
+ const { CustomLabel, hasGenerateDescriptionFn, label, labelProps, required } = props;
10
+ const { path: pathFromContext } = useFieldProps();
11
+ const { t } = useTranslation();
12
+ const locale = useLocale();
13
+ const { getData } = useForm();
14
+ const docInfo = useDocumentInfo();
15
+ const field = useField({
16
+ path: pathFromContext
17
+ });
18
+ const { errorMessage, setValue, showError, value } = field;
19
+ const regenerateDescription = useCallback(async ()=>{
20
+ if (!hasGenerateDescriptionFn) return;
21
+ const genDescriptionResponse = await fetch('/api/plugin-seo/generate-description', {
22
+ body: JSON.stringify({
23
+ ...docInfo,
24
+ doc: {
25
+ ...getData()
26
+ },
27
+ locale: typeof locale === 'object' ? locale?.code : locale
28
+ }),
29
+ credentials: 'include',
30
+ headers: {
31
+ 'Content-Type': 'application/json'
32
+ },
33
+ method: 'POST'
34
+ });
35
+ const { result: generatedDescription } = await genDescriptionResponse.json();
36
+ setValue(generatedDescription || '');
37
+ }, [
38
+ hasGenerateDescriptionFn,
39
+ docInfo,
40
+ getData,
41
+ locale,
42
+ setValue
43
+ ]);
44
+ return /*#__PURE__*/ _jsxs("div", {
45
+ style: {
46
+ marginBottom: '20px'
47
+ },
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
+ });
134
+ };
135
+
136
+ //# sourceMappingURL=MetaDescriptionComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.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\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={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","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;;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,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,CAACS,0BAA0B;QAE/B,MAAMgB,yBAAyB,MAAMC,MAAM,wCAAwC;YACjFC,MAAMC,KAAKC,SAAS,CAAC;gBACnB,GAAGX,OAAO;gBACVY,KAAK;oBAAE,GAAGb,SAAS;gBAAC;gBACpBD,QAAQ,OAAOA,WAAW,WAAWA,QAAQe,OAAOf;YACtD;YACAgB,aAAa;YACbC,SAAS;gBACP,gBAAgB;YAClB;YACAC,QAAQ;QACV;QAEA,MAAM,EAAEC,QAAQC,oBAAoB,EAAE,GAAG,MAAMX,uBAAuBY,IAAI;QAE1EhB,SAASe,wBAAwB;IACnC,GAAG;QAAC3B;QAA0BS;QAASD;QAASD;QAAQK;KAAS;IAEjE,qBACE,MAACiB;QACCC,OAAO;YACLC,cAAc;QAChB;;0BAEA,MAACF;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;;kCAEA,MAACH;wBAAII,WAAU;;0CACb,KAACnD;gCAAWiB,aAAaA;gCAAaE,OAAOA;gCAAQ,GAAIC,cAAc,CAAC,CAAC;;4BACxEF,0CACC,MAACV,MAAM4C,QAAQ;;oCAAC;kDAEd,KAACC;wCACCC,SAASrB;wCACTe,OAAO;4CACLO,YAAY;4CACZC,iBAAiB;4CACjBC,QAAQ;4CACRC,OAAO;4CACPC,QAAQ;4CACRC,SAAS;4CACTC,gBAAgB;wCAClB;wCACAC,MAAK;kDAEJtC,EAAE;;;;;;kCAKX,MAACuB;wBACCC,OAAO;4BACLU,OAAO;wBACT;;4BAEClC,EAAE,mCAAmC;gCAAEZ;gCAAWC;4BAAU;0CAC7D,KAACkD;gCACCC,MAAK;gCACLC,KAAI;gCACJC,QAAO;0CAEN1C,EAAE;;;;;;0BAIT,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"}
@@ -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;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"}
@@ -0,0 +1,23 @@
1
+ import { withMergedProps } from '@payloadcms/ui/shared';
2
+ import { MetaDescriptionComponent } from './MetaDescriptionComponent.js';
3
+ export const MetaDescriptionField = ({ hasGenerateFn = false, overrides })=>{
4
+ return {
5
+ name: 'description',
6
+ type: 'textarea',
7
+ admin: {
8
+ components: {
9
+ Field: withMergedProps({
10
+ Component: MetaDescriptionComponent,
11
+ sanitizeServerOnlyProps: true,
12
+ toMergeIntoProps: {
13
+ hasGenerateDescriptionFn: hasGenerateFn
14
+ }
15
+ })
16
+ }
17
+ },
18
+ localized: true,
19
+ ...overrides ?? {}
20
+ };
21
+ };
22
+
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,8 @@
1
+ import type { UploadInputProps } from '@payloadcms/ui';
2
+ import React from 'react';
3
+ type MetaImageProps = {
4
+ hasGenerateImageFn: boolean;
5
+ } & UploadInputProps;
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":"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,CAqIvD,CAAA"}
@@ -0,0 +1,140 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldLabel, UploadInput, useConfig, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
4
+ import React, { useCallback } from 'react';
5
+ import { Pill } from '../../ui/Pill.js';
6
+ export const MetaImageComponent = (props)=>{
7
+ const { CustomLabel, hasGenerateImageFn, label, labelProps, relationTo, required } = props || {};
8
+ const { path: pathFromContext } = useFieldProps();
9
+ const field = useField({
10
+ ...props,
11
+ path: pathFromContext
12
+ });
13
+ const { t } = useTranslation();
14
+ const locale = useLocale();
15
+ const { getData } = useForm();
16
+ const docInfo = useDocumentInfo();
17
+ const { errorMessage, setValue, showError, value } = field;
18
+ const regenerateImage = useCallback(async ()=>{
19
+ if (!hasGenerateImageFn) return;
20
+ const genImageResponse = await fetch('/api/plugin-seo/generate-image', {
21
+ body: JSON.stringify({
22
+ ...docInfo,
23
+ doc: {
24
+ ...getData()
25
+ },
26
+ locale: typeof locale === 'object' ? locale?.code : locale
27
+ }),
28
+ credentials: 'include',
29
+ headers: {
30
+ 'Content-Type': 'application/json'
31
+ },
32
+ method: 'POST'
33
+ });
34
+ const { result: generatedImage } = await genImageResponse.json();
35
+ setValue(generatedImage || '');
36
+ }, [
37
+ hasGenerateImageFn,
38
+ docInfo,
39
+ getData,
40
+ locale,
41
+ setValue
42
+ ]);
43
+ const hasImage = Boolean(value);
44
+ const config = useConfig();
45
+ const { collections, routes: { api } = {}, serverURL } = config;
46
+ const collection = collections?.find((coll)=>coll.slug === relationTo) || undefined;
47
+ return /*#__PURE__*/ _jsxs("div", {
48
+ style: {
49
+ marginBottom: '20px'
50
+ },
51
+ children: [
52
+ /*#__PURE__*/ _jsxs("div", {
53
+ style: {
54
+ marginBottom: '5px',
55
+ position: 'relative'
56
+ },
57
+ children: [
58
+ /*#__PURE__*/ _jsxs("div", {
59
+ className: "plugin-seo__field",
60
+ children: [
61
+ /*#__PURE__*/ _jsx(FieldLabel, {
62
+ CustomLabel: CustomLabel,
63
+ label: label,
64
+ ...labelProps || {}
65
+ }),
66
+ hasGenerateImageFn && /*#__PURE__*/ _jsxs(React.Fragment, {
67
+ children: [
68
+ "  —  ",
69
+ /*#__PURE__*/ _jsx("button", {
70
+ onClick: regenerateImage,
71
+ style: {
72
+ background: 'none',
73
+ backgroundColor: 'transparent',
74
+ border: 'none',
75
+ color: 'currentcolor',
76
+ cursor: 'pointer',
77
+ padding: 0,
78
+ textDecoration: 'underline'
79
+ },
80
+ type: "button",
81
+ children: t('plugin-seo:autoGenerate')
82
+ })
83
+ ]
84
+ })
85
+ ]
86
+ }),
87
+ hasGenerateImageFn && /*#__PURE__*/ _jsx("div", {
88
+ style: {
89
+ color: '#9A9A9A'
90
+ },
91
+ children: t('plugin-seo:imageAutoGenerationTip')
92
+ })
93
+ ]
94
+ }),
95
+ /*#__PURE__*/ _jsx("div", {
96
+ style: {
97
+ marginBottom: '10px',
98
+ position: 'relative'
99
+ },
100
+ children: /*#__PURE__*/ _jsx(UploadInput, {
101
+ CustomError: errorMessage,
102
+ api: api,
103
+ collection: collection,
104
+ filterOptions: field.filterOptions,
105
+ label: undefined,
106
+ onChange: (incomingImage)=>{
107
+ if (incomingImage !== null) {
108
+ const { id: incomingID } = incomingImage;
109
+ setValue(incomingID);
110
+ } else {
111
+ setValue(null);
112
+ }
113
+ },
114
+ relationTo: relationTo,
115
+ required: required,
116
+ serverURL: serverURL,
117
+ showError: showError,
118
+ style: {
119
+ marginBottom: 0
120
+ },
121
+ value: value
122
+ })
123
+ }),
124
+ /*#__PURE__*/ _jsx("div", {
125
+ style: {
126
+ alignItems: 'center',
127
+ display: 'flex',
128
+ width: '100%'
129
+ },
130
+ children: /*#__PURE__*/ _jsx(Pill, {
131
+ backgroundColor: hasImage ? 'green' : 'red',
132
+ color: "white",
133
+ label: hasImage ? t('plugin-seo:good') : t('plugin-seo:noImage')
134
+ })
135
+ })
136
+ ]
137
+ });
138
+ };
139
+
140
+ //# sourceMappingURL=MetaImageComponent.js.map
@@ -0,0 +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={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","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":"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"}
@@ -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;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"}
@@ -0,0 +1,26 @@
1
+ import { withMergedProps } from '@payloadcms/ui/shared';
2
+ import { MetaImageComponent } from './MetaImageComponent.js';
3
+ export const MetaImageField = ({ hasGenerateFn = false, overrides, relationTo })=>{
4
+ return {
5
+ name: 'image',
6
+ type: 'upload',
7
+ admin: {
8
+ components: {
9
+ Field: withMergedProps({
10
+ Component: MetaImageComponent,
11
+ sanitizeServerOnlyProps: true,
12
+ toMergeIntoProps: {
13
+ hasGenerateImageFn: hasGenerateFn
14
+ }
15
+ })
16
+ },
17
+ description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.'
18
+ },
19
+ label: 'Meta Image',
20
+ localized: true,
21
+ relationTo,
22
+ ...overrides ?? {}
23
+ };
24
+ };
25
+
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,9 @@
1
+ import type { FormFieldBase } from '@payloadcms/ui';
2
+ import React from 'react';
3
+ import '../index.scss';
4
+ type MetaTitleProps = {
5
+ hasGenerateTitleFn: boolean;
6
+ } & FormFieldBase;
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":"AAEA,OAAO,KAAK,EAAa,aAAa,EAAW,MAAM,gBAAgB,CAAA;AAYvE,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,CAqHvD,CAAA"}
@@ -0,0 +1,138 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldLabel, TextInput, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
4
+ import React, { useCallback } from 'react';
5
+ import { defaults } from '../../defaults.js';
6
+ import { LengthIndicator } from '../../ui/LengthIndicator.js';
7
+ import '../index.scss';
8
+ const { maxLength, minLength } = defaults.title;
9
+ export const MetaTitleComponent = (props)=>{
10
+ const { CustomLabel, hasGenerateTitleFn, label, labelProps, required } = props || {};
11
+ const { path: pathFromContext } = useFieldProps();
12
+ const { t } = useTranslation();
13
+ const field = useField({
14
+ path: pathFromContext
15
+ });
16
+ const locale = useLocale();
17
+ const { getData } = useForm();
18
+ const docInfo = useDocumentInfo();
19
+ const { errorMessage, setValue, showError, value } = field;
20
+ const regenerateTitle = useCallback(async ()=>{
21
+ if (!hasGenerateTitleFn) return;
22
+ const genTitleResponse = await fetch('/api/plugin-seo/generate-title', {
23
+ body: JSON.stringify({
24
+ ...docInfo,
25
+ doc: {
26
+ ...getData()
27
+ },
28
+ locale: typeof locale === 'object' ? locale?.code : locale
29
+ }),
30
+ credentials: 'include',
31
+ headers: {
32
+ 'Content-Type': 'application/json'
33
+ },
34
+ method: 'POST'
35
+ });
36
+ const { result: generatedTitle } = await genTitleResponse.json();
37
+ setValue(generatedTitle || '');
38
+ }, [
39
+ hasGenerateTitleFn,
40
+ docInfo,
41
+ getData,
42
+ locale,
43
+ setValue
44
+ ]);
45
+ return /*#__PURE__*/ _jsxs("div", {
46
+ style: {
47
+ marginBottom: '20px'
48
+ },
49
+ children: [
50
+ /*#__PURE__*/ _jsxs("div", {
51
+ style: {
52
+ marginBottom: '5px',
53
+ position: 'relative'
54
+ },
55
+ children: [
56
+ /*#__PURE__*/ _jsxs("div", {
57
+ className: "plugin-seo__field",
58
+ children: [
59
+ /*#__PURE__*/ _jsx(FieldLabel, {
60
+ CustomLabel: CustomLabel,
61
+ label: label,
62
+ ...labelProps || {}
63
+ }),
64
+ hasGenerateTitleFn && /*#__PURE__*/ _jsxs(React.Fragment, {
65
+ children: [
66
+ "  —  ",
67
+ /*#__PURE__*/ _jsx("button", {
68
+ onClick: regenerateTitle,
69
+ style: {
70
+ background: 'none',
71
+ backgroundColor: 'transparent',
72
+ border: 'none',
73
+ color: 'currentcolor',
74
+ cursor: 'pointer',
75
+ padding: 0,
76
+ textDecoration: 'underline'
77
+ },
78
+ type: "button",
79
+ children: t('plugin-seo:autoGenerate')
80
+ })
81
+ ]
82
+ })
83
+ ]
84
+ }),
85
+ /*#__PURE__*/ _jsxs("div", {
86
+ style: {
87
+ color: '#9A9A9A'
88
+ },
89
+ children: [
90
+ t('plugin-seo:lengthTipTitle', {
91
+ maxLength,
92
+ minLength
93
+ }),
94
+ /*#__PURE__*/ _jsx("a", {
95
+ href: "https://developers.google.com/search/docs/advanced/appearance/title-link#page-titles",
96
+ rel: "noopener noreferrer",
97
+ target: "_blank",
98
+ children: t('plugin-seo:bestPractices')
99
+ }),
100
+ "."
101
+ ]
102
+ })
103
+ ]
104
+ }),
105
+ /*#__PURE__*/ _jsx("div", {
106
+ style: {
107
+ marginBottom: '10px',
108
+ position: 'relative'
109
+ },
110
+ children: /*#__PURE__*/ _jsx(TextInput, {
111
+ CustomError: errorMessage,
112
+ onChange: setValue,
113
+ path: pathFromContext,
114
+ required: required,
115
+ showError: showError,
116
+ style: {
117
+ marginBottom: 0
118
+ },
119
+ value: value
120
+ })
121
+ }),
122
+ /*#__PURE__*/ _jsx("div", {
123
+ style: {
124
+ alignItems: 'center',
125
+ display: 'flex',
126
+ width: '100%'
127
+ },
128
+ children: /*#__PURE__*/ _jsx(LengthIndicator, {
129
+ maxLength: maxLength,
130
+ minLength: minLength,
131
+ text: value
132
+ })
133
+ })
134
+ ]
135
+ });
136
+ };
137
+
138
+ //# sourceMappingURL=MetaTitleComponent.js.map