@payloadcms/plugin-seo 3.0.0-canary.8223f17 → 3.0.0-canary.852f9fc
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} +35 -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} +46 -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} +36 -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} +19 -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/index.d.ts.map +1 -1
- package/dist/index.js +56 -112
- package/dist/index.js.map +1 -1
- package/dist/translations/index.d.ts +44 -0
- package/dist/translations/index.d.ts.map +1 -1
- package/dist/translations/index.js +44 -0
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/it.json +22 -0
- package/dist/translations/ru.json +22 -0
- package/dist/types.d.ts +15 -10
- 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/dist/ui/Pill.js.map +1 -1
- package/package.json +33 -23
- 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/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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/MetaTitle/MetaTitleComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldType, Options } from '@payloadcms/ui'\nimport type { TextFieldProps } from 'payload'\n\nimport {\n FieldLabel,\n TextInput,\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 { GenerateTitle } from '../../types.js'\n\nimport { defaults } from '../../defaults.js'\nimport { LengthIndicator } from '../../ui/LengthIndicator.js'\nimport '../index.scss'\n\nconst { maxLength, minLength } = defaults.title\n\ntype MetaTitleProps = {\n readonly hasGenerateTitleFn: boolean\n} & TextFieldProps\n\nexport const MetaTitleComponent: React.FC<MetaTitleProps> = (props) => {\n const {\n field: {\n admin: {\n components: { Label },\n },\n label,\n required,\n },\n hasGenerateTitleFn,\n labelProps,\n } = props || {}\n const { path: pathFromContext } = useFieldProps()\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const field: FieldType<string> = useField({\n path: pathFromContext,\n } as Options)\n\n const locale = useLocale()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const { errorMessage, setValue, showError, value } = field\n\n const regenerateTitle = useCallback(async () => {\n if (!hasGenerateTitleFn) {\n return\n }\n\n const genTitleResponse = await fetch('/api/plugin-seo/generate-title', {\n body: JSON.stringify({\n id: docInfo.id,\n slug: docInfo.slug,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\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<GenerateTitle>[0], 'req'>),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: generatedTitle } = await genTitleResponse.json()\n\n setValue(generatedTitle || '')\n }, [hasGenerateTitleFn, 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 {hasGenerateTitleFn && (\n <React.Fragment>\n — \n <button\n onClick={() => {\n void regenerateTitle()\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:lengthTipTitle', { maxLength, minLength })}\n <a\n href=\"https://developers.google.com/search/docs/advanced/appearance/title-link#page-titles\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {t('plugin-seo:bestPractices')}\n </a>\n .\n </div>\n </div>\n <div\n style={{\n marginBottom: '10px',\n position: 'relative',\n }}\n >\n <TextInput\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","TextInput","useDocumentInfo","useField","useFieldProps","useForm","useLocale","useTranslation","React","useCallback","defaults","LengthIndicator","maxLength","minLength","title","MetaTitleComponent","props","field","admin","components","Label","label","required","hasGenerateTitleFn","labelProps","path","pathFromContext","t","locale","getData","docInfo","errorMessage","setValue","showError","value","regenerateTitle","genTitleResponse","fetch","body","JSON","stringify","id","slug","doc","docPermissions","hasPublishPermission","hasSavePermission","initialData","initialState","code","credentials","headers","method","result","generatedTitle","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,SAAS,EACTC,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;AAC7D,OAAO,gBAAe;AAEtB,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGH,SAASI,KAAK;AAM/C,OAAO,MAAMC,qBAA+C,CAACC;IAC3D,MAAM,EACJC,OAAO,EACLC,OAAO,EACLC,YAAY,EAAEC,KAAK,EAAE,EACtB,EACDC,KAAK,EACLC,QAAQ,EACT,EACDC,kBAAkB,EAClBC,UAAU,EACX,GAAGR,SAAS,CAAC;IACd,MAAM,EAAES,MAAMC,eAAe,EAAE,GAAGtB;IAElC,MAAM,EAAEuB,CAAC,EAAE,GAAGpB;IAEd,MAAMU,QAA2Bd,SAAS;QACxCsB,MAAMC;IACR;IAEA,MAAME,SAAStB;IACf,MAAM,EAAEuB,OAAO,EAAE,GAAGxB;IACpB,MAAMyB,UAAU5B;IAEhB,MAAM,EAAE6B,YAAY,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,KAAK,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T;;4BAECxC,EAAE,6BAA6B;gCAAEf;gCAAWC;4BAAU;0CACvD,KAAC2D;gCACCC,MAAK;gCACLC,KAAI;gCACJC,QAAO;0CAENhD,EAAE;;4BACD;;;;;0BAIR,KAAC6B;gBACCC,OAAO;oBACLC,cAAc;oBACdC,UAAU;gBACZ;0BAEA,cAAA,KAAC1D;oBACC2E,OAAO;wBACLL,MAAM;wBACNM,WAAW;wBACXC,mBAAmB/C;oBACrB;oBACAV,OAAOA;oBACP0D,UAAU/C;oBACVP,MAAMC;oBACNJ,UAAUA;oBACVW,WAAWA;oBACXwB,OAAO;wBACLC,cAAc;oBAChB;oBACAxB,OAAOA;;;0BAGX,KAACsB;gBACCC,OAAO;oBACLuB,YAAY;oBACZC,SAAS;oBACTC,OAAO;gBACT;0BAEA,cAAA,KAACvE;oBAAgBC,WAAWA;oBAAWC,WAAWA;oBAAWsE,MAAMjD;;;;;AAI3E,EAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TextField } 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<TextField>;
|
|
8
|
+
}
|
|
9
|
+
type FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextField;
|
|
10
|
+
export declare const MetaTitleField: FieldFunction;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/MetaTitle/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,UAAU,kBAAkB;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;CAC/B;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,SAAS,CAAA;AAEpF,eAAO,MAAM,cAAc,EAAE,aAiB5B,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const MetaTitleField = ({ hasGenerateFn = false, overrides })=>{
|
|
2
|
+
return {
|
|
3
|
+
name: 'title',
|
|
4
|
+
type: 'text',
|
|
5
|
+
admin: {
|
|
6
|
+
components: {
|
|
7
|
+
Field: {
|
|
8
|
+
clientProps: {
|
|
9
|
+
hasGenerateTitleFn: hasGenerateFn
|
|
10
|
+
},
|
|
11
|
+
path: '@payloadcms/plugin-seo/client#MetaTitleComponent'
|
|
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/MetaTitle/index.ts"],"sourcesContent":["import type { TextField } 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<TextField>\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => TextField\n\nexport const MetaTitleField: FieldFunction = ({ hasGenerateFn = false, overrides }) => {\n return {\n name: 'title',\n type: 'text',\n admin: {\n components: {\n Field: {\n clientProps: {\n hasGenerateTitleFn: hasGenerateFn,\n },\n path: '@payloadcms/plugin-seo/client#MetaTitleComponent',\n },\n },\n },\n localized: true,\n ...((overrides as unknown as TextField) ?? {}),\n }\n}\n"],"names":["MetaTitleField","hasGenerateFn","overrides","name","type","admin","components","Field","clientProps","hasGenerateTitleFn","path","localized"],"mappings":"AAYA,OAAO,MAAMA,iBAAgC,CAAC,EAAEC,gBAAgB,KAAK,EAAEC,SAAS,EAAE;IAChF,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXC,oBAAoBR;oBACtB;oBACAS,MAAM;gBACR;YACF;QACF;QACAC,WAAW;QACX,GAAI,AAACT,aAAsC,CAAC,CAAC;IAC/C;AACF,EAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UIField } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type OverviewProps = {
|
|
4
|
+
descriptionPath?: string;
|
|
5
|
+
imagePath?: string;
|
|
6
|
+
titlePath?: string;
|
|
7
|
+
} & UIField;
|
|
8
|
+
export declare const OverviewComponent: React.FC<OverviewProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=OverviewComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OverviewComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/Overview/OverviewComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,SAAS,CAAA;AAGjD,OAAO,KAA2C,MAAM,OAAO,CAAA;AAW/D,KAAK,aAAa,GAAG;IACnB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAA;AAEX,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA6DrD,CAAA"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useAllFormFields, useForm } from '@payloadcms/ui
|
|
4
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
|
3
|
+
import { useAllFormFields, useForm, useTranslation } from '@payloadcms/ui';
|
|
5
4
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
6
|
-
import { defaults } from '
|
|
5
|
+
import { defaults } from '../../defaults.js';
|
|
7
6
|
const { description: { maxLength: maxDesc, minLength: minDesc }, title: { maxLength: maxTitle, minLength: minTitle } } = defaults;
|
|
8
|
-
export const
|
|
7
|
+
export const OverviewComponent = ({ descriptionPath: descriptionPathFromContext, imagePath: imagePathFromContext, titlePath: titlePathFromContext })=>{
|
|
9
8
|
const { // dispatchFields,
|
|
10
9
|
getFields } = useForm();
|
|
11
|
-
const
|
|
10
|
+
const descriptionPath = descriptionPathFromContext || 'meta.description';
|
|
11
|
+
const titlePath = titlePathFromContext || 'meta.title';
|
|
12
|
+
const imagePath = imagePathFromContext || 'meta.image';
|
|
13
|
+
const [{ [descriptionPath]: { value: metaDesc } = {}, [imagePath]: { value: metaImage } = {}, [titlePath]: { value: metaTitle } = {} }] = useAllFormFields();
|
|
12
14
|
const { t } = useTranslation();
|
|
13
15
|
const [titleIsValid, setTitleIsValid] = useState();
|
|
14
16
|
const [descIsValid, setDescIsValid] = useState();
|
|
15
17
|
const [imageIsValid, setImageIsValid] = useState();
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
18
|
const resetAll = useCallback(()=>{
|
|
18
19
|
const fields = getFields();
|
|
19
20
|
const fieldsWithoutMeta = fields;
|
|
@@ -25,8 +26,12 @@ export const Overview = ()=>{
|
|
|
25
26
|
getFields
|
|
26
27
|
]);
|
|
27
28
|
useEffect(()=>{
|
|
28
|
-
if (typeof metaTitle === 'string')
|
|
29
|
-
|
|
29
|
+
if (typeof metaTitle === 'string') {
|
|
30
|
+
setTitleIsValid(metaTitle.length >= minTitle && metaTitle.length <= maxTitle);
|
|
31
|
+
}
|
|
32
|
+
if (typeof metaDesc === 'string') {
|
|
33
|
+
setDescIsValid(metaDesc.length >= minDesc && metaDesc.length <= maxDesc);
|
|
34
|
+
}
|
|
30
35
|
setImageIsValid(Boolean(metaImage));
|
|
31
36
|
}, [
|
|
32
37
|
metaTitle,
|
|
@@ -52,4 +57,4 @@ export const Overview = ()=>{
|
|
|
52
57
|
});
|
|
53
58
|
};
|
|
54
59
|
|
|
55
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingURL=OverviewComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Overview/OverviewComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FormField, UIField } from 'payload'\n\nimport { useAllFormFields, useForm, useTranslation } from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\n\nimport { defaults } from '../../defaults.js'\n\nconst {\n description: { maxLength: maxDesc, minLength: minDesc },\n title: { maxLength: maxTitle, minLength: minTitle },\n} = defaults\n\ntype OverviewProps = {\n descriptionPath?: string\n imagePath?: string\n titlePath?: string\n} & UIField\n\nexport const OverviewComponent: React.FC<OverviewProps> = ({\n descriptionPath: descriptionPathFromContext,\n imagePath: imagePathFromContext,\n titlePath: titlePathFromContext,\n}) => {\n const {\n // dispatchFields,\n getFields,\n } = useForm()\n\n const descriptionPath = descriptionPathFromContext || 'meta.description'\n const titlePath = titlePathFromContext || 'meta.title'\n const imagePath = imagePathFromContext || 'meta.image'\n\n const [\n {\n [descriptionPath]: { value: metaDesc } = {} as FormField,\n [imagePath]: { value: metaImage } = {} as FormField,\n [titlePath]: { value: metaTitle } = {} as FormField,\n },\n ] = useAllFormFields()\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const [titleIsValid, setTitleIsValid] = useState<boolean | undefined>()\n const [descIsValid, setDescIsValid] = useState<boolean | undefined>()\n const [imageIsValid, setImageIsValid] = useState<boolean | undefined>()\n\n const resetAll = useCallback(() => {\n const fields = getFields()\n const fieldsWithoutMeta = fields\n fieldsWithoutMeta['meta.title'].value = ''\n fieldsWithoutMeta['meta.description'].value = ''\n fieldsWithoutMeta['meta.image'].value = ''\n // dispatchFields(fieldsWithoutMeta);\n }, [getFields])\n\n useEffect(() => {\n if (typeof metaTitle === 'string') {\n setTitleIsValid(metaTitle.length >= minTitle && metaTitle.length <= maxTitle)\n }\n if (typeof metaDesc === 'string') {\n setDescIsValid(metaDesc.length >= minDesc && metaDesc.length <= maxDesc)\n }\n setImageIsValid(Boolean(metaImage))\n }, [metaTitle, metaDesc, metaImage])\n\n const testResults = [titleIsValid, descIsValid, imageIsValid]\n\n const numberOfPasses = testResults.filter(Boolean).length\n\n return (\n <div\n style={{\n marginBottom: '20px',\n }}\n >\n <div>\n {t('plugin-seo:checksPassing', { current: numberOfPasses, max: testResults.length })}\n </div>\n </div>\n )\n}\n"],"names":["useAllFormFields","useForm","useTranslation","React","useCallback","useEffect","useState","defaults","description","maxLength","maxDesc","minLength","minDesc","title","maxTitle","minTitle","OverviewComponent","descriptionPath","descriptionPathFromContext","imagePath","imagePathFromContext","titlePath","titlePathFromContext","getFields","value","metaDesc","metaImage","metaTitle","t","titleIsValid","setTitleIsValid","descIsValid","setDescIsValid","imageIsValid","setImageIsValid","resetAll","fields","fieldsWithoutMeta","length","Boolean","testResults","numberOfPasses","filter","div","style","marginBottom","current","max"],"mappings":"AAAA;;AAIA,SAASA,gBAAgB,EAAEC,OAAO,EAAEC,cAAc,QAAQ,iBAAgB;AAC1E,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAI/D,SAASC,QAAQ,QAAQ,oBAAmB;AAE5C,MAAM,EACJC,aAAa,EAAEC,WAAWC,OAAO,EAAEC,WAAWC,OAAO,EAAE,EACvDC,OAAO,EAAEJ,WAAWK,QAAQ,EAAEH,WAAWI,QAAQ,EAAE,EACpD,GAAGR;AAQJ,OAAO,MAAMS,oBAA6C,CAAC,EACzDC,iBAAiBC,0BAA0B,EAC3CC,WAAWC,oBAAoB,EAC/BC,WAAWC,oBAAoB,EAChC;IACC,MAAM,EACJ,mBAAmB;IACnBC,SAA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;sBACEf,EAAE,4BAA4B;gBAAEkB,SAASL;gBAAgBM,KAAKP,YAAYF,MAAM;YAAC;;;AAI1F,EAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { UIField } from 'payload';
|
|
2
|
+
interface FieldFunctionProps {
|
|
3
|
+
/**
|
|
4
|
+
* Path to the description field to use for the preview
|
|
5
|
+
*
|
|
6
|
+
* @default 'meta.description'
|
|
7
|
+
*/
|
|
8
|
+
descriptionPath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Path to the image field to use for the preview
|
|
11
|
+
*
|
|
12
|
+
* @default 'meta.image'
|
|
13
|
+
*/
|
|
14
|
+
imagePath?: string;
|
|
15
|
+
overrides?: Partial<UIField>;
|
|
16
|
+
/**
|
|
17
|
+
* Path to the title field to use for the preview
|
|
18
|
+
*
|
|
19
|
+
* @default 'meta.title'
|
|
20
|
+
*/
|
|
21
|
+
titlePath?: string;
|
|
22
|
+
}
|
|
23
|
+
type FieldFunction = ({ overrides }: FieldFunctionProps) => UIField;
|
|
24
|
+
export declare const OverviewField: FieldFunction;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Overview/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAA;AAEnE,eAAO,MAAM,aAAa,EAAE,aAwB3B,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const OverviewField = ({ descriptionPath, imagePath, overrides, titlePath })=>{
|
|
2
|
+
return {
|
|
3
|
+
name: 'overview',
|
|
4
|
+
type: 'ui',
|
|
5
|
+
admin: {
|
|
6
|
+
components: {
|
|
7
|
+
Field: {
|
|
8
|
+
clientProps: {
|
|
9
|
+
descriptionPath,
|
|
10
|
+
imagePath,
|
|
11
|
+
titlePath
|
|
12
|
+
},
|
|
13
|
+
path: '@payloadcms/plugin-seo/client#OverviewComponent'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
label: 'Overview',
|
|
18
|
+
...overrides ?? {}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Overview/index.tsx"],"sourcesContent":["import type { UIField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Path to the description field to use for the preview\n *\n * @default 'meta.description'\n */\n descriptionPath?: string\n /**\n * Path to the image field to use for the preview\n *\n * @default 'meta.image'\n */\n imagePath?: string\n overrides?: Partial<UIField>\n /**\n * Path to the title field to use for the preview\n *\n * @default 'meta.title'\n */\n titlePath?: string\n}\n\ntype FieldFunction = ({ overrides }: FieldFunctionProps) => UIField\n\nexport const OverviewField: FieldFunction = ({\n descriptionPath,\n imagePath,\n overrides,\n titlePath,\n}) => {\n return {\n name: 'overview',\n type: 'ui',\n admin: {\n components: {\n Field: {\n clientProps: {\n descriptionPath,\n imagePath,\n titlePath,\n },\n path: '@payloadcms/plugin-seo/client#OverviewComponent',\n },\n },\n },\n label: 'Overview',\n ...((overrides as unknown as UIField) ?? {}),\n }\n}\n"],"names":["OverviewField","descriptionPath","imagePath","overrides","titlePath","name","type","admin","components","Field","clientProps","path","label"],"mappings":"AA0BA,OAAO,MAAMA,gBAA+B,CAAC,EAC3CC,eAAe,EACfC,SAAS,EACTC,SAAS,EACTC,SAAS,EACV;IACC,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXT;wBACAC;wBACAE;oBACF;oBACAO,MAAM;gBACR;YACF;QACF;QACAC,OAAO;QACP,GAAI,AAACT,aAAoC,CAAC,CAAC;IAC7C;AACF,EAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UIField } from 'payload';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type PreviewProps = {
|
|
4
|
+
readonly descriptionPath?: string;
|
|
5
|
+
readonly hasGenerateURLFn: boolean;
|
|
6
|
+
readonly titlePath?: string;
|
|
7
|
+
} & UIField;
|
|
8
|
+
export declare const PreviewComponent: React.FC<PreviewProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=PreviewComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviewComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/Preview/PreviewComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,SAAS,CAAA;AASjD,OAAO,KAA8B,MAAM,OAAO,CAAA;AAKlD,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAA;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B,GAAG,OAAO,CAAA;AAEX,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA+GnD,CAAA"}
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useAllFormFields } from '@payloadcms/ui
|
|
4
|
-
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
|
5
|
-
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
|
6
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
|
3
|
+
import { useAllFormFields, useDocumentInfo, useForm, useLocale, useTranslation } from '@payloadcms/ui';
|
|
7
4
|
import React, { useEffect, useState } from 'react';
|
|
8
|
-
export const
|
|
5
|
+
export const PreviewComponent = (props)=>{
|
|
6
|
+
const { descriptionPath: descriptionPathFromContext, hasGenerateURLFn, titlePath: titlePathFromContext } = props;
|
|
9
7
|
const { t } = useTranslation();
|
|
10
8
|
const locale = useLocale();
|
|
11
9
|
const [fields] = useAllFormFields();
|
|
10
|
+
const { getData } = useForm();
|
|
12
11
|
const docInfo = useDocumentInfo();
|
|
13
|
-
const
|
|
12
|
+
const descriptionPath = descriptionPathFromContext || 'meta.description';
|
|
13
|
+
const titlePath = titlePathFromContext || 'meta.title';
|
|
14
|
+
const { [descriptionPath]: { value: metaDescription } = {}, [titlePath]: { value: metaTitle } = {} } = fields;
|
|
14
15
|
const [href, setHref] = useState();
|
|
15
16
|
useEffect(()=>{
|
|
16
17
|
const getHref = async ()=>{
|
|
17
18
|
const genURLResponse = await fetch('/api/plugin-seo/generate-url', {
|
|
18
19
|
body: JSON.stringify({
|
|
19
|
-
|
|
20
|
-
doc:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
id: docInfo.id,
|
|
21
|
+
doc: getData(),
|
|
22
|
+
docPermissions: docInfo.docPermissions,
|
|
23
|
+
hasPublishPermission: docInfo.hasPublishPermission,
|
|
24
|
+
hasSavePermission: docInfo.hasSavePermission,
|
|
25
|
+
initialData: docInfo.initialData,
|
|
26
|
+
initialState: docInfo.initialState,
|
|
27
|
+
locale: typeof locale === 'object' ? locale?.code : locale,
|
|
28
|
+
title: docInfo.title
|
|
24
29
|
}),
|
|
25
30
|
credentials: 'include',
|
|
26
31
|
headers: {
|
|
@@ -39,7 +44,8 @@ export const Preview = ({ hasGenerateURLFn })=>{
|
|
|
39
44
|
href,
|
|
40
45
|
locale,
|
|
41
46
|
docInfo,
|
|
42
|
-
hasGenerateURLFn
|
|
47
|
+
hasGenerateURLFn,
|
|
48
|
+
getData
|
|
43
49
|
]);
|
|
44
50
|
return /*#__PURE__*/ _jsxs("div", {
|
|
45
51
|
children: [
|
|
@@ -97,4 +103,4 @@ export const Preview = ({ hasGenerateURLFn })=>{
|
|
|
97
103
|
});
|
|
98
104
|
};
|
|
99
105
|
|
|
100
|
-
//# sourceMappingURL=
|
|
106
|
+
//# sourceMappingURL=PreviewComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Preview/PreviewComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FormField, UIField } from 'payload'\n\nimport {\n useAllFormFields,\n useDocumentInfo,\n useForm,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useEffect, useState } from 'react'\n\nimport type { PluginSEOTranslationKeys, PluginSEOTranslations } from '../../translations/index.js'\nimport type { GenerateURL } from '../../types.js'\n\ntype PreviewProps = {\n readonly descriptionPath?: string\n readonly hasGenerateURLFn: boolean\n readonly titlePath?: string\n} & UIField\n\nexport const PreviewComponent: React.FC<PreviewProps> = (props) => {\n const {\n descriptionPath: descriptionPathFromContext,\n hasGenerateURLFn,\n titlePath: titlePathFromContext,\n } = props\n\n const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()\n\n const locale = useLocale()\n const [fields] = useAllFormFields()\n const { getData } = useForm()\n const docInfo = useDocumentInfo()\n\n const descriptionPath = descriptionPathFromContext || 'meta.description'\n const titlePath = titlePathFromContext || 'meta.title'\n\n const {\n [descriptionPath]: { value: metaDescription } = {} as FormField,\n [titlePath]: { value: metaTitle } = {} as FormField,\n } = fields\n\n const [href, setHref] = useState<string>()\n\n useEffect(() => {\n const getHref = async () => {\n const genURLResponse = await fetch('/api/plugin-seo/generate-url', {\n body: JSON.stringify({\n id: docInfo.id,\n doc: getData(),\n docPermissions: docInfo.docPermissions,\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<GenerateURL>[0], 'req'>),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n })\n\n const { result: newHref } = await genURLResponse.json()\n\n setHref(newHref)\n }\n\n if (hasGenerateURLFn && !href) {\n void getHref()\n }\n }, [fields, href, locale, docInfo, hasGenerateURLFn, getData])\n\n return (\n <div>\n <div>{t('plugin-seo:preview')}</div>\n <div\n style={{\n color: '#9A9A9A',\n marginBottom: '5px',\n }}\n >\n {t('plugin-seo:previewDescription')}\n </div>\n <div\n style={{\n background: 'var(--theme-elevation-50)',\n borderRadius: '5px',\n boxShadow: '0px 0px 10px rgba(0, 0, 0, 0.1)',\n maxWidth: '600px',\n padding: '20px',\n pointerEvents: 'none',\n width: '100%',\n }}\n >\n <div>\n <a\n href={href}\n style={{\n textDecoration: 'none',\n }}\n >\n {href || 'https://...'}\n </a>\n </div>\n <h4\n style={{\n margin: 0,\n }}\n >\n <a\n href=\"/\"\n style={{\n textDecoration: 'none',\n }}\n >\n {metaTitle as string}\n </a>\n </h4>\n <p\n style={{\n margin: 0,\n }}\n >\n {metaDescription as string}\n </p>\n </div>\n </div>\n )\n}\n"],"names":["useAllFormFields","useDocumentInfo","useForm","useLocale","useTranslation","React","useEffect","useState","PreviewComponent","props","descriptionPath","descriptionPathFromContext","hasGenerateURLFn","titlePath","titlePathFromContext","t","locale","fields","getData","docInfo","value","metaDescription","metaTitle","href","setHref","getHref","genURLResponse","fetch","body","JSON","stringify","id","doc","docPermissions","hasPublishPermission","hasSavePermission","initialData","initialState","code","title","credentials","headers","method","result","newHref","json","div","style","color","marginBottom","background","borderRadius","boxShadow","maxWidth","padding","pointerEvents","width","a","text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AAG,MAAMlB,eAAemB,IAAI;YAErDrB,QAAQoB;QACV;QAEA,IAAIhC,oBAAoB,CAACW,MAAM;YAC7B,KAAKE;QACP;IACF,GAAG;QAACR;QAAQM;QAAMP;QAAQG;QAASP;QAAkBM;KAAQ;IAE7D,qBACE,MAAC4B;;0BACC,KAACA;0BAAK/B,EAAE;;0BACR,KAAC+B;gBACCC,OAAO;oBACLC,OAAO;oBACPC,cAAc;gBAChB;0BAEClC,EAAE;;0BAEL,MAAC+B;gBACCC,OAAO;oBACLG,YAAY;oBACZC,cAAc;oBACdC,WAAW;oBACXC,UAAU;oBACVC,SAAS;oBACTC,eAAe;oBACfC,OAAO;gBACT;;kCAEA,KAACV;kCACC,cAAA,KAACW;4BACClC,MAAMA;4BACNwB,OAAO;gCACLW,gBAAgB;4BAClB;sCAECnC,QAAQ;;;kCAGb,KAACoC;wBACCZ,OAAO;4BACLa,QAAQ;wBACV;kCAEA,cAAA,KAACH;4BACClC,MAAK;4BACLwB,OAAO;gCACLW,gBAAgB;4BAClB;sCAECpC;;;kCAGL,KAACuC;wBACCd,OAAO;4BACLa,QAAQ;wBACV;kCAECvC;;;;;;AAKX,EAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { UIField } from 'payload';
|
|
2
|
+
interface FieldFunctionProps {
|
|
3
|
+
/**
|
|
4
|
+
* Path to the description field to use for the preview
|
|
5
|
+
*
|
|
6
|
+
* @default 'meta.description'
|
|
7
|
+
*/
|
|
8
|
+
descriptionPath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Tell the component if the generate function is available as configured in the plugin config
|
|
11
|
+
*/
|
|
12
|
+
hasGenerateFn?: boolean;
|
|
13
|
+
overrides?: Partial<UIField>;
|
|
14
|
+
/**
|
|
15
|
+
* Path to the title field to use for the preview
|
|
16
|
+
*
|
|
17
|
+
* @default 'meta.title'
|
|
18
|
+
*/
|
|
19
|
+
titlePath?: string;
|
|
20
|
+
}
|
|
21
|
+
type FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UIField;
|
|
22
|
+
export declare const PreviewField: FieldFunction;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Preview/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAA;AAElF,eAAO,MAAM,YAAY,EAAE,aAwB1B,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const PreviewField = ({ descriptionPath, hasGenerateFn = false, overrides, titlePath })=>{
|
|
2
|
+
return {
|
|
3
|
+
name: 'preview',
|
|
4
|
+
type: 'ui',
|
|
5
|
+
admin: {
|
|
6
|
+
components: {
|
|
7
|
+
Field: {
|
|
8
|
+
clientProps: {
|
|
9
|
+
descriptionPath,
|
|
10
|
+
hasGenerateURLFn: hasGenerateFn,
|
|
11
|
+
titlePath
|
|
12
|
+
},
|
|
13
|
+
path: '@payloadcms/plugin-seo/client#PreviewComponent'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
label: 'Preview',
|
|
18
|
+
...overrides ?? {}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Preview/index.tsx"],"sourcesContent":["import type { UIField } from 'payload'\n\ninterface FieldFunctionProps {\n /**\n * Path to the description field to use for the preview\n *\n * @default 'meta.description'\n */\n descriptionPath?: string\n /**\n * Tell the component if the generate function is available as configured in the plugin config\n */\n hasGenerateFn?: boolean\n overrides?: Partial<UIField>\n /**\n * Path to the title field to use for the preview\n *\n * @default 'meta.title'\n */\n titlePath?: string\n}\n\ntype FieldFunction = ({ hasGenerateFn, overrides }: FieldFunctionProps) => UIField\n\nexport const PreviewField: FieldFunction = ({\n descriptionPath,\n hasGenerateFn = false,\n overrides,\n titlePath,\n}) => {\n return {\n name: 'preview',\n type: 'ui',\n admin: {\n components: {\n Field: {\n clientProps: {\n descriptionPath,\n hasGenerateURLFn: hasGenerateFn,\n titlePath,\n },\n path: '@payloadcms/plugin-seo/client#PreviewComponent',\n },\n },\n },\n label: 'Preview',\n ...((overrides as unknown as UIField) ?? {}),\n }\n}\n"],"names":["PreviewField","descriptionPath","hasGenerateFn","overrides","titlePath","name","type","admin","components","Field","clientProps","hasGenerateURLFn","path","label"],"mappings":"AAwBA,OAAO,MAAMA,eAA8B,CAAC,EAC1CC,eAAe,EACfC,gBAAgB,KAAK,EACrBC,SAAS,EACTC,SAAS,EACV;IACC,OAAO;QACLC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,YAAY;gBACVC,OAAO;oBACLC,aAAa;wBACXT;wBACAU,kBAAkBT;wBAClBE;oBACF;oBACAQ,MAAM;gBACR;YACF;QACF;QACAC,OAAO;QACP,GAAI,AAACV,aAAoC,CAAC,CAAC;IAC7C;AACF,EAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAoC,MAAM,SAAS,CAAA;AAIvE,OAAO,KAAK,EAKV,eAAe,EAChB,MAAM,YAAY,CAAA;AASnB,eAAO,MAAM,SAAS,iBACL,eAAe,cACrB,MAAM,KAAG,MA+OjB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,102 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { deepMergeSimple } from 'payload/shared';
|
|
2
|
+
import { MetaDescriptionField } from './fields/MetaDescription/index.js';
|
|
3
|
+
import { MetaImageField } from './fields/MetaImage/index.js';
|
|
4
|
+
import { MetaTitleField } from './fields/MetaTitle/index.js';
|
|
5
|
+
import { OverviewField } from './fields/Overview/index.js';
|
|
6
|
+
import { PreviewField } from './fields/Preview/index.js';
|
|
7
7
|
import { translations } from './translations/index.js';
|
|
8
|
-
import { Overview } from './ui/Overview.js';
|
|
9
|
-
import { Preview } from './ui/Preview.js';
|
|
10
8
|
export const seoPlugin = (pluginConfig)=>(config)=>{
|
|
11
9
|
const seoFields = [
|
|
12
10
|
{
|
|
13
11
|
name: 'meta',
|
|
14
12
|
type: 'group',
|
|
15
13
|
fields: [
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'title',
|
|
28
|
-
type: 'text',
|
|
29
|
-
admin: {
|
|
30
|
-
components: {
|
|
31
|
-
Field: withMergedProps({
|
|
32
|
-
Component: MetaTitle,
|
|
33
|
-
sanitizeServerOnlyProps: true,
|
|
34
|
-
toMergeIntoProps: {
|
|
35
|
-
hasGenerateTitleFn: typeof pluginConfig?.generateTitle === 'function'
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
localized: true,
|
|
41
|
-
...pluginConfig?.fieldOverrides?.title ?? {}
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'description',
|
|
45
|
-
type: 'textarea',
|
|
46
|
-
admin: {
|
|
47
|
-
components: {
|
|
48
|
-
Field: withMergedProps({
|
|
49
|
-
Component: MetaDescription,
|
|
50
|
-
sanitizeServerOnlyProps: true,
|
|
51
|
-
toMergeIntoProps: {
|
|
52
|
-
hasGenerateDescriptionFn: typeof pluginConfig?.generateDescription === 'function'
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
localized: true,
|
|
58
|
-
...pluginConfig?.fieldOverrides?.description ?? {}
|
|
59
|
-
},
|
|
14
|
+
OverviewField({}),
|
|
15
|
+
MetaTitleField({
|
|
16
|
+
hasGenerateFn: typeof pluginConfig?.generateTitle === 'function',
|
|
17
|
+
overrides: pluginConfig?.fieldOverrides?.title
|
|
18
|
+
}),
|
|
19
|
+
MetaDescriptionField({
|
|
20
|
+
hasGenerateFn: typeof pluginConfig?.generateDescription === 'function',
|
|
21
|
+
overrides: pluginConfig?.fieldOverrides?.description
|
|
22
|
+
}),
|
|
60
23
|
...pluginConfig?.uploadsCollection ? [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
components: {
|
|
67
|
-
Field: withMergedProps({
|
|
68
|
-
Component: MetaImage,
|
|
69
|
-
sanitizeServerOnlyProps: true,
|
|
70
|
-
toMergeIntoProps: {
|
|
71
|
-
hasGenerateImageFn: typeof pluginConfig?.generateImage === 'function'
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
},
|
|
75
|
-
description: 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.'
|
|
76
|
-
},
|
|
77
|
-
label: 'Meta Image',
|
|
78
|
-
localized: true,
|
|
79
|
-
relationTo: pluginConfig?.uploadsCollection,
|
|
80
|
-
...pluginConfig?.fieldOverrides?.image ?? {}
|
|
81
|
-
}
|
|
24
|
+
MetaImageField({
|
|
25
|
+
hasGenerateFn: typeof pluginConfig?.generateImage === 'function',
|
|
26
|
+
overrides: pluginConfig?.fieldOverrides?.image,
|
|
27
|
+
relationTo: pluginConfig.uploadsCollection
|
|
28
|
+
})
|
|
82
29
|
] : [],
|
|
83
30
|
...pluginConfig?.fields || [],
|
|
84
|
-
{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
admin: {
|
|
88
|
-
components: {
|
|
89
|
-
Field: withMergedProps({
|
|
90
|
-
Component: Preview,
|
|
91
|
-
sanitizeServerOnlyProps: true,
|
|
92
|
-
toMergeIntoProps: {
|
|
93
|
-
hasGenerateURLFn: typeof pluginConfig?.generateURL === 'function'
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
label: 'Preview'
|
|
99
|
-
}
|
|
31
|
+
PreviewField({
|
|
32
|
+
hasGenerateFn: typeof pluginConfig?.generateURL === 'function'
|
|
33
|
+
})
|
|
100
34
|
],
|
|
101
35
|
interfaceName: pluginConfig.interfaceName,
|
|
102
36
|
label: 'SEO'
|
|
@@ -168,11 +102,14 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
|
|
|
168
102
|
...config.endpoints ?? [],
|
|
169
103
|
{
|
|
170
104
|
handler: async (req)=>{
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const result = pluginConfig.generateTitle ? await pluginConfig.generateTitle(
|
|
105
|
+
const data = await req.json();
|
|
106
|
+
if (data) {
|
|
107
|
+
req.data = data;
|
|
108
|
+
}
|
|
109
|
+
const result = pluginConfig.generateTitle ? await pluginConfig.generateTitle({
|
|
110
|
+
...req.data,
|
|
111
|
+
req
|
|
112
|
+
}) : '';
|
|
176
113
|
return new Response(JSON.stringify({
|
|
177
114
|
result
|
|
178
115
|
}), {
|
|
@@ -184,11 +121,14 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
|
|
|
184
121
|
},
|
|
185
122
|
{
|
|
186
123
|
handler: async (req)=>{
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const result = pluginConfig.generateDescription ? await pluginConfig.generateDescription(
|
|
124
|
+
const data = await req.json();
|
|
125
|
+
if (data) {
|
|
126
|
+
req.data = data;
|
|
127
|
+
}
|
|
128
|
+
const result = pluginConfig.generateDescription ? await pluginConfig.generateDescription({
|
|
129
|
+
...req.data,
|
|
130
|
+
req
|
|
131
|
+
}) : '';
|
|
192
132
|
return new Response(JSON.stringify({
|
|
193
133
|
result
|
|
194
134
|
}), {
|
|
@@ -200,11 +140,14 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
|
|
|
200
140
|
},
|
|
201
141
|
{
|
|
202
142
|
handler: async (req)=>{
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const result = pluginConfig.generateURL ? await pluginConfig.generateURL(
|
|
143
|
+
const data = await req.json();
|
|
144
|
+
if (data) {
|
|
145
|
+
req.data = data;
|
|
146
|
+
}
|
|
147
|
+
const result = pluginConfig.generateURL ? await pluginConfig.generateURL({
|
|
148
|
+
...req.data,
|
|
149
|
+
req
|
|
150
|
+
}) : '';
|
|
208
151
|
return new Response(JSON.stringify({
|
|
209
152
|
result
|
|
210
153
|
}), {
|
|
@@ -216,11 +159,14 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
|
|
|
216
159
|
},
|
|
217
160
|
{
|
|
218
161
|
handler: async (req)=>{
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const result = pluginConfig.generateImage ? await pluginConfig.generateImage(
|
|
162
|
+
const data = await req.json();
|
|
163
|
+
if (data) {
|
|
164
|
+
req.data = data;
|
|
165
|
+
}
|
|
166
|
+
const result = pluginConfig.generateImage ? await pluginConfig.generateImage({
|
|
167
|
+
...req.data,
|
|
168
|
+
req
|
|
169
|
+
}) : '';
|
|
224
170
|
return new Response(result, {
|
|
225
171
|
status: 200
|
|
226
172
|
});
|
|
@@ -275,9 +221,7 @@ export const seoPlugin = (pluginConfig)=>(config)=>{
|
|
|
275
221
|
}) || [],
|
|
276
222
|
i18n: {
|
|
277
223
|
...config.i18n,
|
|
278
|
-
translations:
|
|
279
|
-
...deepMerge(translations, config.i18n?.translations)
|
|
280
|
-
}
|
|
224
|
+
translations: deepMergeSimple(translations, config.i18n?.translations)
|
|
281
225
|
}
|
|
282
226
|
};
|
|
283
227
|
};
|