@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.
- package/dist/defaults.js.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/MetaDescription.d.ts +1 -1
- package/dist/fields/MetaDescription.d.ts.map +1 -1
- package/dist/fields/MetaDescription.js +94 -74
- package/dist/fields/MetaDescription.js.map +1 -1
- package/dist/fields/MetaImage.d.ts +1 -1
- package/dist/fields/MetaImage.d.ts.map +1 -1
- package/dist/fields/MetaImage.js +95 -79
- package/dist/fields/MetaImage.js.map +1 -1
- package/dist/fields/MetaTitle.d.ts +1 -1
- package/dist/fields/MetaTitle.d.ts.map +1 -1
- package/dist/fields/MetaTitle.js +95 -74
- package/dist/fields/MetaTitle.js.map +1 -1
- package/dist/fields/index.scss +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -14
- package/dist/index.js.map +1 -1
- package/dist/translations/index.d.ts +25 -0
- package/dist/translations/index.d.ts.map +1 -1
- package/dist/translations/index.js +22 -0
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/ru.json +22 -0
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/LengthIndicator.d.ts.map +1 -1
- package/dist/ui/LengthIndicator.js +62 -41
- package/dist/ui/LengthIndicator.js.map +1 -1
- package/dist/ui/Overview.d.ts.map +1 -1
- package/dist/ui/Overview.js +11 -8
- package/dist/ui/Overview.js.map +1 -1
- package/dist/ui/Pill.js +7 -3
- package/dist/ui/Pill.js.map +1 -1
- package/dist/ui/Preview.d.ts +1 -1
- package/dist/ui/Preview.d.ts.map +1 -1
- package/dist/ui/Preview.js +60 -40
- package/dist/ui/Preview.js.map +1 -1
- package/package.json +24 -18
package/dist/defaults.js.map
CHANGED
|
@@ -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"],"
|
|
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":[],"
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaDescription.d.ts","sourceRoot":"","sources":["../../src/fields/MetaDescription.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
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 {
|
|
3
|
-
import { FieldLabel } from '@payloadcms/ui
|
|
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
|
|
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
|
-
...
|
|
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
|
-
|
|
42
|
+
setValue
|
|
49
43
|
]);
|
|
50
|
-
return /*#__PURE__*/
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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 {
|
|
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 — \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,SAA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Te,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;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaImage.d.ts","sourceRoot":"","sources":["../../src/fields/MetaImage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
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"}
|
package/dist/fields/MetaImage.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import { FieldLabel } from '@payloadcms/ui
|
|
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
|
|
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
|
-
...
|
|
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
|
-
|
|
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__*/
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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 {
|
|
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 — \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,kBAAkBnB,YAAY;QAClC,IAAI,CAACK,oBAAoB;QAEzB,MAAMe,mBAAmB,MAAMC,MAAM,kCAAkC;YACrEC,MAAMC,KAAKC,SAAS,CAAC;gBACnB,GAAGV,OAAO;gBACVW,KAAK;oBAAE,GAAGZ,SAAS;gBAAC;gBACpBD,QAAQ,OAAOA,WAAW,WAAWA,QAAQc,OAAOd;YACtD;YACAe,aAAa;YACbC,SAAS;gBACP,gBAAgB;YAClB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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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaTitle.d.ts","sourceRoot":"","sources":["../../src/fields/MetaTitle.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
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"}
|