@payloadcms/plugin-seo 3.0.0-canary.c13f9ba → 3.0.0-canary.c696728
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/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/exports/fields.d.ts +6 -0
- package/dist/exports/fields.d.ts.map +1 -0
- package/dist/exports/fields.js +7 -0
- package/dist/exports/fields.js.map +1 -0
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts +8 -0
- package/dist/fields/MetaDescription/MetaDescriptionComponent.d.ts.map +1 -0
- package/dist/fields/{MetaDescription.js → MetaDescription/MetaDescriptionComponent.js} +36 -27
- package/dist/fields/MetaDescription/MetaDescriptionComponent.js.map +1 -0
- package/dist/fields/MetaDescription/index.d.ts +12 -0
- package/dist/fields/MetaDescription/index.d.ts.map +1 -0
- package/dist/fields/MetaDescription/index.js +20 -0
- package/dist/fields/MetaDescription/index.js.map +1 -0
- package/dist/fields/MetaImage/MetaImageComponent.d.ts +8 -0
- package/dist/fields/MetaImage/MetaImageComponent.d.ts.map +1 -0
- package/dist/fields/{MetaImage.js → MetaImage/MetaImageComponent.js} +47 -30
- package/dist/fields/MetaImage/MetaImageComponent.js.map +1 -0
- package/dist/fields/MetaImage/index.d.ts +13 -0
- package/dist/fields/MetaImage/index.d.ts.map +1 -0
- package/dist/fields/MetaImage/index.js +23 -0
- package/dist/fields/MetaImage/index.js.map +1 -0
- package/dist/fields/MetaTitle/MetaTitleComponent.d.ts +9 -0
- package/dist/fields/MetaTitle/MetaTitleComponent.d.ts.map +1 -0
- package/dist/fields/{MetaTitle.js → MetaTitle/MetaTitleComponent.js} +37 -28
- package/dist/fields/MetaTitle/MetaTitleComponent.js.map +1 -0
- package/dist/fields/MetaTitle/index.d.ts +12 -0
- package/dist/fields/MetaTitle/index.d.ts.map +1 -0
- package/dist/fields/MetaTitle/index.js +20 -0
- package/dist/fields/MetaTitle/index.js.map +1 -0
- package/dist/fields/Overview/OverviewComponent.d.ts +10 -0
- package/dist/fields/Overview/OverviewComponent.d.ts.map +1 -0
- package/dist/{ui/Overview.js → fields/Overview/OverviewComponent.js} +14 -9
- package/dist/fields/Overview/OverviewComponent.js.map +1 -0
- package/dist/fields/Overview/index.d.ts +26 -0
- package/dist/fields/Overview/index.d.ts.map +1 -0
- package/dist/fields/Overview/index.js +22 -0
- package/dist/fields/Overview/index.js.map +1 -0
- package/dist/fields/Preview/PreviewComponent.d.ts +10 -0
- package/dist/fields/Preview/PreviewComponent.d.ts.map +1 -0
- package/dist/{ui/Preview.js → fields/Preview/PreviewComponent.js} +21 -13
- package/dist/fields/Preview/PreviewComponent.js.map +1 -0
- package/dist/fields/Preview/index.d.ts +24 -0
- package/dist/fields/Preview/index.d.ts.map +1 -0
- package/dist/fields/Preview/index.js +22 -0
- package/dist/fields/Preview/index.js.map +1 -0
- 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 +64 -112
- 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 -156
- package/dist/translations/index.d.ts.map +1 -1
- package/dist/translations/index.js +18 -154
- 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 +23 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/LengthIndicator.js +2 -2
- package/dist/ui/LengthIndicator.js.map +1 -1
- package/dist/ui/Pill.js.map +1 -1
- package/package.json +35 -25
- package/dist/fields/MetaDescription.d.ts +0 -9
- package/dist/fields/MetaDescription.d.ts.map +0 -1
- package/dist/fields/MetaDescription.js.map +0 -1
- package/dist/fields/MetaImage.d.ts +0 -8
- package/dist/fields/MetaImage.d.ts.map +0 -1
- package/dist/fields/MetaImage.js.map +0 -1
- package/dist/fields/MetaTitle.d.ts +0 -9
- package/dist/fields/MetaTitle.d.ts.map +0 -1
- package/dist/fields/MetaTitle.js.map +0 -1
- 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/uk.json +0 -22
- package/dist/ui/Overview.d.ts +0 -3
- package/dist/ui/Overview.d.ts.map +0 -1
- package/dist/ui/Overview.js.map +0 -1
- package/dist/ui/Preview.d.ts +0 -8
- package/dist/ui/Preview.d.ts.map +0 -1
- package/dist/ui/Preview.js.map +0 -1
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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js';
|
|
2
|
+
export { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js';
|
|
3
|
+
export { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js';
|
|
4
|
+
export { OverviewComponent } from '../fields/Overview/OverviewComponent.js';
|
|
5
|
+
export { PreviewComponent } from '../fields/Preview/PreviewComponent.js';
|
|
6
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAA;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js';
|
|
2
|
+
export { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js';
|
|
3
|
+
export { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js';
|
|
4
|
+
export { OverviewComponent } from '../fields/Overview/OverviewComponent.js';
|
|
5
|
+
export { PreviewComponent } from '../fields/Preview/PreviewComponent.js';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { MetaDescriptionComponent } from '../fields/MetaDescription/MetaDescriptionComponent.js'\nexport { MetaImageComponent } from '../fields/MetaImage/MetaImageComponent.js'\nexport { MetaTitleComponent } from '../fields/MetaTitle/MetaTitleComponent.js'\nexport { OverviewComponent } from '../fields/Overview/OverviewComponent.js'\nexport { PreviewComponent } from '../fields/Preview/PreviewComponent.js'\n"],"names":["MetaDescriptionComponent","MetaImageComponent","MetaTitleComponent","OverviewComponent","PreviewComponent"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,wDAAuD;AAChG,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,kBAAkB,QAAQ,4CAA2C;AAC9E,SAASC,iBAAiB,QAAQ,0CAAyC;AAC3E,SAASC,gBAAgB,QAAQ,wCAAuC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { MetaDescriptionField } from '../fields/MetaDescription/index.js';
|
|
2
|
+
export { MetaImageField } from '../fields/MetaImage/index.js';
|
|
3
|
+
export { MetaTitleField } from '../fields/MetaTitle/index.js';
|
|
4
|
+
export { OverviewField } from '../fields/Overview/index.js';
|
|
5
|
+
export { PreviewField } from '../fields/Preview/index.js';
|
|
6
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/exports/fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MetaDescriptionField } from '../fields/MetaDescription/index.js';
|
|
2
|
+
export { MetaImageField } from '../fields/MetaImage/index.js';
|
|
3
|
+
export { MetaTitleField } from '../fields/MetaTitle/index.js';
|
|
4
|
+
export { OverviewField } from '../fields/Overview/index.js';
|
|
5
|
+
export { PreviewField } from '../fields/Preview/index.js';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/fields.ts"],"sourcesContent":["export { MetaDescriptionField } from '../fields/MetaDescription/index.js'\nexport { MetaImageField } from '../fields/MetaImage/index.js'\nexport { MetaTitleField } from '../fields/MetaTitle/index.js'\nexport { OverviewField } from '../fields/Overview/index.js'\nexport { PreviewField } from '../fields/Preview/index.js'\n"],"names":["MetaDescriptionField","MetaImageField","MetaTitleField","OverviewField","PreviewField"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,YAAY,QAAQ,6BAA4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n Meta,\n SEOPluginConfig,\n} from '../types.js'\n"],"names":[],"
|
|
1
|
+
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n GenerateDescription,\n GenerateImage,\n GenerateTitle,\n GenerateURL,\n Meta,\n SEOPluginConfig,\n} from '../types.js'\n"],"names":[],"mappings":"AAAA,WAOoB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TextareaFieldClientProps } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type MetaDescriptionProps = {
|
|
4
|
+
readonly hasGenerateDescriptionFn: boolean;
|
|
5
|
+
} & TextareaFieldClientProps;
|
|
6
|
+
export declare const MetaDescriptionComponent: React.FC<MetaDescriptionProps>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=MetaDescriptionComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaDescriptionComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAYvD,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,CAkJnE,CAAA"}
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { TextareaInput } from '@payloadcms/ui
|
|
4
|
-
import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel';
|
|
5
|
-
import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
|
|
6
|
-
import { useAllFormFields } from '@payloadcms/ui/forms/Form';
|
|
7
|
-
import { useField } from '@payloadcms/ui/forms/useField';
|
|
8
|
-
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
|
9
|
-
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
|
10
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
|
3
|
+
import { FieldLabel, TextareaInput, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
|
|
11
4
|
import React, { useCallback } from 'react';
|
|
12
|
-
import { defaults } from '
|
|
13
|
-
import { LengthIndicator } from '
|
|
5
|
+
import { defaults } from '../../defaults.js';
|
|
6
|
+
import { LengthIndicator } from '../../ui/LengthIndicator.js';
|
|
14
7
|
const { maxLength, minLength } = defaults.description;
|
|
15
|
-
export const
|
|
16
|
-
const {
|
|
8
|
+
export const MetaDescriptionComponent = (props)=>{
|
|
9
|
+
const { field: { admin: { components: { Label } }, label, required }, hasGenerateDescriptionFn, labelProps } = props;
|
|
17
10
|
const { path: pathFromContext } = useFieldProps();
|
|
18
11
|
const { t } = useTranslation();
|
|
19
12
|
const locale = useLocale();
|
|
20
|
-
const
|
|
13
|
+
const { getData } = useForm();
|
|
21
14
|
const docInfo = useDocumentInfo();
|
|
22
15
|
const field = useField({
|
|
23
|
-
path
|
|
16
|
+
path: pathFromContext
|
|
24
17
|
});
|
|
25
18
|
const { errorMessage, setValue, showError, value } = field;
|
|
26
19
|
const regenerateDescription = useCallback(async ()=>{
|
|
27
|
-
if (!hasGenerateDescriptionFn)
|
|
20
|
+
if (!hasGenerateDescriptionFn) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
28
23
|
const genDescriptionResponse = await fetch('/api/plugin-seo/generate-description', {
|
|
29
24
|
body: JSON.stringify({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
id: docInfo.id,
|
|
26
|
+
collectionSlug: docInfo.collectionSlug,
|
|
27
|
+
doc: getData(),
|
|
28
|
+
docPermissions: docInfo.docPermissions,
|
|
29
|
+
globalSlug: docInfo.globalSlug,
|
|
30
|
+
hasPublishPermission: docInfo.hasPublishPermission,
|
|
31
|
+
hasSavePermission: docInfo.hasSavePermission,
|
|
32
|
+
initialData: docInfo.initialData,
|
|
33
|
+
initialState: docInfo.initialState,
|
|
34
|
+
locale: typeof locale === 'object' ? locale?.code : locale,
|
|
35
|
+
title: docInfo.title
|
|
35
36
|
}),
|
|
36
37
|
credentials: 'include',
|
|
37
38
|
headers: {
|
|
@@ -42,11 +43,11 @@ export const MetaDescription = (props)=>{
|
|
|
42
43
|
const { result: generatedDescription } = await genDescriptionResponse.json();
|
|
43
44
|
setValue(generatedDescription || '');
|
|
44
45
|
}, [
|
|
45
|
-
fields,
|
|
46
|
-
setValue,
|
|
47
46
|
hasGenerateDescriptionFn,
|
|
47
|
+
docInfo,
|
|
48
|
+
getData,
|
|
48
49
|
locale,
|
|
49
|
-
|
|
50
|
+
setValue
|
|
50
51
|
]);
|
|
51
52
|
return /*#__PURE__*/ _jsxs("div", {
|
|
52
53
|
style: {
|
|
@@ -63,7 +64,8 @@ export const MetaDescription = (props)=>{
|
|
|
63
64
|
className: "plugin-seo__field",
|
|
64
65
|
children: [
|
|
65
66
|
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
66
|
-
|
|
67
|
+
field: null,
|
|
68
|
+
Label: Label,
|
|
67
69
|
label: label,
|
|
68
70
|
...labelProps || {}
|
|
69
71
|
}),
|
|
@@ -71,7 +73,9 @@ export const MetaDescription = (props)=>{
|
|
|
71
73
|
children: [
|
|
72
74
|
" — ",
|
|
73
75
|
/*#__PURE__*/ _jsx("button", {
|
|
74
|
-
onClick:
|
|
76
|
+
onClick: ()=>{
|
|
77
|
+
void regenerateDescription();
|
|
78
|
+
},
|
|
75
79
|
style: {
|
|
76
80
|
background: 'none',
|
|
77
81
|
backgroundColor: 'transparent',
|
|
@@ -113,7 +117,12 @@ export const MetaDescription = (props)=>{
|
|
|
113
117
|
position: 'relative'
|
|
114
118
|
},
|
|
115
119
|
children: /*#__PURE__*/ _jsx(TextareaInput, {
|
|
116
|
-
|
|
120
|
+
Error: {
|
|
121
|
+
type: 'client',
|
|
122
|
+
Component: null,
|
|
123
|
+
RenderedComponent: errorMessage
|
|
124
|
+
},
|
|
125
|
+
label: label,
|
|
117
126
|
onChange: setValue,
|
|
118
127
|
path: pathFromContext,
|
|
119
128
|
required: required,
|
|
@@ -140,4 +149,4 @@ export const MetaDescription = (props)=>{
|
|
|
140
149
|
});
|
|
141
150
|
};
|
|
142
151
|
|
|
143
|
-
//# sourceMappingURL=
|
|
152
|
+
//# sourceMappingURL=MetaDescriptionComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaDescription/MetaDescriptionComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { TextareaFieldClientProps } from 'payload'\n\nimport {\n FieldLabel,\n TextareaInput,\n useDocumentInfo,\n useField,\n useFieldProps,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateDescription } from '../../types.js'\n\nimport { defaults } from '../../defaults.js'\nimport { LengthIndicator } from '../../ui/LengthIndicator.js'\n\nconst { maxLength, minLength } = defaults.description\n\ntype MetaDescriptionProps = {\n readonly hasGenerateDescriptionFn: boolean\n} & 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 { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const field: FieldType<string> = useField({\n path: pathFromContext,\n } as Options)\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateDescription = useCallback(async () => {\n if (!hasGenerateDescriptionFn) {\n return\n }\n\n const genDescriptionResponse = await fetch('/api/plugin-seo/generate-description', {\n body: JSON.stringify({\n id: docInfo.id,\n 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 }, [hasGenerateDescriptionFn, docInfo, getData, locale, setValue])\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel field={null} Label={Label} label={label} {...(labelProps || {})} />\n {hasGenerateDescriptionFn && (\n <React.Fragment>\n — \n <button\n onClick={() => {\n void regenerateDescription()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:lengthTipDescription', { maxLength, minLength })}\n <a\n href=\"https://developers.google.com/search/docs/advanced/appearance/snippet#meta-descriptions\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {t('plugin-seo:bestPractices')}\n </a>\n </div>\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <TextareaInput\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n label={label}\n onChange={setValue}\n path={pathFromContext}\n required={required}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <LengthIndicator maxLength={maxLength} minLength={minLength} text={value} />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","TextareaInput","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","description","MetaDescriptionComponent","props","field","admin","components","Label","label","required","hasGenerateDescriptionFn","labelProps","path","pathFromContext","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateDescription","genDescriptionResponse","fetch","body","JSON","stringify","id","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":"AAAA;;AAKA,SACEA,UAAU,EACVC,aAAa,EACbC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,SAASC,eAAe,QAAQ,8BAA6B;AAE7D,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH,SAASI,WAAW;AAMrD,OAAO,MAAMC,2BAA2D,CAACC;IACvE,MAAM,EACJC,OAAO,EACLC,OAAO,EACLC,YAAY,EA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;kCAEA,MAACH;wBAAII,WAAU;;0CACb,KAAC9D;gCAAWiB,OAAO;gCAAMG,OAAOA;gCAAOC,OAAOA;gCAAQ,GAAIG,cAAc,CAAC,CAAC;;4BACzED,0CACC,MAACf,MAAMuD,QAAQ;;oCAAC;kDAEd,KAACC;wCACCC,SAAS;4CACP,KAAK9B;wCACP;wCACAwB,OAAO;4CACLO,YAAY;4CACZC,iBAAiB;4CACjBC,QAAQ;4CACRC,OAAO;4CACPC,QAAQ;4CACRC,SAAS;4CACTC,gBAAgB;wCAClB;wCACAC,MAAK;kDAEJ9C,EAAE;;;;;;kCAKX,MAAC+B;wBACCC,OAAO;4BACLU,OAAO;wBACT;;4BAEC1C,EAAE,mCAAmC;gCAAEf;gCAAWC;4BAAU;0CAC7D,KAAC6D;gCACCC,MAAK;gCACLC,KAAI;gCACJC,QAAO;0CAENlD,EAAE;;;;;;0BAIT,KAAC+B;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAAC5D;oBACC6E,OAAO;wBACLL,MAAM;wBACNM,WAAW;wBACXC,mBAAmBjD;oBACrB;oBACAV,OAAOA;oBACP4D,UAAUjD;oBACVP,MAAMC;oBACNJ,UAAUA;oBACVW,WAAWA;oBACX0B,OAAO;wBACLC,cAAc;oBAChB;oBACA1B,OAAOA;;;0BAGX,KAACwB;gBACCC,OAAO;oBACLuB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAACzE;oBAAgBC,WAAWA;oBAAWC,WAAWA;oBAAWwE,MAAMnD;;;;;AAI3E,EAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TextareaField } from 'payload';
|
|
2
|
+
interface FieldFunctionProps {
|
|
3
|
+
/**
|
|
4
|
+
* Tell the component if the generate function is available as configured in the plugin config
|
|
5
|
+
*/
|
|
6
|
+
hasGenerateFn?: boolean;
|
|
7
|
+
overrides?: Partial<TextareaField>;
|
|
8
|
+
}
|
|
9
|
+
type FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextareaField;
|
|
10
|
+
export declare const MetaDescriptionField: FieldFunction;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaDescription/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CACnC;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,aAAa,CAAA;AAExF,eAAO,MAAM,oBAAoB,EAAE,aAiBlC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const MetaDescriptionField = ({ hasGenerateFn = false, overrides })=>{
|
|
2
|
+
return {
|
|
3
|
+
name: 'description',
|
|
4
|
+
type: 'textarea',
|
|
5
|
+
admin: {
|
|
6
|
+
components: {
|
|
7
|
+
Field: {
|
|
8
|
+
clientProps: {
|
|
9
|
+
hasGenerateDescriptionFn: hasGenerateFn
|
|
10
|
+
},
|
|
11
|
+
path: '@payloadcms/plugin-seo/client#MetaDescriptionComponent'
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
localized: true,
|
|
16
|
+
...overrides ?? {}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaDescription/index.ts"],"sourcesContent":["import type { TextareaField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<TextareaField>\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextareaField\n\nexport const MetaDescriptionField: FieldFunction = ({ hasGenerateFn = false, overrides }) => {\n return {\n name: 'description',\n type: 'textarea',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateDescriptionFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaDescriptionComponent',\n },\n },\n },\n localized: true,\n ...((overrides as unknown as TextareaField) ?? {}),\n }\n}\n"],"names":["MetaDescriptionField","hasGenerateFn","overrides","name","type","admin","components","Field","clientProps","hasGenerateDescriptionFn","path","localized"],"mappings":"AAYA,OAAO,MAAMA,uBAAsC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAE;IACtF,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,0BAA0BR;oBAC5B;oBACAS,MAAM;gBACR;YACF;QACF;QACAC,WAAW;QACX,GAAI,AAACT,aAA0C,CAAC,CAAC;IACnD;AACF,EAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UploadFieldClientProps } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type MetaImageProps = {
|
|
4
|
+
readonly hasGenerateImageFn: boolean;
|
|
5
|
+
} & UploadFieldClientProps;
|
|
6
|
+
export declare const MetaImageComponent: React.FC<MetaImageProps>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=MetaImageComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaImageComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,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,CAqKvD,CAAA"}
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { UploadInput } from '@payloadcms/ui
|
|
4
|
-
import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel';
|
|
5
|
-
import { useAllFormFields } from '@payloadcms/ui/forms/Form';
|
|
6
|
-
import { useField } from '@payloadcms/ui/forms/useField';
|
|
7
|
-
import { useConfig } from '@payloadcms/ui/providers/Config';
|
|
8
|
-
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
|
9
|
-
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
|
10
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
|
3
|
+
import { FieldLabel, UploadInput, useConfig, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
|
|
11
4
|
import React, { useCallback } from 'react';
|
|
12
|
-
import { Pill } from '
|
|
13
|
-
export const
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
5
|
+
import { Pill } from '../../ui/Pill.js';
|
|
6
|
+
export const MetaImageComponent = (props)=>{
|
|
7
|
+
const { field: { admin: { components: { Label } }, label, relationTo, required }, hasGenerateImageFn, labelProps } = props || {};
|
|
8
|
+
const { path: pathFromContext } = useFieldProps();
|
|
9
|
+
const field = useField({
|
|
10
|
+
...props,
|
|
11
|
+
path: pathFromContext
|
|
12
|
+
});
|
|
16
13
|
const { t } = useTranslation();
|
|
17
14
|
const locale = useLocale();
|
|
18
|
-
const
|
|
15
|
+
const { getData } = useForm();
|
|
19
16
|
const docInfo = useDocumentInfo();
|
|
20
17
|
const { errorMessage, setValue, showError, value } = field;
|
|
21
18
|
const regenerateImage = useCallback(async ()=>{
|
|
22
|
-
if (!hasGenerateImageFn)
|
|
19
|
+
if (!hasGenerateImageFn) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
23
22
|
const genImageResponse = await fetch('/api/plugin-seo/generate-image', {
|
|
24
23
|
body: JSON.stringify({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
id: docInfo.id,
|
|
25
|
+
collectionSlug: docInfo.collectionSlug,
|
|
26
|
+
doc: getData(),
|
|
27
|
+
docPermissions: docInfo.docPermissions,
|
|
28
|
+
globalSlug: docInfo.globalSlug,
|
|
29
|
+
hasPublishPermission: docInfo.hasPublishPermission,
|
|
30
|
+
hasSavePermission: docInfo.hasSavePermission,
|
|
31
|
+
initialData: docInfo.initialData,
|
|
32
|
+
initialState: docInfo.initialState,
|
|
33
|
+
locale: typeof locale === 'object' ? locale?.code : locale,
|
|
34
|
+
title: docInfo.title
|
|
30
35
|
}),
|
|
31
36
|
credentials: 'include',
|
|
32
37
|
headers: {
|
|
@@ -34,17 +39,17 @@ export const MetaImage = (props)=>{
|
|
|
34
39
|
},
|
|
35
40
|
method: 'POST'
|
|
36
41
|
});
|
|
37
|
-
const
|
|
42
|
+
const generatedImage = await genImageResponse.text();
|
|
38
43
|
setValue(generatedImage || '');
|
|
39
44
|
}, [
|
|
40
|
-
fields,
|
|
41
|
-
setValue,
|
|
42
45
|
hasGenerateImageFn,
|
|
46
|
+
docInfo,
|
|
47
|
+
getData,
|
|
43
48
|
locale,
|
|
44
|
-
|
|
49
|
+
setValue
|
|
45
50
|
]);
|
|
46
51
|
const hasImage = Boolean(value);
|
|
47
|
-
const config = useConfig();
|
|
52
|
+
const { config } = useConfig();
|
|
48
53
|
const { collections, routes: { api } = {}, serverURL } = config;
|
|
49
54
|
const collection = collections?.find((coll)=>coll.slug === relationTo) || undefined;
|
|
50
55
|
return /*#__PURE__*/ _jsxs("div", {
|
|
@@ -62,7 +67,8 @@ export const MetaImage = (props)=>{
|
|
|
62
67
|
className: "plugin-seo__field",
|
|
63
68
|
children: [
|
|
64
69
|
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
65
|
-
|
|
70
|
+
field: null,
|
|
71
|
+
Label: Label,
|
|
66
72
|
label: label,
|
|
67
73
|
...labelProps || {}
|
|
68
74
|
}),
|
|
@@ -70,7 +76,9 @@ export const MetaImage = (props)=>{
|
|
|
70
76
|
children: [
|
|
71
77
|
" — ",
|
|
72
78
|
/*#__PURE__*/ _jsx("button", {
|
|
73
|
-
onClick:
|
|
79
|
+
onClick: ()=>{
|
|
80
|
+
void regenerateImage();
|
|
81
|
+
},
|
|
74
82
|
style: {
|
|
75
83
|
background: 'none',
|
|
76
84
|
backgroundColor: 'transparent',
|
|
@@ -101,19 +109,28 @@ export const MetaImage = (props)=>{
|
|
|
101
109
|
position: 'relative'
|
|
102
110
|
},
|
|
103
111
|
children: /*#__PURE__*/ _jsx(UploadInput, {
|
|
104
|
-
CustomError: errorMessage,
|
|
105
112
|
api: api,
|
|
106
113
|
collection: collection,
|
|
114
|
+
Error: {
|
|
115
|
+
type: 'client',
|
|
116
|
+
Component: null,
|
|
117
|
+
RenderedComponent: errorMessage
|
|
118
|
+
},
|
|
107
119
|
filterOptions: field.filterOptions,
|
|
108
120
|
label: undefined,
|
|
109
121
|
onChange: (incomingImage)=>{
|
|
110
122
|
if (incomingImage !== null) {
|
|
111
|
-
|
|
112
|
-
|
|
123
|
+
if (typeof incomingImage === 'object') {
|
|
124
|
+
const { id: incomingID } = incomingImage;
|
|
125
|
+
setValue(incomingID);
|
|
126
|
+
} else {
|
|
127
|
+
setValue(incomingImage);
|
|
128
|
+
}
|
|
113
129
|
} else {
|
|
114
130
|
setValue(null);
|
|
115
131
|
}
|
|
116
132
|
},
|
|
133
|
+
path: field.path,
|
|
117
134
|
relationTo: relationTo,
|
|
118
135
|
required: required,
|
|
119
136
|
serverURL: serverURL,
|
|
@@ -140,4 +157,4 @@ export const MetaImage = (props)=>{
|
|
|
140
157
|
});
|
|
141
158
|
};
|
|
142
159
|
|
|
143
|
-
//# sourceMappingURL=
|
|
160
|
+
//# sourceMappingURL=MetaImageComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaImage/MetaImageComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { 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 field: FieldType<string> = useField({ ...props, path: pathFromContext } as Options)\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateImage = useCallback(async () => {\n if (!hasGenerateImageFn) {\n return\n }\n\n const genImageResponse = await fetch('/api/plugin-seo/generate-image', {\n body: JSON.stringify({\n id: docInfo.id,\n 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 }, [hasGenerateImageFn, docInfo, getData, locale, setValue])\n\n const hasImage = Boolean(value)\n\n const { config } = useConfig()\n\n const { collections, routes: { api } = {}, serverURL } = config\n\n const collection = collections?.find((coll) => coll.slug === relationTo) || undefined\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div\n style={{\n marginBottom: '5px',\n position: 'relative',\n }}\n >\n <div className=\"plugin-seo__field\">\n <FieldLabel field={null} Label={Label} label={label} {...(labelProps || {})} />\n {hasGenerateImageFn && (\n <React.Fragment>\n — \n <button\n onClick={() => {\n void regenerateImage()\n }}\n style={{\n background: 'none',\n backgroundColor: 'transparent',\n border: 'none',\n color: 'currentcolor',\n cursor: 'pointer',\n padding: 0,\n textDecoration: 'underline',\n }}\n type=\"button\"\n >\n {t('plugin-seo:autoGenerate')}\n </button>\n </React.Fragment>\n )}\n </div>\n {hasGenerateImageFn && (\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n {t('plugin-seo:imageAutoGenerationTip')}\n </div>\n )}\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <UploadInput\n api={api}\n collection={collection}\n Error={{\n type: 'client',\n Component: null,\n RenderedComponent: errorMessage,\n }}\n filterOptions={field.filterOptions}\n label={undefined}\n onChange={(incomingImage) => {\n if (incomingImage !== null) {\n if (typeof incomingImage === 'object') {\n const { id: incomingID } = incomingImage\n setValue(incomingID)\n } else {\n setValue(incomingImage)\n }\n } else {\n setValue(null)\n }\n }}\n path={field.path}\n relationTo={relationTo}\n required={required}\n serverURL={serverURL}\n showError={showError}\n style={{\n marginBottom: 0,\n }}\n value={value}\n />\n </div>\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n width: '100%',\n }}\n >\n <Pill\n backgroundColor={hasImage ? 'green' : 'red'}\n color=\"white\"\n label={hasImage ? t('plugin-seo:good') : t('plugin-seo:noImage')}\n />\n </div>\n </div>\n )\n}\n"],"names":["FieldLabel","UploadInput","useConfig","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","Pill","MetaImageComponent","props","field","admin","components","Label","label","relationTo","required","hasGenerateImageFn","labelProps","path","pathFromContext","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateImage","genImageResponse","fetch","body","JSON","stringify","id","collectionSlug","doc","docPermissions","globalSlug","hasPublishPermission","hasSavePermission","initialData","initialState","code","title","credentials","headers","method","generatedImage","text","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","Error","Component","RenderedComponent","filterOptions","onChange","incomingImage","incomingID","alignItems","display","width"],"mappings":"AAAA;;AAKA,SACEA,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,IAAI,QAAQ,mBAAkB;AAMvC,OAAO,MAAMC,qBAA+C,CAACC;IAC3D,MAAM,EACJC,OAAO,EACLC,OAAO,EACLC,YAAY,EAAEC,KAAK,EAAE,EACtB,EACDC,KAAK,EACLC,UAAU,EACVC,QAAQ,EACT,EACDC,kBAAkB,EAClBC,UAAU,EACX,GAAGT,SAAS,CAAC;IACd,MAAM,EAAEU,MAAMC,eAAe,EAAE,GAAGnB;IAElC,MAAMS,QAA2BV,SAAS;QAAE,GAAGS,KAAK;QAAEU,MAAMC;IAAgB;IAE5E,MAAM,EAAEC,CAAC,EAAE,GAAGjB;IAEd,MAAMkB,SAASnB;IACf,MAAM,EAAEoB,OAAO,EAAE,GAAGrB;IACpB,MAA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payload';
|
|
2
|
+
interface FieldFunctionProps {
|
|
3
|
+
/**
|
|
4
|
+
* Tell the component if the generate function is available as configured in the plugin config
|
|
5
|
+
*/
|
|
6
|
+
hasGenerateFn?: boolean;
|
|
7
|
+
overrides?: Partial<UploadField>;
|
|
8
|
+
relationTo: string;
|
|
9
|
+
}
|
|
10
|
+
type FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UploadField;
|
|
11
|
+
export declare const MetaImageField: FieldFunction;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaImage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,WAAW,CAAA;AAEtF,eAAO,MAAM,cAAc,EAAE,aAoB5B,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const MetaImageField = ({ hasGenerateFn = false, overrides, relationTo })=>{
|
|
2
|
+
return {
|
|
3
|
+
name: 'image',
|
|
4
|
+
type: 'upload',
|
|
5
|
+
admin: {
|
|
6
|
+
components: {
|
|
7
|
+
Field: {
|
|
8
|
+
clientProps: {
|
|
9
|
+
hasGenerateImageFn: hasGenerateFn
|
|
10
|
+
},
|
|
11
|
+
path: '@payloadcms/plugin-seo/client#MetaImageComponent'
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.'
|
|
15
|
+
},
|
|
16
|
+
label: 'Meta Image',
|
|
17
|
+
localized: true,
|
|
18
|
+
relationTo,
|
|
19
|
+
...overrides ?? {}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaImage/index.ts"],"sourcesContent":["import type { UploadField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<UploadField>\n relationTo: string\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UploadField\n\nexport const MetaImageField: FieldFunction = ({ hasGenerateFn = false, overrides, relationTo }) => {\n return {\n name: 'image',\n type: 'upload',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateImageFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaImageComponent',\n },\n },\n description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.',\n },\n label: 'Meta Image',\n localized: true,\n relationTo,\n ...((overrides as unknown as UploadField) ?? {}),\n }\n}\n"],"names":["MetaImageField","hasGenerateFn","overrides","relationTo","name","type","admin","components","Field","clientProps","hasGenerateImageFn","path","description","label","localized"],"mappings":"AAaA,OAAO,MAAMA,iBAAgC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE;IAC5F,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,oBAAoBT;oBACtB;oBACAU,MAAM;gBACR;YACF;YACAC,aAAa;QACf;QACAC,OAAO;QACPC,WAAW;QACXX;QACA,GAAI,AAACD,aAAwC,CAAC,CAAC;IACjD;AACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TextFieldClientProps } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import '../index.scss';
|
|
4
|
+
type MetaTitleProps = {
|
|
5
|
+
readonly hasGenerateTitleFn: boolean;
|
|
6
|
+
} & TextFieldClientProps;
|
|
7
|
+
export declare const MetaTitleComponent: React.FC<MetaTitleProps>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=MetaTitleComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaTitleComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAYnD,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,CAgJvD,CAAA"}
|
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { TextInput } from '@payloadcms/ui
|
|
4
|
-
import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel';
|
|
5
|
-
import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
|
|
6
|
-
import { useAllFormFields } from '@payloadcms/ui/forms/Form';
|
|
7
|
-
import { useField } from '@payloadcms/ui/forms/useField';
|
|
8
|
-
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
|
9
|
-
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
|
10
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
|
3
|
+
import { FieldLabel, TextInput, useDocumentInfo, useField, useFieldProps, useForm, useLocale, useTranslation } from '@payloadcms/ui';
|
|
11
4
|
import React, { useCallback } from 'react';
|
|
12
|
-
import { defaults } from '
|
|
13
|
-
import { LengthIndicator } from '
|
|
14
|
-
import '
|
|
5
|
+
import { defaults } from '../../defaults.js';
|
|
6
|
+
import { LengthIndicator } from '../../ui/LengthIndicator.js';
|
|
7
|
+
import '../index.scss';
|
|
15
8
|
const { maxLength, minLength } = defaults.title;
|
|
16
|
-
export const
|
|
17
|
-
const {
|
|
9
|
+
export const MetaTitleComponent = (props)=>{
|
|
10
|
+
const { field: { admin: { components: { Label } }, label, required }, hasGenerateTitleFn, labelProps } = props || {};
|
|
18
11
|
const { path: pathFromContext } = useFieldProps();
|
|
19
12
|
const { t } = useTranslation();
|
|
20
13
|
const field = useField({
|
|
21
|
-
path
|
|
14
|
+
path: pathFromContext
|
|
22
15
|
});
|
|
23
16
|
const locale = useLocale();
|
|
24
|
-
const
|
|
17
|
+
const { getData } = useForm();
|
|
25
18
|
const docInfo = useDocumentInfo();
|
|
26
19
|
const { errorMessage, setValue, showError, value } = field;
|
|
27
20
|
const regenerateTitle = useCallback(async ()=>{
|
|
28
|
-
if (!hasGenerateTitleFn)
|
|
21
|
+
if (!hasGenerateTitleFn) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
29
24
|
const genTitleResponse = await fetch('/api/plugin-seo/generate-title', {
|
|
30
25
|
body: JSON.stringify({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
36
37
|
}),
|
|
37
38
|
credentials: 'include',
|
|
38
39
|
headers: {
|
|
@@ -43,11 +44,11 @@ export const MetaTitle = (props)=>{
|
|
|
43
44
|
const { result: generatedTitle } = await genTitleResponse.json();
|
|
44
45
|
setValue(generatedTitle || '');
|
|
45
46
|
}, [
|
|
46
|
-
fields,
|
|
47
|
-
setValue,
|
|
48
47
|
hasGenerateTitleFn,
|
|
48
|
+
docInfo,
|
|
49
|
+
getData,
|
|
49
50
|
locale,
|
|
50
|
-
|
|
51
|
+
setValue
|
|
51
52
|
]);
|
|
52
53
|
return /*#__PURE__*/ _jsxs("div", {
|
|
53
54
|
style: {
|
|
@@ -64,7 +65,8 @@ export const MetaTitle = (props)=>{
|
|
|
64
65
|
className: "plugin-seo__field",
|
|
65
66
|
children: [
|
|
66
67
|
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
67
|
-
|
|
68
|
+
field: null,
|
|
69
|
+
Label: Label,
|
|
68
70
|
label: label,
|
|
69
71
|
...labelProps || {}
|
|
70
72
|
}),
|
|
@@ -72,7 +74,9 @@ export const MetaTitle = (props)=>{
|
|
|
72
74
|
children: [
|
|
73
75
|
" — ",
|
|
74
76
|
/*#__PURE__*/ _jsx("button", {
|
|
75
|
-
onClick:
|
|
77
|
+
onClick: ()=>{
|
|
78
|
+
void regenerateTitle();
|
|
79
|
+
},
|
|
76
80
|
style: {
|
|
77
81
|
background: 'none',
|
|
78
82
|
backgroundColor: 'transparent',
|
|
@@ -115,7 +119,12 @@ export const MetaTitle = (props)=>{
|
|
|
115
119
|
position: 'relative'
|
|
116
120
|
},
|
|
117
121
|
children: /*#__PURE__*/ _jsx(TextInput, {
|
|
118
|
-
|
|
122
|
+
Error: {
|
|
123
|
+
type: 'client',
|
|
124
|
+
Component: null,
|
|
125
|
+
RenderedComponent: errorMessage
|
|
126
|
+
},
|
|
127
|
+
label: label,
|
|
119
128
|
onChange: setValue,
|
|
120
129
|
path: pathFromContext,
|
|
121
130
|
required: required,
|
|
@@ -142,4 +151,4 @@ export const MetaTitle = (props)=>{
|
|
|
142
151
|
});
|
|
143
152
|
};
|
|
144
153
|
|
|
145
|
-
//# sourceMappingURL=
|
|
154
|
+
//# sourceMappingURL=MetaTitleComponent.js.map
|