@payloadcms/plugin-seo 3.0.0-canary.95fcd13 → 3.0.0-canary.96477cf
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/exports/client.d.ts +6 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +7 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts +3 -4
- package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts.map +1 -1
- package/dist/fields/MetaDescription/MetaDescriptionComponent.js +38 -12
- package/dist/fields/MetaDescription/MetaDescriptionComponent.js.map +1 -1
- package/dist/fields/MetaDescription/index.d.ts.map +1 -1
- package/dist/fields/MetaDescription/index.js +5 -8
- package/dist/fields/MetaDescription/index.js.map +1 -1
- package/dist/fields/MetaImage/MetaImageComponent.d.ts +3 -3
- package/dist/fields/MetaImage/MetaImageComponent.d.ts.map +1 -1
- package/dist/fields/MetaImage/MetaImageComponent.js +45 -17
- package/dist/fields/MetaImage/MetaImageComponent.js.map +1 -1
- package/dist/fields/MetaImage/index.d.ts.map +1 -1
- package/dist/fields/MetaImage/index.js +5 -8
- package/dist/fields/MetaImage/index.js.map +1 -1
- package/dist/fields/MetaTitle/MetaTitleComponent.d.ts +3 -3
- package/dist/fields/MetaTitle/MetaTitleComponent.d.ts.map +1 -1
- package/dist/fields/MetaTitle/MetaTitleComponent.js +38 -12
- package/dist/fields/MetaTitle/MetaTitleComponent.js.map +1 -1
- package/dist/fields/MetaTitle/index.d.ts.map +1 -1
- package/dist/fields/MetaTitle/index.js +5 -8
- package/dist/fields/MetaTitle/index.js.map +1 -1
- package/dist/fields/Overview/OverviewComponent.d.ts.map +1 -1
- package/dist/fields/Overview/OverviewComponent.js +6 -3
- package/dist/fields/Overview/OverviewComponent.js.map +1 -1
- package/dist/fields/Overview/index.d.ts.map +1 -1
- package/dist/fields/Overview/index.js +5 -8
- package/dist/fields/Overview/index.js.map +1 -1
- package/dist/fields/Preview/PreviewComponent.d.ts +3 -3
- package/dist/fields/Preview/PreviewComponent.d.ts.map +1 -1
- package/dist/fields/Preview/PreviewComponent.js +23 -9
- package/dist/fields/Preview/PreviewComponent.js.map +1 -1
- package/dist/fields/Preview/index.d.ts.map +1 -1
- package/dist/fields/Preview/index.js +5 -8
- package/dist/fields/Preview/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -99
- package/dist/index.js.map +1 -1
- package/dist/translations/en.d.ts +3 -0
- package/dist/translations/en.d.ts.map +1 -0
- package/dist/translations/en.js +25 -0
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/es.d.ts +3 -0
- package/dist/translations/es.d.ts.map +1 -0
- package/dist/translations/es.js +25 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fa.d.ts +3 -0
- package/dist/translations/fa.d.ts.map +1 -0
- package/dist/translations/fa.js +25 -0
- package/dist/translations/fa.js.map +1 -0
- package/dist/translations/fr.d.ts +3 -0
- package/dist/translations/fr.d.ts.map +1 -0
- package/dist/translations/fr.js +25 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/index.d.ts +11 -178
- package/dist/translations/index.d.ts.map +1 -1
- package/dist/translations/index.js +18 -176
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/it.d.ts +3 -0
- package/dist/translations/it.d.ts.map +1 -0
- package/dist/translations/it.js +25 -0
- package/dist/translations/it.js.map +1 -0
- package/dist/translations/nb.d.ts +3 -0
- package/dist/translations/nb.d.ts.map +1 -0
- package/dist/translations/nb.js +25 -0
- package/dist/translations/nb.js.map +1 -0
- package/dist/translations/pl.d.ts +3 -0
- package/dist/translations/pl.d.ts.map +1 -0
- package/dist/translations/pl.js +25 -0
- package/dist/translations/pl.js.map +1 -0
- package/dist/translations/ru.d.ts +3 -0
- package/dist/translations/ru.d.ts.map +1 -0
- package/dist/translations/ru.js +25 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/translation-schema.json +5 -1
- package/dist/translations/uk.d.ts +3 -0
- package/dist/translations/uk.d.ts.map +1 -0
- package/dist/translations/uk.js +25 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/vi.d.ts +3 -0
- package/dist/translations/vi.d.ts.map +1 -0
- package/dist/translations/vi.js +25 -0
- package/dist/translations/vi.js.map +1 -0
- package/dist/types.d.ts +18 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/LengthIndicator.js +1 -1
- package/dist/ui/LengthIndicator.js.map +1 -1
- package/package.json +22 -17
- package/dist/translations/en.json +0 -22
- package/dist/translations/es.json +0 -22
- package/dist/translations/fa.json +0 -22
- package/dist/translations/fr.json +0 -22
- package/dist/translations/pl.json +0 -22
- package/dist/translations/ru.json +0 -22
- package/dist/translations/uk.json +0 -22
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js';
|
|
2
|
+
export { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js';
|
|
3
|
+
export { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js';
|
|
4
|
+
export { OverviewComponent } from '../fields/Overview/OverviewComponent.js';
|
|
5
|
+
export { PreviewComponent } from '../fields/Preview/PreviewComponent.js';
|
|
6
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAA;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js';
|
|
2
|
+
export { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js';
|
|
3
|
+
export { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js';
|
|
4
|
+
export { OverviewComponent } from '../fields/Overview/OverviewComponent.js';
|
|
5
|
+
export { PreviewComponent } from '../fields/Preview/PreviewComponent.js';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js'\nexport { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js'\nexport { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js'\nexport { OverviewComponent } from '../fields/Overview/OverviewComponent.js'\nexport { PreviewComponent } from '../fields/Preview/PreviewComponent.js'\n"],"names":["MetaDescriptionComponent","MetaImageComponent","MetaTitleComponent","OverviewComponent","PreviewComponent"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,wDAAuD;AAChG,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,iBAAiB,QAAQ,0CAAyC;AAC3E,SAASC,gBAAgB,QAAQ,wCAAuC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TextareaFieldClientProps } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
type MetaDescriptionProps = {
|
|
4
|
-
hasGenerateDescriptionFn: boolean;
|
|
5
|
-
|
|
6
|
-
} & FormFieldBase;
|
|
4
|
+
readonly hasGenerateDescriptionFn: boolean;
|
|
5
|
+
} & TextareaFieldClientProps;
|
|
7
6
|
export declare const MetaDescriptionComponent: React.FC<MetaDescriptionProps>;
|
|
8
7
|
export {};
|
|
9
8
|
//# sourceMappingURL=MetaDescriptionComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaDescriptionComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"MetaDescriptionComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAavD,OAAO,KAAsB,MAAM,OAAO,CAAA;AAU1C,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAA;CAC3C,GAAG,wBAAwB,CAAA;AAE5B,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAgLnE,CAAA"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
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';
|
|
3
|
+
import { FieldLabel, TextareaInput, useConfig, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
|
|
4
4
|
import React, { useCallback } from 'react';
|
|
5
5
|
import { defaults } from '../../defaults.js';
|
|
6
6
|
import { LengthIndicator } from '../../ui/LengthIndicator.js';
|
|
7
7
|
const { maxLength, minLength } = defaults.description;
|
|
8
8
|
export const MetaDescriptionComponent = (props)=>{
|
|
9
|
-
const {
|
|
9
|
+
const { field: { admin: { components: { Label } }, label, required }, hasGenerateDescriptionFn, labelProps } = props;
|
|
10
10
|
const { path: pathFromContext } = useFieldProps();
|
|
11
|
+
const { config: { routes: { api }, serverURL } } = useConfig();
|
|
11
12
|
const { t } = useTranslation();
|
|
12
13
|
const locale = useLocale();
|
|
13
14
|
const { getData } = useForm();
|
|
@@ -17,14 +18,23 @@ export const MetaDescriptionComponent = (props)=>{
|
|
|
17
18
|
});
|
|
18
19
|
const { errorMessage, setValue, showError, value } = field;
|
|
19
20
|
const regenerateDescription = useCallback(async ()=>{
|
|
20
|
-
if (!hasGenerateDescriptionFn)
|
|
21
|
-
|
|
21
|
+
if (!hasGenerateDescriptionFn) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const endpoint = `${serverURL}${api}/plugin-seo/generate-description`;
|
|
25
|
+
const genDescriptionResponse = await fetch(endpoint, {
|
|
22
26
|
body: JSON.stringify({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
id: docInfo.id,
|
|
28
|
+
collectionSlug: docInfo.collectionSlug,
|
|
29
|
+
doc: getData(),
|
|
30
|
+
docPermissions: docInfo.docPermissions,
|
|
31
|
+
globalSlug: docInfo.globalSlug,
|
|
32
|
+
hasPublishPermission: docInfo.hasPublishPermission,
|
|
33
|
+
hasSavePermission: docInfo.hasSavePermission,
|
|
34
|
+
initialData: docInfo.initialData,
|
|
35
|
+
initialState: docInfo.initialState,
|
|
36
|
+
locale: typeof locale === 'object' ? locale?.code : locale,
|
|
37
|
+
title: docInfo.title
|
|
28
38
|
}),
|
|
29
39
|
credentials: 'include',
|
|
30
40
|
headers: {
|
|
@@ -36,7 +46,17 @@ export const MetaDescriptionComponent = (props)=>{
|
|
|
36
46
|
setValue(generatedDescription || '');
|
|
37
47
|
}, [
|
|
38
48
|
hasGenerateDescriptionFn,
|
|
39
|
-
|
|
49
|
+
serverURL,
|
|
50
|
+
api,
|
|
51
|
+
docInfo.id,
|
|
52
|
+
docInfo.collectionSlug,
|
|
53
|
+
docInfo.docPermissions,
|
|
54
|
+
docInfo.globalSlug,
|
|
55
|
+
docInfo.hasPublishPermission,
|
|
56
|
+
docInfo.hasSavePermission,
|
|
57
|
+
docInfo.initialData,
|
|
58
|
+
docInfo.initialState,
|
|
59
|
+
docInfo.title,
|
|
40
60
|
getData,
|
|
41
61
|
locale,
|
|
42
62
|
setValue
|
|
@@ -56,8 +76,10 @@ export const MetaDescriptionComponent = (props)=>{
|
|
|
56
76
|
className: "plugin-seo__field",
|
|
57
77
|
children: [
|
|
58
78
|
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
59
|
-
|
|
79
|
+
field: null,
|
|
80
|
+
Label: Label,
|
|
60
81
|
label: label,
|
|
82
|
+
required: required,
|
|
61
83
|
...labelProps || {}
|
|
62
84
|
}),
|
|
63
85
|
hasGenerateDescriptionFn && /*#__PURE__*/ _jsxs(React.Fragment, {
|
|
@@ -108,7 +130,11 @@ export const MetaDescriptionComponent = (props)=>{
|
|
|
108
130
|
position: 'relative'
|
|
109
131
|
},
|
|
110
132
|
children: /*#__PURE__*/ _jsx(TextareaInput, {
|
|
111
|
-
|
|
133
|
+
Error: {
|
|
134
|
+
type: 'client',
|
|
135
|
+
Component: null,
|
|
136
|
+
RenderedComponent: errorMessage
|
|
137
|
+
},
|
|
112
138
|
onChange: setValue,
|
|
113
139
|
path: pathFromContext,
|
|
114
140
|
required: required,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { TextareaFieldClientProps } from 'payload'\n\nimport {\n FieldLabel,\n TextareaInput,\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 { GenerateDescription } from '../../types.js'\n\nimport { defaults } from '../../defaults.js'\nimport { LengthIndicator } from '../../ui/LengthIndicator.js'\n\nconst { maxLength, minLength } = defaults.description\n\ntype MetaDescriptionProps = {\n readonly hasGenerateDescriptionFn: boolean\n} & TextareaFieldClientProps\n\nexport const MetaDescriptionComponent: React.FC<MetaDescriptionProps> = (props) => {\n const {\n field: {\n admin: {\n components: { Label },\n },\n label,\n required,\n },\n hasGenerateDescriptionFn,\n labelProps,\n } = props\n const { path: pathFromContext } = useFieldProps()\n\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const field: FieldType<string> = useField({\n path: pathFromContext,\n } as Options)\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateDescription = useCallback(async () => {\n if (!hasGenerateDescriptionFn) {\n return\n }\n\n const endpoint = `${serverURL}${api}/plugin-seo/generate-description`\n\n const genDescriptionResponse = await fetch(endpoint, {\n body: JSON.stringify({\n id: docInfo.id,\n collectionSlug: docInfo.collectionSlug,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\n globalSlug: docInfo.globalSlug,\n hasPublishPermission: docInfo.hasPublishPermission,\n hasSavePermission: docInfo.hasSavePermission,\n initialData: docInfo.initialData,\n initialState: docInfo.initialState,\n locale: typeof locale === 'object' ? locale?.code : locale,\n title: docInfo.title,\n } satisfies Omit<\n Parameters<GenerateDescription>[0],\n 'collectionConfig' | 'globalConfig' | 'req'\n >),\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 }, [\n hasGenerateDescriptionFn,\n serverURL,\n api,\n docInfo.id,\n docInfo.collectionSlug,\n docInfo.docPermissions,\n docInfo.globalSlug,\n docInfo.hasPublishPermission,\n docInfo.hasSavePermission,\n docInfo.initialData,\n docInfo.initialState,\n docInfo.title,\n getData,\n locale,\n setValue,\n ])\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\n field={null}\n Label={Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n {hasGenerateDescriptionFn && (\n <React.Fragment>\n — \n <button\n onClick={() => {\n void regenerateDescription()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:lengthTipDescription', { maxLength, minLength })}\n <a\n href=\"https://developers.google.com/search/docs/advanced/appearance/snippet#meta-descriptions\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {t('plugin-seo:bestPractices')}\n </a>\n </div>\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <TextareaInput\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n 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","useConfig","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","description","MetaDescriptionComponent","props","field","admin","components","Label","label","required","hasGenerateDescriptionFn","labelProps","path","pathFromContext","config","routes","api","serverURL","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateDescription","endpoint","genDescriptionResponse","fetch","body","JSON","stringify","id","collectionSlug","doc","docPermissions","globalSlug","hasPublishPermission","hasSavePermission","initialData","initialState","code","title","credentials","headers","method","result","generatedDescription","json","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","a","href","rel","target","Error","Component","RenderedComponent","onChange","alignItems","display","width","text"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CACnC;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,aAAa,CAAA;AAExF,eAAO,MAAM,oBAAoB,EAAE,aAiBlC,CAAA"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { withMergedProps } from '@payloadcms/ui/shared';
|
|
2
|
-
import { MetaDescriptionComponent } from './MetaDescriptionComponent.js';
|
|
3
1
|
export const MetaDescriptionField = ({ hasGenerateFn = false, overrides })=>{
|
|
4
2
|
return {
|
|
5
3
|
name: 'description',
|
|
6
4
|
type: 'textarea',
|
|
7
5
|
admin: {
|
|
8
6
|
components: {
|
|
9
|
-
Field:
|
|
10
|
-
|
|
11
|
-
sanitizeServerOnlyProps: true,
|
|
12
|
-
toMergeIntoProps: {
|
|
7
|
+
Field: {
|
|
8
|
+
clientProps: {
|
|
13
9
|
hasGenerateDescriptionFn: hasGenerateFn
|
|
14
|
-
}
|
|
15
|
-
|
|
10
|
+
},
|
|
11
|
+
path: '@payloadcms/plugin-seo/client#MetaDescriptionComponent'
|
|
12
|
+
}
|
|
16
13
|
}
|
|
17
14
|
},
|
|
18
15
|
localized: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/MetaDescription/index.ts"],"sourcesContent":["import type { TextareaField } from 'payload'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaDescription/index.ts"],"sourcesContent":["import type { TextareaField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<TextareaField>\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextareaField\n\nexport const MetaDescriptionField: FieldFunction = ({ hasGenerateFn = false, overrides }) => {\n return {\n name: 'description',\n type: 'textarea',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateDescriptionFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaDescriptionComponent',\n },\n },\n },\n localized: true,\n ...((overrides as unknown as TextareaField) ?? {}),\n }\n}\n"],"names":["MetaDescriptionField","hasGenerateFn","overrides","name","type","admin","components","Field","clientProps","hasGenerateDescriptionFn","path","localized"],"mappings":"AAYA,OAAO,MAAMA,uBAAsC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAE;IACtF,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,0BAA0BR;oBAC5B;oBACAS,MAAM;gBACR;YACF;QACF;QACAC,WAAW;QACX,GAAI,AAACT,aAA0C,CAAC,CAAC;IACnD;AACF,EAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UploadFieldClientProps } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
type MetaImageProps = {
|
|
4
|
-
hasGenerateImageFn: boolean;
|
|
5
|
-
} &
|
|
4
|
+
readonly hasGenerateImageFn: boolean;
|
|
5
|
+
} & UploadFieldClientProps;
|
|
6
6
|
export declare const MetaImageComponent: React.FC<MetaImageProps>;
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=MetaImageComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaImageComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MetaImageComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAarD,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;CACrC,GAAG,sBAAsB,CAAA;AAE1B,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAgMvD,CAAA"}
|
|
@@ -4,8 +4,9 @@ import { FieldLabel, UploadInput, useConfig, useDocumentInfo, useField, useField
|
|
|
4
4
|
import React, { useCallback } from 'react';
|
|
5
5
|
import { Pill } from '../../ui/Pill.js';
|
|
6
6
|
export const MetaImageComponent = (props)=>{
|
|
7
|
-
const {
|
|
7
|
+
const { field: { admin: { components: { Label } }, label, relationTo, required }, hasGenerateImageFn, labelProps } = props || {};
|
|
8
8
|
const { path: pathFromContext } = useFieldProps();
|
|
9
|
+
const { config: { collections, routes: { api }, serverURL } } = useConfig();
|
|
9
10
|
const field = useField({
|
|
10
11
|
...props,
|
|
11
12
|
path: pathFromContext
|
|
@@ -16,14 +17,23 @@ export const MetaImageComponent = (props)=>{
|
|
|
16
17
|
const docInfo = useDocumentInfo();
|
|
17
18
|
const { errorMessage, setValue, showError, value } = field;
|
|
18
19
|
const regenerateImage = useCallback(async ()=>{
|
|
19
|
-
if (!hasGenerateImageFn)
|
|
20
|
-
|
|
20
|
+
if (!hasGenerateImageFn) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const endpoint = `${serverURL}${api}/plugin-seo/generate-image`;
|
|
24
|
+
const genImageResponse = await fetch(endpoint, {
|
|
21
25
|
body: JSON.stringify({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
id: docInfo.id,
|
|
27
|
+
collectionSlug: docInfo.collectionSlug,
|
|
28
|
+
doc: getData(),
|
|
29
|
+
docPermissions: docInfo.docPermissions,
|
|
30
|
+
globalSlug: docInfo.globalSlug,
|
|
31
|
+
hasPublishPermission: docInfo.hasPublishPermission,
|
|
32
|
+
hasSavePermission: docInfo.hasSavePermission,
|
|
33
|
+
initialData: docInfo.initialData,
|
|
34
|
+
initialState: docInfo.initialState,
|
|
35
|
+
locale: typeof locale === 'object' ? locale?.code : locale,
|
|
36
|
+
title: docInfo.title
|
|
27
37
|
}),
|
|
28
38
|
credentials: 'include',
|
|
29
39
|
headers: {
|
|
@@ -31,18 +41,26 @@ export const MetaImageComponent = (props)=>{
|
|
|
31
41
|
},
|
|
32
42
|
method: 'POST'
|
|
33
43
|
});
|
|
34
|
-
const
|
|
44
|
+
const generatedImage = await genImageResponse.text();
|
|
35
45
|
setValue(generatedImage || '');
|
|
36
46
|
}, [
|
|
37
47
|
hasGenerateImageFn,
|
|
38
|
-
|
|
48
|
+
serverURL,
|
|
49
|
+
api,
|
|
50
|
+
docInfo.id,
|
|
51
|
+
docInfo.collectionSlug,
|
|
52
|
+
docInfo.docPermissions,
|
|
53
|
+
docInfo.globalSlug,
|
|
54
|
+
docInfo.hasPublishPermission,
|
|
55
|
+
docInfo.hasSavePermission,
|
|
56
|
+
docInfo.initialData,
|
|
57
|
+
docInfo.initialState,
|
|
58
|
+
docInfo.title,
|
|
39
59
|
getData,
|
|
40
60
|
locale,
|
|
41
61
|
setValue
|
|
42
62
|
]);
|
|
43
63
|
const hasImage = Boolean(value);
|
|
44
|
-
const config = useConfig();
|
|
45
|
-
const { collections, routes: { api } = {}, serverURL } = config;
|
|
46
64
|
const collection = collections?.find((coll)=>coll.slug === relationTo) || undefined;
|
|
47
65
|
return /*#__PURE__*/ _jsxs("div", {
|
|
48
66
|
style: {
|
|
@@ -59,8 +77,10 @@ export const MetaImageComponent = (props)=>{
|
|
|
59
77
|
className: "plugin-seo__field",
|
|
60
78
|
children: [
|
|
61
79
|
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
62
|
-
|
|
80
|
+
field: null,
|
|
81
|
+
Label: Label,
|
|
63
82
|
label: label,
|
|
83
|
+
required: required,
|
|
64
84
|
...labelProps || {}
|
|
65
85
|
}),
|
|
66
86
|
hasGenerateImageFn && /*#__PURE__*/ _jsxs(React.Fragment, {
|
|
@@ -100,19 +120,27 @@ export const MetaImageComponent = (props)=>{
|
|
|
100
120
|
position: 'relative'
|
|
101
121
|
},
|
|
102
122
|
children: /*#__PURE__*/ _jsx(UploadInput, {
|
|
103
|
-
CustomError: errorMessage,
|
|
104
123
|
api: api,
|
|
105
124
|
collection: collection,
|
|
125
|
+
Error: {
|
|
126
|
+
type: 'client',
|
|
127
|
+
Component: null,
|
|
128
|
+
RenderedComponent: errorMessage
|
|
129
|
+
},
|
|
106
130
|
filterOptions: field.filterOptions,
|
|
107
|
-
label: undefined,
|
|
108
131
|
onChange: (incomingImage)=>{
|
|
109
132
|
if (incomingImage !== null) {
|
|
110
|
-
|
|
111
|
-
|
|
133
|
+
if (typeof incomingImage === 'object') {
|
|
134
|
+
const { id: incomingID } = incomingImage;
|
|
135
|
+
setValue(incomingID);
|
|
136
|
+
} else {
|
|
137
|
+
setValue(incomingImage);
|
|
138
|
+
}
|
|
112
139
|
} else {
|
|
113
140
|
setValue(null);
|
|
114
141
|
}
|
|
115
142
|
},
|
|
143
|
+
path: field.path,
|
|
116
144
|
relationTo: relationTo,
|
|
117
145
|
required: required,
|
|
118
146
|
serverURL: serverURL,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { UploadFieldClientProps } from 'payload'\n\nimport {\n FieldLabel,\n UploadInput,\n useConfig,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateImage } from '../../types.js'\n\nimport { Pill } from '../../ui/Pill.js'\n\ntype MetaImageProps = {\n readonly hasGenerateImageFn: boolean\n} & UploadFieldClientProps\n\nexport const MetaImageComponent: React.FC<MetaImageProps> = (props) => {\n const {\n field: {\n admin: {\n components: { Label },\n },\n label,\n relationTo,\n required,\n },\n hasGenerateImageFn,\n labelProps,\n } = props || {}\n const { path: pathFromContext } = useFieldProps()\n\n const {\n config: {\n collections,\n routes: { api },\n serverURL,\n },\n } = useConfig()\n\n const field: FieldType<string> = useField({ ...props, path: pathFromContext } as Options)\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateImage = useCallback(async () => {\n if (!hasGenerateImageFn) {\n return\n }\n\n const endpoint = `${serverURL}${api}/plugin-seo/generate-image`\n\n const genImageResponse = await fetch(endpoint, {\n body: JSON.stringify({\n id: docInfo.id,\n collectionSlug: docInfo.collectionSlug,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\n globalSlug: docInfo.globalSlug,\n hasPublishPermission: docInfo.hasPublishPermission,\n hasSavePermission: docInfo.hasSavePermission,\n initialData: docInfo.initialData,\n initialState: docInfo.initialState,\n locale: typeof locale === 'object' ? locale?.code : locale,\n title: docInfo.title,\n } satisfies Omit<Parameters<GenerateImage>[0], 'collectionConfig' | 'globalConfig' | 'req'>),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const generatedImage = await genImageResponse.text()\n\n setValue(generatedImage || '')\n }, [\n hasGenerateImageFn,\n serverURL,\n api,\n docInfo.id,\n docInfo.collectionSlug,\n docInfo.docPermissions,\n docInfo.globalSlug,\n docInfo.hasPublishPermission,\n docInfo.hasSavePermission,\n docInfo.initialData,\n docInfo.initialState,\n docInfo.title,\n getData,\n locale,\n setValue,\n ])\n\n const hasImage = Boolean(value)\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\n field={null}\n Label={Label}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n {hasGenerateImageFn && (\n <React.Fragment>\n — \n <button\n onClick={() => {\n void regenerateImage()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n {hasGenerateImageFn && (\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:imageAutoGenerationTip')}\n </div>\n )}\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <UploadInput\n api={api}\n collection={collection}\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n filterOptions={field.filterOptions}\n onChange={(incomingImage) => {\n if (incomingImage !== null) {\n if (typeof incomingImage === 'object') {\n const { id: incomingID } = incomingImage\n setValue(incomingID)\n } else {\n setValue(incomingImage)\n }\n } else {\n setValue(null)\n }\n }}\n path={field.path}\n relationTo={relationTo}\n required={required}\n serverURL={serverURL}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <Pill\n backgroundColor={hasImage ? 'green' : 'red'}\n color=\"white\"\n label={hasImage ? t('plugin-seo:good') : t('plugin-seo:noImage')}\n />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","UploadInput","useConfig","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","Pill","MetaImageComponent","props","field","admin","components","Label","label","relationTo","required","hasGenerateImageFn","labelProps","path","pathFromContext","config","collections","routes","api","serverURL","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateImage","endpoint","genImageResponse","fetch","body","JSON","stringify","id","collectionSlug","doc","docPermissions","globalSlug","hasPublishPermission","hasSavePermission","initialData","initialState","code","title","credentials","headers","method","generatedImage","text","hasImage","Boolean","collection","find","coll","slug","undefined","div","style","marginBottom","position","className","Fragment","button","onClick","background","backgroundColor","border","color","cursor","padding","textDecoration","type","Error","Component","RenderedComponent","filterOptions","onChange","incomingImage","incomingID","alignItems","display","width"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,WAAW,CAAA;AAEtF,eAAO,MAAM,cAAc,EAAE,aAoB5B,CAAA"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { withMergedProps } from '@payloadcms/ui/shared';
|
|
2
|
-
import { MetaImageComponent } from './MetaImageComponent.js';
|
|
3
1
|
export const MetaImageField = ({ hasGenerateFn = false, overrides, relationTo })=>{
|
|
4
2
|
return {
|
|
5
3
|
name: 'image',
|
|
6
4
|
type: 'upload',
|
|
7
5
|
admin: {
|
|
8
6
|
components: {
|
|
9
|
-
Field:
|
|
10
|
-
|
|
11
|
-
sanitizeServerOnlyProps: true,
|
|
12
|
-
toMergeIntoProps: {
|
|
7
|
+
Field: {
|
|
8
|
+
clientProps: {
|
|
13
9
|
hasGenerateImageFn: hasGenerateFn
|
|
14
|
-
}
|
|
15
|
-
|
|
10
|
+
},
|
|
11
|
+
path: '@payloadcms/plugin-seo/client#MetaImageComponent'
|
|
12
|
+
}
|
|
16
13
|
},
|
|
17
14
|
description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.'
|
|
18
15
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/MetaImage/index.ts"],"sourcesContent":["import type { UploadField } from 'payload'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaImage/index.ts"],"sourcesContent":["import type { UploadField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<UploadField>\n relationTo: string\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UploadField\n\nexport const MetaImageField: FieldFunction = ({ hasGenerateFn = false, overrides, relationTo }) => {\n return {\n name: 'image',\n type: 'upload',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateImageFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaImageComponent',\n },\n },\n description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.',\n },\n label: 'Meta Image',\n localized: true,\n relationTo,\n ...((overrides as unknown as UploadField) ?? {}),\n }\n}\n"],"names":["MetaImageField","hasGenerateFn","overrides","relationTo","name","type","admin","components","Field","clientProps","hasGenerateImageFn","path","description","label","localized"],"mappings":"AAaA,OAAO,MAAMA,iBAAgC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE;IAC5F,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,oBAAoBT;oBACtB;oBACAU,MAAM;gBACR;YACF;YACAC,aAAa;QACf;QACAC,OAAO;QACPC,WAAW;QACXX;QACA,GAAI,AAACD,aAAwC,CAAC,CAAC;IACjD;AACF,EAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TextFieldClientProps } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import '../index.scss';
|
|
4
4
|
type MetaTitleProps = {
|
|
5
|
-
hasGenerateTitleFn: boolean;
|
|
6
|
-
} &
|
|
5
|
+
readonly hasGenerateTitleFn: boolean;
|
|
6
|
+
} & TextFieldClientProps;
|
|
7
7
|
export declare const MetaTitleComponent: React.FC<MetaTitleProps>;
|
|
8
8
|
export {};
|
|
9
9
|
//# sourceMappingURL=MetaTitleComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaTitleComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"MetaTitleComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAanD,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,OAAO,eAAe,CAAA;AAItB,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;CACrC,GAAG,oBAAoB,CAAA;AAExB,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA8KvD,CAAA"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
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';
|
|
3
|
+
import { FieldLabel, TextInput, useConfig, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
|
|
4
4
|
import React, { useCallback } from 'react';
|
|
5
5
|
import { defaults } from '../../defaults.js';
|
|
6
6
|
import { LengthIndicator } from '../../ui/LengthIndicator.js';
|
|
7
7
|
import '../index.scss';
|
|
8
8
|
const { maxLength, minLength } = defaults.title;
|
|
9
9
|
export const MetaTitleComponent = (props)=>{
|
|
10
|
-
const {
|
|
10
|
+
const { field: { admin: { components: { Label } }, label, required }, field: fieldFromProps, hasGenerateTitleFn, labelProps } = props || {};
|
|
11
11
|
const { path: pathFromContext } = useFieldProps();
|
|
12
12
|
const { t } = useTranslation();
|
|
13
|
+
const { config: { routes: { api }, serverURL } } = useConfig();
|
|
13
14
|
const field = useField({
|
|
14
15
|
path: pathFromContext
|
|
15
16
|
});
|
|
@@ -18,14 +19,23 @@ export const MetaTitleComponent = (props)=>{
|
|
|
18
19
|
const docInfo = useDocumentInfo();
|
|
19
20
|
const { errorMessage, setValue, showError, value } = field;
|
|
20
21
|
const regenerateTitle = useCallback(async ()=>{
|
|
21
|
-
if (!hasGenerateTitleFn)
|
|
22
|
-
|
|
22
|
+
if (!hasGenerateTitleFn) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const endpoint = `${serverURL}${api}/plugin-seo/generate-title`;
|
|
26
|
+
const genTitleResponse = await fetch(endpoint, {
|
|
23
27
|
body: JSON.stringify({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
id: docInfo.id,
|
|
29
|
+
collectionSlug: docInfo.collectionSlug,
|
|
30
|
+
doc: getData(),
|
|
31
|
+
docPermissions: docInfo.docPermissions,
|
|
32
|
+
globalSlug: docInfo.globalSlug,
|
|
33
|
+
hasPublishPermission: docInfo.hasPublishPermission,
|
|
34
|
+
hasSavePermission: docInfo.hasSavePermission,
|
|
35
|
+
initialData: docInfo.initialData,
|
|
36
|
+
initialState: docInfo.initialState,
|
|
37
|
+
locale: typeof locale === 'object' ? locale?.code : locale,
|
|
38
|
+
title: docInfo.title
|
|
29
39
|
}),
|
|
30
40
|
credentials: 'include',
|
|
31
41
|
headers: {
|
|
@@ -37,7 +47,17 @@ export const MetaTitleComponent = (props)=>{
|
|
|
37
47
|
setValue(generatedTitle || '');
|
|
38
48
|
}, [
|
|
39
49
|
hasGenerateTitleFn,
|
|
40
|
-
|
|
50
|
+
serverURL,
|
|
51
|
+
api,
|
|
52
|
+
docInfo.id,
|
|
53
|
+
docInfo.collectionSlug,
|
|
54
|
+
docInfo.docPermissions,
|
|
55
|
+
docInfo.globalSlug,
|
|
56
|
+
docInfo.hasPublishPermission,
|
|
57
|
+
docInfo.hasSavePermission,
|
|
58
|
+
docInfo.initialData,
|
|
59
|
+
docInfo.initialState,
|
|
60
|
+
docInfo.title,
|
|
41
61
|
getData,
|
|
42
62
|
locale,
|
|
43
63
|
setValue
|
|
@@ -57,8 +77,10 @@ export const MetaTitleComponent = (props)=>{
|
|
|
57
77
|
className: "plugin-seo__field",
|
|
58
78
|
children: [
|
|
59
79
|
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
60
|
-
|
|
80
|
+
field: fieldFromProps,
|
|
81
|
+
Label: Label,
|
|
61
82
|
label: label,
|
|
83
|
+
required: required,
|
|
62
84
|
...labelProps || {}
|
|
63
85
|
}),
|
|
64
86
|
hasGenerateTitleFn && /*#__PURE__*/ _jsxs(React.Fragment, {
|
|
@@ -110,7 +132,11 @@ export const MetaTitleComponent = (props)=>{
|
|
|
110
132
|
position: 'relative'
|
|
111
133
|
},
|
|
112
134
|
children: /*#__PURE__*/ _jsx(TextInput, {
|
|
113
|
-
|
|
135
|
+
Error: {
|
|
136
|
+
type: 'client',
|
|
137
|
+
Component: null,
|
|
138
|
+
RenderedComponent: errorMessage
|
|
139
|
+
},
|
|
114
140
|
onChange: setValue,
|
|
115
141
|
path: pathFromContext,
|
|
116
142
|
required: required,
|