@payload-enchants/translator 1.1.40 → 1.2.0-pre.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/client/components/CustomButton/CustomButtonWithTranslator.d.ts.map +1 -1
- package/dist/client/components/CustomButton/CustomButtonWithTranslator.js +1 -2
- package/dist/client/components/CustomButton/CustomButtonWithTranslator.js.map +1 -1
- package/dist/client/components/CustomButton/index.js +1 -1
- package/dist/client/components/CustomButton/index.js.map +1 -1
- package/dist/client/components/LocaleLabel/LocaleLabel.d.ts +1 -1
- package/dist/client/components/LocaleLabel/LocaleLabel.d.ts.map +1 -1
- package/dist/client/components/LocaleLabel/LocaleLabel.js +2 -3
- package/dist/client/components/LocaleLabel/LocaleLabel.js.map +1 -1
- package/dist/client/components/ResolverButton/ResolverButton.d.ts.map +1 -1
- package/dist/client/components/ResolverButton/ResolverButton.js +1 -2
- package/dist/client/components/ResolverButton/ResolverButton.js.map +1 -1
- package/dist/client/components/TranslatorModal/Content.d.ts.map +1 -1
- package/dist/client/components/TranslatorModal/Content.js +1 -2
- package/dist/client/components/TranslatorModal/Content.js.map +1 -1
- package/dist/client/components/TranslatorModal/TranslatorModal.js +1 -1
- package/dist/client/components/TranslatorModal/TranslatorModal.js.map +1 -1
- package/dist/client/providers/Translator/TranslatorProvider.d.ts.map +1 -1
- package/dist/client/providers/Translator/TranslatorProvider.js +2 -9
- package/dist/client/providers/Translator/TranslatorProvider.js.map +1 -1
- package/dist/client/providers/Translator/context.d.ts +1 -1
- package/dist/client/providers/Translator/context.d.ts.map +1 -1
- package/dist/client/providers/Translator/context.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/resolvers/types.d.ts +1 -1
- package/dist/resolvers/types.d.ts.map +1 -1
- package/dist/resolvers/types.js.map +1 -1
- package/dist/translate/endpoint.d.ts +1 -1
- package/dist/translate/endpoint.d.ts.map +1 -1
- package/dist/translate/endpoint.js +1 -1
- package/dist/translate/endpoint.js.map +1 -1
- package/dist/translate/findEntityWithConfig.d.ts +1 -1
- package/dist/translate/findEntityWithConfig.d.ts.map +1 -1
- package/dist/translate/findEntityWithConfig.js +1 -1
- package/dist/translate/findEntityWithConfig.js.map +1 -1
- package/dist/translate/operation.d.ts +1 -1
- package/dist/translate/operation.d.ts.map +1 -1
- package/dist/translate/operation.js +1 -1
- package/dist/translate/operation.js.map +1 -1
- package/dist/translate/traverseFields.d.ts +1 -1
- package/dist/translate/traverseFields.d.ts.map +1 -1
- package/dist/translate/traverseFields.js +1 -1
- package/dist/translate/traverseFields.js.map +1 -1
- package/dist/translate/updateEntity.d.ts +1 -1
- package/dist/translate/updateEntity.d.ts.map +1 -1
- package/dist/translate/updateEntity.js +1 -1
- package/dist/translate/updateEntity.js.map +1 -1
- package/package.json +7 -7
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CustomButtonWithTranslator.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"CustomButtonWithTranslator.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC,eAAO,MAAM,0BAA0B,sBAAuB;IAAE,aAAa,EAAE,SAAS,CAAA;CAAE,gUAoBzF,CAAC"}
|
@@ -1,8 +1,7 @@
|
|
1
1
|
'use client';
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
3
3
|
import './styles.scss';
|
4
|
-
import { useConfig } from '@payloadcms/ui
|
5
|
-
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
4
|
+
import { useConfig, useDocumentInfo } from '@payloadcms/ui';
|
6
5
|
import { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';
|
7
6
|
import { ResolverButton } from '../ResolverButton';
|
8
7
|
import { TranslatorModal } from '../TranslatorModal';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"sourcesContent":["'use client';\n\nimport './styles.scss';\n\nimport { useConfig
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"sourcesContent":["'use client';\n\nimport './styles.scss';\n\nimport { useConfig, useDocumentInfo } from '@payloadcms/ui';\nimport type { ReactNode } from 'react';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';\nimport { ResolverButton } from '../ResolverButton';\nimport { TranslatorModal } from '../TranslatorModal';\n\nexport const CustomButtonWithTranslator = ({ defaultButton }: { defaultButton: ReactNode }) => {\n const config = useConfig();\n\n const { globalSlug, id } = useDocumentInfo();\n\n const resolvers = (config.admin?.custom?.translator?.resolvers as TranslateResolver[]) ?? [];\n\n if (!id && !globalSlug) return defaultButton;\n\n return (\n <TranslatorProvider>\n <div className={'translator__custom-save-button'}>\n <TranslatorModal />\n {resolvers.map((resolver) => (\n <ResolverButton key={resolver.key} resolver={resolver} />\n ))}\n {defaultButton}\n </div>\n </TranslatorProvider>\n );\n};\n"],"names":["useConfig","useDocumentInfo","TranslatorProvider","ResolverButton","TranslatorModal","CustomButtonWithTranslator","defaultButton","config","globalSlug","id","resolvers","admin","custom","translator","div","className","map","resolver","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAEA,OAAO,gBAAgB;AAEvB,SAASA,SAAS,EAAEC,eAAe,QAAQ,iBAAiB;AAI5D,SAASC,kBAAkB,QAAQ,gDAAgD;AACnF,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,eAAe,QAAQ,qBAAqB;AAErD,OAAO,MAAMC,6BAA6B,CAAC,EAAEC,aAAa,EAAgC;IACxF,MAAMC,SAASP;IAEf,MAAM,EAAEQ,UAAU,EAAEC,EAAE,EAAE,GAAGR;IAE3B,MAAMS,YAAY,AAACH,OAAOI,KAAK,EAAEC,QAAQC,YAAYH,aAAqC,EAAE;IAE5F,IAAI,CAACD,MAAM,CAACD,YAAY,OAAOF;IAE/B,qBACE,KAACJ;kBACC,cAAA,MAACY;YAAIC,WAAW;;8BACd,KAACX;gBACAM,UAAUM,GAAG,CAAC,CAACC,yBACd,KAACd;wBAAkCc,UAAUA;uBAAxBA,SAASC,GAAG;gBAElCZ;;;;AAIT,EAAE"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { DefaultPublishButton } from '@payloadcms/ui
|
2
|
+
import { DefaultPublishButton } from '@payloadcms/ui';
|
3
3
|
import { DefaultSaveButton } from '@payloadcms/ui/elements/SaveButton';
|
4
4
|
import { CustomButtonWithTranslator } from './CustomButtonWithTranslator';
|
5
5
|
export const CustomButton = (type)=>{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/CustomButton/index.tsx"],"sourcesContent":["import { DefaultPublishButton } from '@payloadcms/ui
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/CustomButton/index.tsx"],"sourcesContent":["import { DefaultPublishButton } from '@payloadcms/ui';\nimport { DefaultSaveButton } from '@payloadcms/ui/elements/SaveButton';\n\nimport { CustomButtonWithTranslator } from './CustomButtonWithTranslator';\n\nexport const CustomButton = (type: 'publish' | 'save') => {\n return () => {\n const defaultButton = type === 'publish' ? <DefaultPublishButton /> : <DefaultSaveButton />;\n\n return <CustomButtonWithTranslator defaultButton={defaultButton} />;\n };\n};\n"],"names":["DefaultPublishButton","DefaultSaveButton","CustomButtonWithTranslator","CustomButton","type","defaultButton"],"rangeMappings":";;;;;;;;;;;","mappings":";AAAA,SAASA,oBAAoB,QAAQ,iBAAiB;AACtD,SAASC,iBAAiB,QAAQ,qCAAqC;AAEvE,SAASC,0BAA0B,QAAQ,+BAA+B;AAE1E,OAAO,MAAMC,eAAe,CAACC;IAC3B,OAAO;QACL,MAAMC,gBAAgBD,SAAS,0BAAY,KAACJ,0CAA0B,KAACC;QAEvE,qBAAO,KAACC;YAA2BG,eAAeA;;IACpD;AACF,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"LocaleLabel.d.ts","sourceRoot":"","sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"LocaleLabel.d.ts","sourceRoot":"","sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,eAAO,MAAM,WAAW,eAAgB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,gCAczD,CAAC"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { getTranslation } from '@payloadcms/translations';
|
3
|
-
import {
|
4
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
3
|
+
import { ChevronIcon, useTranslation } from '@payloadcms/ui';
|
5
4
|
const baseClass = 'localizer-button';
|
6
5
|
export const LocaleLabel = ({ locale })=>{
|
7
6
|
const { i18n, t } = useTranslation();
|
@@ -19,7 +18,7 @@ export const LocaleLabel = ({ locale })=>{
|
|
19
18
|
children: `${getTranslation(locale.label, i18n)}`
|
20
19
|
}),
|
21
20
|
" ",
|
22
|
-
/*#__PURE__*/ _jsx(
|
21
|
+
/*#__PURE__*/ _jsx(ChevronIcon, {
|
23
22
|
className: `${baseClass}__chevron`
|
24
23
|
})
|
25
24
|
]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport {
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport { ChevronIcon, useTranslation } from '@payloadcms/ui';\nimport type { Locale } from 'payload';\n\nconst baseClass = 'localizer-button';\n\nexport const LocaleLabel = ({ locale }: { locale: Locale }) => {\n const { i18n, t } = useTranslation();\n\n return (\n <div aria-label={t('general:locale')} className={baseClass}>\n <div className={`${baseClass}__label`}>{`${t('general:locale')}:`}</div>\n \n <span className={`${baseClass}__current-label`}>\n {`${getTranslation(locale.label, i18n)}`}\n </span>\n \n <ChevronIcon className={`${baseClass}__chevron`} />\n </div>\n );\n};\n"],"names":["getTranslation","ChevronIcon","useTranslation","baseClass","LocaleLabel","locale","i18n","t","div","aria-label","className","span","label"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,WAAW,EAAEC,cAAc,QAAQ,iBAAiB;AAG7D,MAAMC,YAAY;AAElB,OAAO,MAAMC,cAAc,CAAC,EAAEC,MAAM,EAAsB;IACxD,MAAM,EAAEC,IAAI,EAAEC,CAAC,EAAE,GAAGL;IAEpB,qBACE,MAACM;QAAIC,cAAYF,EAAE;QAAmBG,WAAWP;;0BAC/C,KAACK;gBAAIE,WAAW,CAAC,EAAEP,UAAU,OAAO,CAAC;0BAAG,CAAC,EAAEI,EAAE,kBAAkB,CAAC,CAAC;;YAAO;0BAExE,KAACI;gBAAKD,WAAW,CAAC,EAAEP,UAAU,eAAe,CAAC;0BAC3C,CAAC,EAAEH,eAAeK,OAAOO,KAAK,EAAEN,MAAM,CAAC;;YACnC;0BAEP,KAACL;gBAAYS,WAAW,CAAC,EAAEP,UAAU,SAAS,CAAC;;;;AAGrD,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ResolverButton.d.ts","sourceRoot":"","sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"ResolverButton.d.ts","sourceRoot":"","sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,eAAO,MAAM,cAAc,wCAExB;IACD,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,gCAYA,CAAC"}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { Button } from '@payloadcms/ui
|
3
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
2
|
+
import { Button, useTranslation } from '@payloadcms/ui';
|
4
3
|
import { useTranslator } from '../../providers/Translator/context';
|
5
4
|
export const ResolverButton = ({ resolver: { key: resolverKey } })=>{
|
6
5
|
const { openTranslator } = useTranslator();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"sourcesContent":["import { Button
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"sourcesContent":["import { Button, useTranslation } from '@payloadcms/ui';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport { useTranslator } from '../../providers/Translator/context';\n\nexport const ResolverButton = ({\n resolver: { key: resolverKey },\n}: {\n resolver: TranslateResolver;\n}) => {\n const { openTranslator } = useTranslator();\n\n const { t } = useTranslation();\n\n const handleClick = () => openTranslator({ resolverKey });\n\n return (\n <Button onClick={handleClick} size='small'>\n {t(`plugin-translator:resolver_${resolverKey}_buttonLabel` as Parameters<typeof t>[0])}\n </Button>\n );\n};\n"],"names":["Button","useTranslation","useTranslator","ResolverButton","resolver","key","resolverKey","openTranslator","t","handleClick","onClick","size"],"rangeMappings":";;;;;;;;;;;;;;","mappings":";AAAA,SAASA,MAAM,EAAEC,cAAc,QAAQ,iBAAiB;AAGxD,SAASC,aAAa,QAAQ,qCAAqC;AAEnE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,UAAU,EAAEC,KAAKC,WAAW,EAAE,EAG/B;IACC,MAAM,EAAEC,cAAc,EAAE,GAAGL;IAE3B,MAAM,EAAEM,CAAC,EAAE,GAAGP;IAEd,MAAMQ,cAAc,IAAMF,eAAe;YAAED;QAAY;IAEvD,qBACE,KAACN;QAAOU,SAASD;QAAaE,MAAK;kBAChCH,EAAE,CAAC,2BAA2B,EAAEF,YAAY,YAAY,CAAC;;AAGhE,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Content.d.ts","sourceRoot":"","sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"Content.d.ts","sourceRoot":"","sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,mCAwDnB,CAAC"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { getTranslation } from '@payloadcms/translations';
|
3
|
-
import { Button, Popup, PopupList } from '@payloadcms/ui
|
4
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
3
|
+
import { Button, Popup, PopupList, useTranslation } from '@payloadcms/ui';
|
5
4
|
import { useTranslator } from '../../providers/Translator/context';
|
6
5
|
import { LocaleLabel } from '../LocaleLabel';
|
7
6
|
export const Content = ()=>{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport { Button, Popup, PopupList
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport { Button, Popup, PopupList, useTranslation } from '@payloadcms/ui';\n\nimport { useTranslator } from '../../providers/Translator/context';\nimport { LocaleLabel } from '../LocaleLabel';\n\nexport const Content = () => {\n const {\n localeToTranslateFrom: localeCodeToTranslateFrom,\n localesOptions,\n resolverT,\n setLocaleToTranslateFrom,\n submit,\n } = useTranslator();\n\n const { i18n } = useTranslation();\n\n const localeToTranslateFrom = localesOptions.find(\n (each) => each.code === localeCodeToTranslateFrom,\n );\n\n return (\n <div className={'translator__content'}>\n <h2>{resolverT('modalTitle')}</h2>\n {localeToTranslateFrom && (\n <Popup\n button={<LocaleLabel locale={localeToTranslateFrom} />}\n horizontalAlign='center'\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {localesOptions.map((option) => {\n const label = getTranslation(option.label, i18n);\n\n return (\n <PopupList.Button\n active={option.code === localeCodeToTranslateFrom}\n key={option.code}\n onClick={() => {\n setLocaleToTranslateFrom(option.code);\n close();\n }}\n >\n {label}\n {label !== option.code && ` (${option.code})`}\n </PopupList.Button>\n );\n })}\n </PopupList.ButtonGroup>\n )}\n verticalAlign='bottom'\n />\n )}\n <div className={'translator__buttons'}>\n <Button onClick={() => submit({ emptyOnly: false })}>\n {resolverT('submitButtonLabelFull')}\n </Button>\n <Button onClick={() => submit({ emptyOnly: true })}>\n {resolverT('submitButtonLabelEmpty')}\n </Button>\n </div>\n </div>\n );\n};\n"],"names":["getTranslation","Button","Popup","PopupList","useTranslation","useTranslator","LocaleLabel","Content","localeToTranslateFrom","localeCodeToTranslateFrom","localesOptions","resolverT","setLocaleToTranslateFrom","submit","i18n","find","each","code","div","className","h2","button","locale","horizontalAlign","render","close","ButtonGroup","map","option","label","active","onClick","verticalAlign","emptyOnly"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,cAAc,QAAQ,iBAAiB;AAE1E,SAASC,aAAa,QAAQ,qCAAqC;AACnE,SAASC,WAAW,QAAQ,iBAAiB;AAE7C,OAAO,MAAMC,UAAU;IACrB,MAAM,EACJC,uBAAuBC,yBAAyB,EAChDC,cAAc,EACdC,SAAS,EACTC,wBAAwB,EACxBC,MAAM,EACP,GAAGR;IAEJ,MAAM,EAAES,IAAI,EAAE,GAAGV;IAEjB,MAAMI,wBAAwBE,eAAeK,IAAI,CAC/C,CAACC,OAASA,KAAKC,IAAI,KAAKR;IAG1B,qBACE,MAACS;QAAIC,WAAW;;0BACd,KAACC;0BAAIT,UAAU;;YACdH,uCACC,KAACN;gBACCmB,sBAAQ,KAACf;oBAAYgB,QAAQd;;gBAC7Be,iBAAgB;gBAChBC,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,KAACtB,UAAUuB,WAAW;kCACnBhB,eAAeiB,GAAG,CAAC,CAACC;4BACnB,MAAMC,QAAQ7B,eAAe4B,OAAOC,KAAK,EAAEf;4BAE3C,qBACE,MAACX,UAAUF,MAAM;gCACf6B,QAAQF,OAAOX,IAAI,KAAKR;gCAExBsB,SAAS;oCACPnB,yBAAyBgB,OAAOX,IAAI;oCACpCQ;gCACF;;oCAECI;oCACAA,UAAUD,OAAOX,IAAI,IAAI,CAAC,EAAE,EAAEW,OAAOX,IAAI,CAAC,CAAC,CAAC;;+BAPxCW,OAAOX,IAAI;wBAUtB;;gBAGJe,eAAc;;0BAGlB,MAACd;gBAAIC,WAAW;;kCACd,KAAClB;wBAAO8B,SAAS,IAAMlB,OAAO;gCAAEoB,WAAW;4BAAM;kCAC9CtB,UAAU;;kCAEb,KAACV;wBAAO8B,SAAS,IAAMlB,OAAO;gCAAEoB,WAAW;4BAAK;kCAC7CtB,UAAU;;;;;;AAKrB,EAAE"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import './styles.scss';
|
3
|
-
import { Modal } from '@payloadcms/ui
|
3
|
+
import { Modal } from '@payloadcms/ui';
|
4
4
|
import { useTranslator } from '../../providers/Translator/context';
|
5
5
|
import { Content } from './Content';
|
6
6
|
export const TranslatorModal = ()=>{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"sourcesContent":["import './styles.scss';\n\nimport { Modal } from '@payloadcms/ui
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"sourcesContent":["import './styles.scss';\n\nimport { Modal } from '@payloadcms/ui';\n\nimport { useTranslator } from '../../providers/Translator/context';\nimport { Content } from './Content';\n\nexport const TranslatorModal = () => {\n const { closeTranslator, modalSlug, resolver } = useTranslator();\n\n if (!resolver) return;\n\n return (\n <Modal className={'translator__modal'} slug={modalSlug}>\n <div className={'translator__wrapper'}>\n <span\n aria-label='Close'\n className={'translator__close'}\n onClick={closeTranslator}\n role='button'\n />\n <Content />\n </div>\n </Modal>\n );\n};\n"],"names":["Modal","useTranslator","Content","TranslatorModal","closeTranslator","modalSlug","resolver","className","slug","div","span","aria-label","onClick","role"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,OAAO,gBAAgB;AAEvB,SAASA,KAAK,QAAQ,iBAAiB;AAEvC,SAASC,aAAa,QAAQ,qCAAqC;AACnE,SAASC,OAAO,QAAQ,YAAY;AAEpC,OAAO,MAAMC,kBAAkB;IAC7B,MAAM,EAAEC,eAAe,EAAEC,SAAS,EAAEC,QAAQ,EAAE,GAAGL;IAEjD,IAAI,CAACK,UAAU;IAEf,qBACE,KAACN;QAAMO,WAAW;QAAqBC,MAAMH;kBAC3C,cAAA,MAACI;YAAIF,WAAW;;8BACd,KAACG;oBACCC,cAAW;oBACXJ,WAAW;oBACXK,SAASR;oBACTS,MAAK;;8BAEP,KAACX;;;;AAIT,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TranslatorProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"TranslatorProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,SAAS,EAAgC,MAAM,OAAO,CAAC;AASrE,eAAO,MAAM,kBAAkB,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,gCAoIvE,CAAC"}
|
@@ -1,13 +1,6 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { toast } from '@payloadcms/ui
|
3
|
-
import {
|
4
|
-
import { useAllFormFields, useForm } from '@payloadcms/ui/forms/Form';
|
5
|
-
import { useConfig } from '@payloadcms/ui/providers/Config';
|
6
|
-
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
7
|
-
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
8
|
-
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
9
|
-
import { getFormState } from '@payloadcms/ui/utilities/getFormState';
|
10
|
-
import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
|
2
|
+
import { toast, useAllFormFields, useConfig, useDocumentInfo, useForm, useLocale, useModal, useTranslation } from '@payloadcms/ui';
|
3
|
+
import { getFormState, reduceFieldsToValues } from '@payloadcms/ui/shared';
|
11
4
|
import { useEffect, useMemo, useState } from 'react';
|
12
5
|
import { createClient } from '../../api';
|
13
6
|
import { TranslatorContext } from './context';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import {\n toast,\n useAllFormFields,\n useConfig,\n useDocumentInfo,\n useForm,\n useLocale,\n useModal,\n useTranslation,\n} from '@payloadcms/ui';\nimport { getFormState, reduceFieldsToValues } from '@payloadcms/ui/shared';\nimport { type ReactNode, useEffect, useMemo, useState } from 'react';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport type { TranslateArgs } from '../../../translate/types';\nimport { createClient } from '../../api';\nimport { TranslatorContext } from './context';\n\nconst modalSlug = 'translator-modal';\n\nexport const TranslatorProvider = ({ children }: { children: ReactNode }) => {\n const [resolver, setResolver] = useState<null | string>(null);\n\n const [data, dispatch] = useAllFormFields();\n\n const { collectionSlug, globalSlug, id } = useDocumentInfo();\n\n const { setModified } = useForm();\n\n const modal = useModal();\n\n const { t } = useTranslation();\n\n const resolverT = (\n key:\n | 'buttonLabel'\n | 'errorMessage'\n | 'modalTitle'\n | 'submitButtonLabelEmpty'\n | 'submitButtonLabelFull'\n | 'successMessage',\n ) => {\n if (!resolver) return '';\n\n return t(`plugin-translator:resolver_${resolver}_${key}` as Parameters<typeof t>[0]);\n };\n\n const locale = useLocale();\n\n const {\n admin: { custom },\n localization,\n routes: { api },\n serverURL,\n } = useConfig();\n\n const apiClient = createClient({ api, serverURL });\n\n const resolverConfig = useMemo(() => {\n if (!resolver) return null;\n\n const resolvers = (custom?.translator?.resolvers as TranslateResolver[]) || undefined;\n\n if (!resolvers) return null;\n\n const resolverConfig = resolvers.find((each) => each.key === resolver);\n\n return resolverConfig ?? null;\n }, [custom, resolver]);\n\n if (!localization)\n throw new Error('Localization config is not provided and PluginTranslator is used');\n\n const localesOptions = localization.locales.filter((each) => each.code !== locale.code);\n\n const [localeToTranslateFrom, setLocaleToTranslateFrom] = useState<string>('');\n\n useEffect(() => {\n const defaultFromOptions = localesOptions.find(\n (each) => localization.defaultLocale === each.code,\n );\n\n if (defaultFromOptions) setLocaleToTranslateFrom(defaultFromOptions.code);\n setLocaleToTranslateFrom(localesOptions[0].code);\n }, [locale]);\n\n const closeTranslator = () => modal.closeModal(modalSlug);\n\n const submit = async ({ emptyOnly }: { emptyOnly: boolean }) => {\n if (!resolver) return;\n\n const args: TranslateArgs = {\n collectionSlug,\n data: reduceFieldsToValues(data, true),\n emptyOnly,\n globalSlug,\n id: id === null ? undefined : id,\n locale: locale.code,\n localeFrom: localeToTranslateFrom,\n resolver,\n };\n\n const result = await apiClient.translate(args);\n\n if (!result.success) {\n toast.error(resolverT('errorMessage'));\n\n return;\n }\n\n dispatch({\n state: await getFormState({\n apiRoute: api,\n body: {\n collectionSlug,\n data: result.translatedData,\n globalSlug,\n locale: locale.code,\n schemaPath: collectionSlug || globalSlug || '',\n },\n serverURL,\n }),\n type: 'REPLACE_STATE',\n });\n\n if (resolverConfig) {\n setModified(true);\n toast.success(resolverT('successMessage'));\n }\n closeTranslator();\n };\n\n return (\n <TranslatorContext.Provider\n value={{\n closeTranslator,\n localeToTranslateFrom,\n localesOptions,\n modalSlug,\n openTranslator: ({ resolverKey }) => {\n setResolver(resolverKey);\n modal.openModal(modalSlug);\n },\n resolver: resolverConfig,\n resolverT,\n setLocaleToTranslateFrom,\n submit,\n }}\n >\n {children}\n </TranslatorContext.Provider>\n );\n};\n"],"names":["toast","useAllFormFields","useConfig","useDocumentInfo","useForm","useLocale","useModal","useTranslation","getFormState","reduceFieldsToValues","useEffect","useMemo","useState","createClient","TranslatorContext","modalSlug","TranslatorProvider","children","resolver","setResolver","data","dispatch","collectionSlug","globalSlug","id","setModified","modal","t","resolverT","key","locale","admin","custom","localization","routes","api","serverURL","apiClient","resolverConfig","resolvers","translator","undefined","find","each","Error","localesOptions","locales","filter","code","localeToTranslateFrom","setLocaleToTranslateFrom","defaultFromOptions","defaultLocale","closeTranslator","closeModal","submit","emptyOnly","args","localeFrom","result","translate","success","error","state","apiRoute","body","translatedData","schemaPath","type","Provider","value","openTranslator","resolverKey","openModal"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SACEA,KAAK,EACLC,gBAAgB,EAChBC,SAAS,EACTC,eAAe,EACfC,OAAO,EACPC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAiB;AACxB,SAASC,YAAY,EAAEC,oBAAoB,QAAQ,wB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kBAECtC;;AAGP,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,KAAK,qBAAqB,GAAG;IAC3B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,CACT,GAAG,EACC,aAAa,GACb,cAAc,GACd,YAAY,GACZ,wBAAwB,GACxB,uBAAuB,GACvB,gBAAgB,KACjB,MAAM,CAAC;IACZ,wBAAwB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAEF,eAAO,MAAM,iBAAiB,uDAAoD,CAAC;AAEnF,eAAO,MAAM,aAAa,6BAMzB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/providers/Translator/context.ts"],"sourcesContent":["import type { Locale } from 'payload
|
1
|
+
{"version":3,"sources":["../../../../src/client/providers/Translator/context.ts"],"sourcesContent":["import type { Locale } from 'payload';\nimport { createContext, useContext } from 'react';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\n\ntype TranslatorContextData = {\n closeTranslator: () => void;\n localeToTranslateFrom: string;\n localesOptions: Locale[];\n modalSlug: string;\n openTranslator: (args: { resolverKey: string }) => void;\n resolver: TranslateResolver | null;\n resolverT: (\n key:\n | 'buttonLabel'\n | 'errorMessage'\n | 'modalTitle'\n | 'submitButtonLabelEmpty'\n | 'submitButtonLabelFull'\n | 'successMessage',\n ) => string;\n setLocaleToTranslateFrom: (code: string) => void;\n submit: (args: { emptyOnly: boolean }) => Promise<void>;\n};\n\nexport const TranslatorContext = createContext<TranslatorContextData | null>(null);\n\nexport const useTranslator = () => {\n const context = useContext(TranslatorContext);\n\n if (context === null) throw new Error('useTranslator must be used within TranslatorProvider');\n\n return context;\n};\n"],"names":["createContext","useContext","TranslatorContext","useTranslator","context","Error"],"rangeMappings":";;;;;;","mappings":"AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAwBlD,OAAO,MAAMC,oBAAoBF,cAA4C,MAAM;AAEnF,OAAO,MAAMG,gBAAgB;IAC3B,MAAMC,UAAUH,WAAWC;IAE3B,IAAIE,YAAY,MAAM,MAAM,IAAIC,MAAM;IAEtC,OAAOD;AACT,EAAE"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAMtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,UAAU,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,MA4E5D,CAAC"}
|
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* eslint-disable perfectionist/sort-named-exports */ import { deepMerge } from 'payload/
|
1
|
+
/* eslint-disable perfectionist/sort-named-exports */ import { deepMerge } from 'payload/shared';
|
2
2
|
import { CustomButton } from './client/components/CustomButton';
|
3
3
|
import { translations } from './i18n-translations';
|
4
4
|
import { translateEndpoint } from './translate/endpoint';
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-named-exports */\nimport type { Plugin } from 'payload
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-named-exports */\nimport type { Plugin } from 'payload';\nimport { deepMerge } from 'payload/shared';\n\nimport { CustomButton } from './client/components/CustomButton';\nimport { translations } from './i18n-translations';\nimport { translateEndpoint } from './translate/endpoint';\nimport { translateOperation } from './translate/operation';\nimport type { TranslatorConfig } from './types';\n\nexport { translateOperation };\n\nexport const translator: (pluginConfig: TranslatorConfig) => Plugin = (pluginConfig) => {\n return (config) => {\n if (pluginConfig.disabled || !config.localization || config.localization.locales.length < 2)\n return config;\n\n return {\n ...config,\n admin: {\n ...(config.admin ?? {}),\n custom: {\n ...(config.admin?.custom ?? {}),\n translator: {\n resolvers: pluginConfig.resolvers.map(({ key }) => ({ key })),\n },\n },\n },\n collections:\n config.collections?.map((collection) => {\n if (!pluginConfig.collections.includes(collection.slug)) return collection;\n\n return {\n ...collection,\n admin: {\n ...(collection.admin ?? {}),\n components: {\n ...(collection.admin?.components ?? {}),\n edit: {\n ...(collection.admin?.components?.edit ?? {}),\n PublishButton: CustomButton('publish'),\n SaveButton: CustomButton('save'),\n },\n },\n },\n };\n }) ?? [],\n custom: {\n ...(config.custom ?? {}),\n translator: {\n resolvers: pluginConfig.resolvers,\n },\n },\n endpoints: [\n ...(config.endpoints ?? []),\n {\n handler: translateEndpoint,\n method: 'post',\n path: '/translator/translate',\n },\n ],\n globals:\n config.globals?.map((global) => {\n if (!pluginConfig.globals.includes(global.slug)) return global;\n\n return {\n ...global,\n admin: {\n ...(global.admin ?? {}),\n components: {\n ...(global.admin?.components ?? {}),\n elements: {\n ...(global.admin?.components?.elements ?? {}),\n PublishButton: CustomButton('publish'),\n SaveButton: CustomButton('save'),\n },\n },\n },\n };\n }) ?? [],\n i18n: {\n ...config.i18n,\n translations: {\n ...deepMerge(config.i18n?.translations ?? {}, translations),\n },\n },\n };\n };\n};\n"],"names":["deepMerge","CustomButton","translations","translateEndpoint","translateOperation","translator","pluginConfig","config","disabled","localization","locales","length","admin","custom","resolvers","map","key","collections","collection","includes","slug","components","edit","PublishButton","SaveButton","endpoints","handler","method","path","globals","global","elements","i18n"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,mDAAmD,GAEnD,SAASA,SAAS,QAAQ,iBAAiB;AAE3C,SAASC,YAAY,QAAQ,mCAAmC;AAChE,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,kBAAkB,QAAQ,wBAAwB;AAG3D,SAASA,kBAAkB,GAAG;AAE9B,OAAO,MAAMC,aAAyD,CAACC;IACrE,OAAO,CAACC;QACN,IAAID,aAAaE,QAAQ,IAAI,CAACD,OAAOE,YAAY,IAAIF,OAAOE,YAAY,CAACC,OAAO,CAACC,MAAM,GAAG,GACxF,OAAOJ;QAET,OAAO;YACL,GAAGA,MAAM;YACTK,OAAO;gBACL,GAAIL,OAAOK,KAAK,IAAI,CAAC,CAAC;gBACtBC,QAAQ;oBACN,GAAIN,OAAOK,KAAK,EAAEC,UAAU,CAAC,CAAC;oBAC9BR,YAAY;wBACVS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M,EAAE;YACV+B,MAAM;gBACJ,GAAGzB,OAAOyB,IAAI;gBACd9B,cAAc;oBACZ,GAAGF,UAAUO,OAAOyB,IAAI,EAAE9B,gBAAgB,CAAC,GAAGA,aAAa;gBAC7D;YACF;QACF;IACF;AACF,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolvers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolvers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,qBAAqB,GAAG;IAClC,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC;IACE,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,OAAO,EAAE,IAAI,CAAC;IACd,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,CACP,IAAI,EAAE,qBAAqB,KACxB,OAAO,CAAC,yBAAyB,CAAC,GAAG,yBAAyB,CAAC;CACrE,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/resolvers/types.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload
|
1
|
+
{"version":3,"sources":["../../src/resolvers/types.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload';\n\nexport type TranslateResolverArgs = {\n /** Locale to translate from */\n localeFrom: string;\n /** Locale to translate to */\n localeTo: string;\n req: PayloadRequest;\n texts: string[];\n};\n\nexport type TranslateResolverResponse =\n | {\n success: false;\n }\n | {\n success: true;\n translatedTexts: string[];\n };\n\nexport type TranslateResolver = {\n key: string;\n resolve: (\n args: TranslateResolverArgs,\n ) => Promise<TranslateResolverResponse> | TranslateResolverResponse;\n};\n"],"names":[],"rangeMappings":"","mappings":"AAoBA,WAKE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/translate/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/translate/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM9C,eAAO,MAAM,iBAAiB,EAAE,cAsB/B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/translate/endpoint.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload
|
1
|
+
{"version":3,"sources":["../../src/translate/endpoint.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload';\nimport { APIError } from 'payload';\n\nimport { translateOperation } from './operation';\nimport type { TranslateEndpointArgs } from './types';\n\nexport const translateEndpoint: PayloadHandler = async (req) => {\n if (!req.json) throw new APIError('Content-Type should be json');\n\n const args: TranslateEndpointArgs = await req.json();\n\n const { collectionSlug, data, emptyOnly, globalSlug, id, locale, localeFrom, resolver } = args;\n\n const result = await translateOperation({\n collectionSlug,\n data,\n emptyOnly,\n globalSlug,\n id,\n locale,\n localeFrom,\n overrideAccess: false,\n req,\n resolver,\n update: false,\n });\n\n return Response.json(result);\n};\n"],"names":["APIError","translateOperation","translateEndpoint","req","json","args","collectionSlug","data","emptyOnly","globalSlug","id","locale","localeFrom","resolver","result","overrideAccess","update","Response"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,QAAQ,QAAQ,UAAU;AAEnC,SAASC,kBAAkB,QAAQ,cAAc;AAGjD,OAAO,MAAMC,oBAAoC,OAAOC;IACtD,IAAI,CAACA,IAAIC,IAAI,EAAE,MAAM,IAAIJ,SAAS;IAElC,MAAMK,OAA8B,MAAMF,IAAIC,IAAI;IAElD,MAAM,EAAEE,cAAc,EAAEC,IAAI,EAAEC,SAAS,EAAEC,UAAU,EAAEC,EAAE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGR;IAE1F,MAAMS,SAAS,MAAMb,mBAAmB;QACtCK;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAG,gBAAgB;QAChBZ;QACAU;QACAG,QAAQ;IACV;IAEA,OAAOC,SAASb,IAAI,CAACU;AACvB,EAAE"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { PayloadRequest, SanitizedCollectionConfig, SanitizedGlobalConfig, TypeWithID } from 'payload
|
1
|
+
import type { PayloadRequest, SanitizedCollectionConfig, SanitizedGlobalConfig, TypeWithID } from 'payload';
|
2
2
|
type Args = {
|
3
3
|
collectionSlug?: string;
|
4
4
|
globalSlug?: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findEntityWithConfig.d.ts","sourceRoot":"","sources":["../../src/translate/findEntityWithConfig.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"findEntityWithConfig.d.ts","sourceRoot":"","sources":["../../src/translate/findEntityWithConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,UAAU,EACX,MAAM,SAAS,CAAC;AAGjB,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAOF,eAAO,MAAM,oBAAoB,SACzB,IAAI,KACT,OAAO,CAAC;IACT,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAC;IAC1D,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC;CAC3C,CA0CA,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { APIError } from 'payload
|
1
|
+
import { APIError } from 'payload';
|
2
2
|
const findConfigBySlug = (slug, enities)=>enities.find((entity)=>entity.slug === slug);
|
3
3
|
export const findEntityWithConfig = async (args)=>{
|
4
4
|
const { collectionSlug, globalSlug, id, locale, overrideAccess, req } = args;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/translate/findEntityWithConfig.ts"],"sourcesContent":["import
|
1
|
+
{"version":3,"sources":["../../src/translate/findEntityWithConfig.ts"],"sourcesContent":["import type {\n PayloadRequest,\n SanitizedCollectionConfig,\n SanitizedGlobalConfig,\n TypeWithID,\n} from 'payload';\nimport { APIError } from 'payload';\n\ntype Args = {\n collectionSlug?: string;\n globalSlug?: string;\n id?: number | string;\n locale: string;\n overrideAccess?: boolean;\n req: PayloadRequest;\n};\n\nconst findConfigBySlug = (\n slug: string,\n enities: SanitizedCollectionConfig[] | SanitizedGlobalConfig[],\n) => enities.find((entity) => entity.slug === slug);\n\nexport const findEntityWithConfig = async (\n args: Args,\n): Promise<{\n config: SanitizedCollectionConfig | SanitizedGlobalConfig;\n doc: Record<string, unknown> & TypeWithID;\n}> => {\n const { collectionSlug, globalSlug, id, locale, overrideAccess, req } = args;\n\n if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);\n\n const { payload } = req;\n\n const { config } = payload;\n\n const isGlobal = !!globalSlug;\n\n if (!isGlobal && !id) throw new APIError('Bad Request', 400);\n\n const entityConfig = isGlobal\n ? findConfigBySlug(globalSlug, config.globals)\n : findConfigBySlug(collectionSlug as string, config.collections);\n\n if (!entityConfig) throw new APIError('Bad Request', 400);\n\n const docPromise = isGlobal\n ? payload.findGlobal({\n depth: 0,\n fallbackLocale: null,\n locale,\n overrideAccess,\n req,\n slug: args.globalSlug as string,\n })\n : payload.findByID({\n collection: collectionSlug as string,\n depth: 0,\n fallbackLocale: null,\n id: id as number | string,\n locale,\n overrideAccess,\n req,\n });\n\n return {\n config: entityConfig,\n doc: await docPromise,\n };\n};\n"],"names":["APIError","findConfigBySlug","slug","enities","find","entity","findEntityWithConfig","args","collectionSlug","globalSlug","id","locale","overrideAccess","req","payload","config","isGlobal","entityConfig","globals","collections","docPromise","findGlobal","depth","fallbackLocale","findByID","collection","doc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,SAASA,QAAQ,QAAQ,UAAU;AAWnC,MAAMC,mBAAmB,CACvBC,MACAC,UACGA,QAAQC,IAAI,CAAC,CAACC,SAAWA,OAAOH,IAAI,KAAKA;AAE9C,OAAO,MAAMI,uBAAuB,OAClCC;IAKA,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAEC,MAAM,EAAEC,cAAc,EAAEC,GAAG,EAAE,GAAGN;IAExE,IAAI,CAACC,kBAAkB,CAACC,YAAY,MAAM,IAAIT,SAAS,eAAe;IAEtE,MAAM,EAAEc,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,MAAM,EAAE,GAAGD;IAEnB,MAAME,WAAW,CAAC,CAACP;IAEnB,IAAI,CAACO,YAAY,CAACN,IAAI,MAAM,IAAIV,SAAS,eAAe;IAExD,MAAMiB,eAAeD,WACjBf,iBAAiBQ,YAAYM,OAAOG,OAAO,IAC3CjB,iBAAiBO,gBAA0BO,OAAOI,WAAW;IAEjE,IAAI,CAACF,cAAc,MAAM,IAAIjB,SAAS,eAAe;IAErD,MAAMoB,aAAaJ,WACfF,QAAQO,UAAU,CAAC;QACjBC,OAAO;QACPC,gBAAgB;QAChBZ;QACAC;QACAC;QACAX,MAAMK,KAAKE,UAAU;IACvB,KACAK,QAAQU,QAAQ,CAAC;QACfC,YAAYjB;QACZc,OAAO;QACPC,gBAAgB;QAChBb,IAAIA;QACJC;QACAC;QACAC;IACF;IAEJ,OAAO;QACLE,QAAQE;QACRS,KAAK,MAAMN;IACb;AACF,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/translate/operation.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/translate/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAKtE,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAoB,MAAM,SAAS,CAAC;AAGhF,MAAM,MAAM,sBAAsB,GAAG,CACjC;IACE,OAAO,EAAE,OAAO,CAAC;CAClB,GACD;IACE,GAAG,EAAE,cAAc,CAAC;CACrB,CACJ,GACC,aAAa,CAAC;AAEhB,eAAO,MAAM,kBAAkB,SAAgB,sBAAsB,6BAyFpE,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/translate/operation.ts"],"sourcesContent":["import { APIError
|
1
|
+
{"version":3,"sources":["../../src/translate/operation.ts"],"sourcesContent":["import { APIError, type Payload, type PayloadRequest } from 'payload';\n\nimport type { TranslateResolver } from '../resolvers/types';\nimport { findEntityWithConfig } from './findEntityWithConfig';\nimport { traverseFields } from './traverseFields';\nimport type { TranslateArgs, TranslateResult, ValueToTranslate } from './types';\nimport { updateEntity } from './updateEntity';\n\nexport type TranslateOperationArgs = (\n | {\n payload: Payload;\n }\n | {\n req: PayloadRequest;\n }\n) &\n TranslateArgs;\n\nexport const translateOperation = async (args: TranslateOperationArgs) => {\n const req: PayloadRequest =\n 'req' in args\n ? args.req\n : ({\n payload: args.payload,\n } as PayloadRequest);\n\n const { collectionSlug, globalSlug, id, locale, localeFrom, overrideAccess } = args;\n\n const { config, doc: dataFrom } = await findEntityWithConfig({\n collectionSlug,\n globalSlug,\n id,\n locale: localeFrom,\n req,\n });\n\n const resolver = (\n (req.payload.config.custom?.translator?.resolvers as TranslateResolver[]) ?? []\n ).find((each) => each.key === args.resolver);\n\n if (!resolver) throw new APIError(`Resolver with the key ${args.resolver} was not found`);\n\n const valuesToTranslate: ValueToTranslate[] = [];\n\n let translatedData = args.data;\n\n console.log(translatedData);\n\n if (!translatedData) {\n const { doc } = await findEntityWithConfig({\n collectionSlug,\n globalSlug,\n id,\n locale,\n overrideAccess,\n req,\n });\n\n translatedData = doc;\n }\n\n traverseFields({\n dataFrom,\n emptyOnly: args.emptyOnly,\n fields: config.fields,\n translatedData,\n valuesToTranslate,\n });\n\n const resolveResult = await resolver.resolve({\n localeFrom: args.localeFrom,\n localeTo: args.locale,\n req,\n texts: valuesToTranslate.map((each) => each.value),\n });\n\n let result: TranslateResult;\n\n if (!resolveResult.success) {\n result = {\n success: false,\n };\n } else {\n resolveResult.translatedTexts.forEach((translated, index) => {\n valuesToTranslate[index].onTranslate(translated);\n });\n\n if (args.update) {\n await updateEntity({\n collectionSlug,\n data: translatedData,\n depth: 0,\n globalSlug,\n id,\n locale,\n overrideAccess,\n req,\n });\n }\n\n result = {\n success: true,\n translatedData,\n };\n }\n\n return result;\n};\n"],"names":["APIError","findEntityWithConfig","traverseFields","updateEntity","translateOperation","args","req","payload","collectionSlug","globalSlug","id","locale","localeFrom","overrideAccess","config","doc","dataFrom","resolver","custom","translator","resolvers","find","each","key","valuesToTranslate","translatedData","data","console","log","emptyOnly","fields","resolveResult","resolve","localeTo","texts","map","value","result","success","translatedTexts","forEach","translated","index","onTranslate","update","depth"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAA2C,UAAU;AAGtE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SA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cO,OAAO,EAAE;QAC1BD,SAAS;YACPC,SAAS;QACX;IACF,OAAO;QACLP,cAAcQ,eAAe,CAACC,OAAO,CAAC,CAACC,YAAYC;YACjDlB,iBAAiB,CAACkB,MAAM,CAACC,WAAW,CAACF;QACvC;QAEA,IAAIpC,KAAKuC,MAAM,EAAE;YACf,MAAMzC,aAAa;gBACjBK;gBACAkB,MAAMD;gBACNoB,OAAO;gBACPpC;gBACAC;gBACAC;gBACAE;gBACAP;YACF;QACF;QAEA+B,SAAS;YACPC,SAAS;YACTb;QACF;IACF;IAEA,OAAOY;AACT,EAAE"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import type { Field } from 'payload';
|
2
2
|
import type { ValueToTranslate } from './types';
|
3
3
|
export declare const traverseFields: ({ dataFrom, emptyOnly, fields, localizedParent, siblingDataFrom, siblingDataTranslated, translatedData, valuesToTranslate, }: {
|
4
4
|
dataFrom: Record<string, unknown>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/translate/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/translate/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,cAAc,iIASxB;IACD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;CACvC,SAyOA,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import ObjectID from 'bson-objectid';
|
2
|
-
import { tabHasName } from 'payload/
|
2
|
+
import { tabHasName } from 'payload/shared';
|
3
3
|
import { isEmpty } from '../utils/isEmpty';
|
4
4
|
import { traverseRichText } from './traverseRichText';
|
5
5
|
export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, siblingDataFrom, siblingDataTranslated, translatedData, valuesToTranslate })=>{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/translate/traverseFields.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\nimport { type Field, tabHasName } from 'payload/types';\n\nimport { isEmpty } from '../utils/isEmpty';\nimport { traverseRichText } from './traverseRichText';\nimport type { ValueToTranslate } from './types';\n\nexport const traverseFields = ({\n dataFrom,\n emptyOnly,\n fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n}: {\n dataFrom: Record<string, unknown>;\n emptyOnly?: boolean;\n fields: Field[];\n localizedParent?: boolean;\n siblingDataFrom?: Record<string, unknown>;\n siblingDataTranslated?: Record<string, unknown>;\n translatedData: Record<string, unknown>;\n valuesToTranslate: ValueToTranslate[];\n}) => {\n siblingDataFrom = siblingDataFrom ?? dataFrom;\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\n\n fields.forEach((field) => {\n switch (field.type) {\n case 'tabs':\n field.tabs.forEach((tab) => {\n const hasName = tabHasName(tab);\n\n const tabDataFrom = hasName\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\n : siblingDataFrom;\n\n if (!tabDataFrom) return;\n\n const tabDataTranslated = hasName\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\n : siblingDataTranslated;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: tab.fields,\n localizedParent: tab.localized,\n siblingDataFrom: tabDataFrom,\n siblingDataTranslated: tabDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n });\n\n break;\n\n case 'group':\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\n\n if (!groupDataFrom) break;\n\n const groupDataTranslated =\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: field.localized,\n siblingDataFrom: groupDataFrom,\n siblingDataTranslated: groupDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n\n break;\n\n case 'array':\n const arrayDataFrom = siblingDataFrom[field.name] as {\n id: string;\n }[];\n\n if (isEmpty(arrayDataFrom)) break;\n\n let arrayDataTranslated =\n (siblingDataTranslated[field.name] as { id: string }[] | undefined) ?? [];\n\n if (field.localized || localizedParent) {\n if (arrayDataTranslated.length > 0 && emptyOnly) break;\n\n arrayDataTranslated = arrayDataFrom.map(() => ({\n id: ObjectID().toHexString(),\n }));\n }\n\n arrayDataTranslated.forEach((item, index) => {\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: arrayDataFrom[index],\n siblingDataTranslated: item,\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = arrayDataTranslated;\n\n break;\n\n case 'blocks':\n const blocksDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\n\n if (isEmpty(blocksDataFrom)) break;\n\n let blocksDataTranslated =\n (siblingDataTranslated[field.name] as { blockType: string; id: string }[] | undefined) ??\n [];\n\n if (field.localized || localizedParent) {\n if (blocksDataTranslated.length > 0 && emptyOnly) break;\n\n blocksDataTranslated = blocksDataFrom.map(({ blockType }) => ({\n blockType,\n id: ObjectID().toHexString(),\n }));\n }\n\n blocksDataTranslated.forEach((item, index) => {\n const block = field.blocks.find((each) => each.slug === item.blockType);\n\n if (!block) return;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: block.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: blocksDataFrom[index],\n siblingDataTranslated: item,\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = blocksDataTranslated;\n\n break;\n\n case 'collapsible':\n case 'row':\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n break;\n\n // long ass cases here we have\n case 'date':\n case 'checkbox':\n case 'json':\n case 'code':\n case 'email':\n case 'number':\n case 'point':\n case 'radio':\n case 'relationship':\n case 'select':\n case 'upload':\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\n\n break;\n\n case 'text':\n case 'textarea':\n if (field.custom && typeof field.custom === 'object' && field.custom.translatorSkip) break;\n\n if (!(field.localized || localizedParent) || isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) break;\n\n // do not translate the block ID or admin-facing label\n if (field.name === 'blockName' || field.name === 'id') {\n break;\n }\n\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingDataTranslated[field.name] = translated;\n },\n value: siblingDataFrom[field.name],\n });\n break;\n\n case 'richText':\n if (!(field.localized || localizedParent) || isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) break;\n\n const richTextDataFrom = siblingDataFrom[field.name] as object;\n\n siblingDataTranslated[field.name] = richTextDataFrom;\n\n if (!richTextDataFrom) break;\n\n const isSlate = Array.isArray(richTextDataFrom);\n\n const isLexical = 'root' in richTextDataFrom;\n\n if (!isSlate && !isLexical) break;\n\n if (isLexical) {\n const root = (siblingDataTranslated[field.name] as Record<string, unknown>)\n ?.root as Record<string, unknown>;\n\n if (root)\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root,\n });\n } else {\n for (const root of siblingDataTranslated[field.name] as unknown[]) {\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root: root as Record<string, unknown>,\n });\n }\n }\n\n break;\n\n default:\n break;\n }\n });\n};\n"],"names":["ObjectID","tabHasName","isEmpty","traverseRichText","traverseFields","dataFrom","emptyOnly","fields","localizedParent","siblingDataFrom","siblingDataTranslated","translatedData","valuesToTranslate","forEach","field","type","tabs","tab","hasName","tabDataFrom","name","tabDataTranslated","localized","groupDataFrom","groupDataTranslated","arrayDataFrom","arrayDataTranslated","length","map","id","toHexString","item","index","blocksDataFrom","blocksDataTranslated","blockType","block","blocks","find","each","slug","custom","translatorSkip","push","onTranslate","translated","value","richTextDataFrom","isSlate","Array","isArray","isLexical","root","onText","siblingData","text"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,cAAc,gBAAgB;AACrC,SAAqBC,UAAU,QAAQ,gBAAgB;AAEvD,SAASC,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,gBAAgB,QAAQ,qBAAqB;AAGtD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,eAAe,EACfC,qBAAqB,EACrBC,cAAc,EACdC,iBAAiB,EAUlB;IACCH,kBAAkBA,mBAAmBJ;IACrCK,wBAAwBA,yBAAyBC;IAEjDJ,OAAOM,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBACHD,MAAME,IAAI,CAACH,OAAO,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,kBAAkB+B,IAAI,CAAC;gCACrBC,aAAa,CAACC;oCACZS,YAAYC,IAAI,GAAGV;gCACrB;gCACAC,OAAOQ,YAAYC,IAAI;4BACzB;wBACF;wBACAH;oBACF;gBACJ,OAAO;oBACL,KAAK,MAAMA,QAAQ1C,qBAAqB,CAACI,MAAMM,IAAI,CAAC,CAAe;wBACjEjB,iBAAiB;4BACfkD,QAAQ,CAACC;gCACP1C,kBAAkB+B,IAAI,CAAC;oCACrBC,aAAa,CAACC;wCACZS,YAAYC,IAAI,GAAGV;oCACrB;oCACAC,OAAOQ,YAAYC,IAAI;gCACzB;4BACF;4BACAH,MAAMA;wBACR;oBACF;gBACF;gBAEA;YAEF;gBACE;QACJ;IACF;AACF,EAAE"}
|
1
|
+
{"version":3,"sources":["../../src/translate/traverseFields.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\nimport type { Field } from 'payload';\nimport { tabHasName } from 'payload/shared';\n\nimport { isEmpty } from '../utils/isEmpty';\nimport { traverseRichText } from './traverseRichText';\nimport type { ValueToTranslate } from './types';\n\nexport const traverseFields = ({\n dataFrom,\n emptyOnly,\n fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n}: {\n dataFrom: Record<string, unknown>;\n emptyOnly?: boolean;\n fields: Field[];\n localizedParent?: boolean;\n siblingDataFrom?: Record<string, unknown>;\n siblingDataTranslated?: Record<string, unknown>;\n translatedData: Record<string, unknown>;\n valuesToTranslate: ValueToTranslate[];\n}) => {\n siblingDataFrom = siblingDataFrom ?? dataFrom;\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\n\n fields.forEach((field) => {\n switch (field.type) {\n case 'tabs':\n field.tabs.forEach((tab) => {\n const hasName = tabHasName(tab);\n\n const tabDataFrom = hasName\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\n : siblingDataFrom;\n\n if (!tabDataFrom) return;\n\n const tabDataTranslated = hasName\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\n : siblingDataTranslated;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: tab.fields,\n localizedParent: tab.localized,\n siblingDataFrom: tabDataFrom,\n siblingDataTranslated: tabDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n });\n\n break;\n\n case 'group':\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\n\n if (!groupDataFrom) break;\n\n const groupDataTranslated =\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: field.localized,\n siblingDataFrom: groupDataFrom,\n siblingDataTranslated: groupDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n\n break;\n\n case 'array':\n const arrayDataFrom = siblingDataFrom[field.name] as {\n id: string;\n }[];\n\n if (isEmpty(arrayDataFrom)) break;\n\n let arrayDataTranslated =\n (siblingDataTranslated[field.name] as { id: string }[] | undefined) ?? [];\n\n if (field.localized || localizedParent) {\n if (arrayDataTranslated.length > 0 && emptyOnly) break;\n\n arrayDataTranslated = arrayDataFrom.map(() => ({\n id: ObjectID().toHexString(),\n }));\n }\n\n arrayDataTranslated.forEach((item, index) => {\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: arrayDataFrom[index],\n siblingDataTranslated: item,\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = arrayDataTranslated;\n\n break;\n\n case 'blocks':\n const blocksDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\n\n if (isEmpty(blocksDataFrom)) break;\n\n let blocksDataTranslated =\n (siblingDataTranslated[field.name] as { blockType: string; id: string }[] | undefined) ??\n [];\n\n if (field.localized || localizedParent) {\n if (blocksDataTranslated.length > 0 && emptyOnly) break;\n\n blocksDataTranslated = blocksDataFrom.map(({ blockType }) => ({\n blockType,\n id: ObjectID().toHexString(),\n }));\n }\n\n blocksDataTranslated.forEach((item, index) => {\n const block = field.blocks.find((each) => each.slug === item.blockType);\n\n if (!block) return;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: block.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: blocksDataFrom[index],\n siblingDataTranslated: item,\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = blocksDataTranslated;\n\n break;\n\n case 'collapsible':\n case 'row':\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n break;\n\n // long ass cases here we have\n case 'date':\n case 'checkbox':\n case 'json':\n case 'code':\n case 'email':\n case 'number':\n case 'point':\n case 'radio':\n case 'relationship':\n case 'select':\n case 'upload':\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\n\n break;\n\n case 'text':\n case 'textarea':\n if (field.custom && typeof field.custom === 'object' && field.custom.translatorSkip) break;\n\n if (!(field.localized || localizedParent) || isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) break;\n\n // do not translate the block ID or admin-facing label\n if (field.name === 'blockName' || field.name === 'id') {\n break;\n }\n\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingDataTranslated[field.name] = translated;\n },\n value: siblingDataFrom[field.name],\n });\n break;\n\n case 'richText':\n if (!(field.localized || localizedParent) || isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) break;\n\n const richTextDataFrom = siblingDataFrom[field.name] as object;\n\n siblingDataTranslated[field.name] = richTextDataFrom;\n\n if (!richTextDataFrom) break;\n\n const isSlate = Array.isArray(richTextDataFrom);\n\n const isLexical = 'root' in richTextDataFrom;\n\n if (!isSlate && !isLexical) break;\n\n if (isLexical) {\n const root = (siblingDataTranslated[field.name] as Record<string, unknown>)\n ?.root as Record<string, unknown>;\n\n if (root)\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root,\n });\n } else {\n for (const root of siblingDataTranslated[field.name] as unknown[]) {\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root: root as Record<string, unknown>,\n });\n }\n }\n\n break;\n\n default:\n break;\n }\n });\n};\n"],"names":["ObjectID","tabHasName","isEmpty","traverseRichText","traverseFields","dataFrom","emptyOnly","fields","localizedParent","siblingDataFrom","siblingDataTranslated","translatedData","valuesToTranslate","forEach","field","type","tabs","tab","hasName","tabDataFrom","name","tabDataTranslated","localized","groupDataFrom","groupDataTranslated","arrayDataFrom","arrayDataTranslated","length","map","id","toHexString","item","index","blocksDataFrom","blocksDataTranslated","blockType","block","blocks","find","each","slug","custom","translatorSkip","push","onTranslate","translated","value","richTextDataFrom","isSlate","Array","isArray","isLexical","root","onText","siblingData","text"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,cAAc,gBAAgB;AAErC,SAASC,UAAU,QAAQ,iBAAiB;AAE5C,SAASC,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,gBAAgB,QAAQ,qBAAqB;AAGtD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,eAAe,EACfC,qBAAqB,EACrBC,cAAc,EACdC,iBAAiB,EAUlB;IACCH,kBAAkBA,mBAAmBJ;IACrCK,wBAAwBA,yBAAyBC;IAEjDJ,OAAOM,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,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iBAAiB;wBACfkD,QAAQ,CAACC;4BACP1C,kBAAkB+B,IAAI,CAAC;gCACrBC,aAAa,CAACC;oCACZS,YAAYC,IAAI,GAAGV;gCACrB;gCACAC,OAAOQ,YAAYC,IAAI;4BACzB;wBACF;wBACAH;oBACF;gBACJ,OAAO;oBACL,KAAK,MAAMA,QAAQ1C,qBAAqB,CAACI,MAAMM,IAAI,CAAC,CAAe;wBACjEjB,iBAAiB;4BACfkD,QAAQ,CAACC;gCACP1C,kBAAkB+B,IAAI,CAAC;oCACrBC,aAAa,CAACC;wCACZS,YAAYC,IAAI,GAAGV;oCACrB;oCACAC,OAAOQ,YAAYC,IAAI;gCACzB;4BACF;4BACAH,MAAMA;wBACR;oBACF;gBACF;gBAEA;YAEF;gBACE;QACJ;IACF;AACF,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateEntity.d.ts","sourceRoot":"","sources":["../../src/translate/updateEntity.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"updateEntity.d.ts","sourceRoot":"","sources":["../../src/translate/updateEntity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1D,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,YAAY,iGAStB,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CA6BrD,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { APIError } from 'payload
|
1
|
+
import { APIError } from 'payload';
|
2
2
|
export const updateEntity = ({ collectionSlug, data, depth: incomingDepth, globalSlug, id, locale, overrideAccess, req })=>{
|
3
3
|
if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);
|
4
4
|
const isGlobal = !!globalSlug;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/translate/updateEntity.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../src/translate/updateEntity.ts"],"sourcesContent":["import type { PayloadRequest, TypeWithID } from 'payload';\nimport { APIError } from 'payload';\n\ntype Args = {\n collectionSlug?: string;\n data: Record<string, any>;\n depth?: number;\n globalSlug?: string;\n id?: number | string;\n locale: string;\n overrideAccess?: boolean;\n req: PayloadRequest;\n};\n\nexport const updateEntity = ({\n collectionSlug,\n data,\n depth: incomingDepth,\n globalSlug,\n id,\n locale,\n overrideAccess,\n req,\n}: Args): Promise<Record<string, unknown> & TypeWithID> => {\n if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);\n\n const isGlobal = !!globalSlug;\n\n if (!isGlobal && !id) throw new APIError('Bad Request', 400);\n\n const depth = incomingDepth ?? req.payload.config.defaultDepth;\n\n const promise = isGlobal\n ? req.payload.updateGlobal({\n data,\n depth,\n locale,\n overrideAccess,\n req,\n slug: globalSlug as string,\n })\n : req.payload.update({\n collection: collectionSlug as string,\n data,\n depth,\n id: id as number | string,\n locale,\n overrideAccess,\n req,\n });\n\n return promise;\n};\n"],"names":["APIError","updateEntity","collectionSlug","data","depth","incomingDepth","globalSlug","id","locale","overrideAccess","req","isGlobal","payload","config","defaultDepth","promise","updateGlobal","slug","update","collection"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,QAAQ,QAAQ,UAAU;AAanC,OAAO,MAAMC,eAAe,CAAC,EAC3BC,cAAc,EACdC,IAAI,EACJC,OAAOC,aAAa,EACpBC,UAAU,EACVC,EAAE,EACFC,MAAM,EACNC,cAAc,EACdC,GAAG,EACE;IACL,IAAI,CAACR,kBAAkB,CAACI,YAAY,MAAM,IAAIN,SAAS,eAAe;IAEtE,MAAMW,WAAW,CAAC,CAACL;IAEnB,IAAI,CAACK,YAAY,CAACJ,IAAI,MAAM,IAAIP,SAAS,eAAe;IAExD,MAAMI,QAAQC,iBAAiBK,IAAIE,OAAO,CAACC,MAAM,CAACC,YAAY;IAE9D,MAAMC,UAAUJ,WACZD,IAAIE,OAAO,CAACI,YAAY,CAAC;QACvBb;QACAC;QACAI;QACAC;QACAC;QACAO,MAAMX;IACR,KACAI,IAAIE,OAAO,CAACM,MAAM,CAAC;QACjBC,YAAYjB;QACZC;QACAC;QACAG,IAAIA;QACJC;QACAC;QACAC;IACF;IAEJ,OAAOK;AACT,EAAE"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payload-enchants/translator",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.2.0-pre.0",
|
4
4
|
"private": false,
|
5
5
|
"bugs": "https://github.com/r1tsuu/payload-enchants/issues",
|
6
6
|
"repository": "https://github.com/r1tsuu/payload-enchants",
|
@@ -46,19 +46,19 @@
|
|
46
46
|
"bson-objectid": "^2.0.4"
|
47
47
|
},
|
48
48
|
"devDependencies": {
|
49
|
-
"@payloadcms/translations": "3.0.0-beta.
|
50
|
-
"@payloadcms/ui": "3.0.0-beta.
|
49
|
+
"@payloadcms/translations": "3.0.0-beta.53",
|
50
|
+
"@payloadcms/ui": "3.0.0-beta.53",
|
51
51
|
"@types/react": "npm:types-react@19.0.0-beta.2",
|
52
52
|
"@types/react-dom": "npm:types-react-dom@19.0.0-beta.2",
|
53
|
-
"payload": "3.0.0-beta.
|
53
|
+
"payload": "3.0.0-beta.53",
|
54
54
|
"typescript": "^5.4.5",
|
55
55
|
"react": "19.0.0-rc-f994737d14-20240522",
|
56
56
|
"react-dom": "19.0.0-rc-f994737d14-20240522"
|
57
57
|
},
|
58
58
|
"peerDependencies": {
|
59
|
-
"@payloadcms/translations": "^3.0.0-beta.
|
60
|
-
"@payloadcms/ui": "^3.0.0-beta.
|
61
|
-
"payload": "^3.0.0-beta.
|
59
|
+
"@payloadcms/translations": "^3.0.0-beta.53",
|
60
|
+
"@payloadcms/ui": "^3.0.0-beta.53",
|
61
|
+
"payload": "^3.0.0-beta.53"
|
62
62
|
},
|
63
63
|
"publishConfig": {
|
64
64
|
"registry": "https://registry.npmjs.org/"
|