@payload-enchants/translator 1.2.0-pre.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/dist/client/api/index.js.map +1 -1
  2. package/dist/client/components/CustomButton/CustomButtonWithTranslator.js.map +1 -1
  3. package/dist/client/components/CustomButton/index.d.ts.map +1 -1
  4. package/dist/client/components/CustomButton/index.js +1 -2
  5. package/dist/client/components/CustomButton/index.js.map +1 -1
  6. package/dist/client/components/LocaleLabel/LocaleLabel.js.map +1 -1
  7. package/dist/client/components/LocaleLabel/index.js.map +1 -1
  8. package/dist/client/components/ResolverButton/ResolverButton.js.map +1 -1
  9. package/dist/client/components/ResolverButton/index.js.map +1 -1
  10. package/dist/client/components/TranslatorModal/Content.js.map +1 -1
  11. package/dist/client/components/TranslatorModal/TranslatorModal.js.map +1 -1
  12. package/dist/client/components/TranslatorModal/index.js.map +1 -1
  13. package/dist/client/providers/Translator/TranslatorProvider.d.ts.map +1 -1
  14. package/dist/client/providers/Translator/TranslatorProvider.js +2 -1
  15. package/dist/client/providers/Translator/TranslatorProvider.js.map +1 -1
  16. package/dist/client/providers/Translator/context.js.map +1 -1
  17. package/dist/i18n-translations.js.map +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/resolvers/copy.js.map +1 -1
  20. package/dist/resolvers/google.js.map +1 -1
  21. package/dist/resolvers/openAI.js.map +1 -1
  22. package/dist/resolvers/types.js.map +1 -1
  23. package/dist/translate/endpoint.js.map +1 -1
  24. package/dist/translate/findEntityWithConfig.js.map +1 -1
  25. package/dist/translate/operation.d.ts.map +1 -1
  26. package/dist/translate/operation.js +0 -1
  27. package/dist/translate/operation.js.map +1 -1
  28. package/dist/translate/traverseFields.js.map +1 -1
  29. package/dist/translate/traverseRichText.js.map +1 -1
  30. package/dist/translate/types.js.map +1 -1
  31. package/dist/translate/updateEntity.js.map +1 -1
  32. package/dist/types.d.ts +3 -3
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/types.js.map +1 -1
  35. package/dist/utils/chunkArray.js.map +1 -1
  36. package/dist/utils/isEmpty.js.map +1 -1
  37. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/api/index.ts"],"sourcesContent":["import type { TranslateEndpointArgs, TranslateResult } from '../../translate/types';\n\nexport const createClient = ({ api, serverURL }: { api: string; serverURL: string }) => {\n const translate = async (args: TranslateEndpointArgs): Promise<TranslateResult> => {\n try {\n const response = await fetch(`${serverURL}${api}/translator/translate`, {\n body: JSON.stringify(args),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n });\n\n if (!response.ok) return { success: false };\n\n return response.json();\n } catch (e) {\n if (e instanceof Error) console.error(e.message);\n\n return { success: false };\n }\n };\n\n return {\n translate,\n };\n};\n"],"names":["createClient","api","serverURL","translate","args","response","fetch","body","JSON","stringify","credentials","headers","method","ok","success","json","e","Error","console","error","message"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,eAAe,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAsC;IACjF,MAAMC,YAAY,OAAOC;QACvB,IAAI;YACF,MAAMC,WAAW,MAAMC,MAAM,CAAC,EAAEJ,UAAU,EAAED,IAAI,qBAAqB,CAAC,EAAE;gBACtEM,MAAMC,KAAKC,SAAS,CAACL;gBACrBM,aAAa;gBACbC,SAAS;oBACP,gBAAgB;gBAClB;gBACAC,QAAQ;YACV;YAEA,IAAI,CAACP,SAASQ,EAAE,EAAE,OAAO;gBAAEC,SAAS;YAAM;YAE1C,OAAOT,SAASU,IAAI;QACtB,EAAE,OAAOC,GAAG;YACV,IAAIA,aAAaC,OAAOC,QAAQC,KAAK,CAACH,EAAEI,OAAO;YAE/C,OAAO;gBAAEN,SAAS;YAAM;QAC1B;IACF;IAEA,OAAO;QACLX;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../src/client/api/index.ts"],"sourcesContent":["import type { TranslateEndpointArgs, TranslateResult } from '../../translate/types';\n\nexport const createClient = ({ api, serverURL }: { api: string; serverURL: string }) => {\n const translate = async (args: TranslateEndpointArgs): Promise<TranslateResult> => {\n try {\n const response = await fetch(`${serverURL}${api}/translator/translate`, {\n body: JSON.stringify(args),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n });\n\n if (!response.ok) return { success: false };\n\n return response.json();\n } catch (e) {\n if (e instanceof Error) console.error(e.message);\n\n return { success: false };\n }\n };\n\n return {\n translate,\n };\n};\n"],"names":["createClient","api","serverURL","translate","args","response","fetch","body","JSON","stringify","credentials","headers","method","ok","success","json","e","Error","console","error","message"],"mappings":"AAEA,OAAO,MAAMA,eAAe,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAsC;IACjF,MAAMC,YAAY,OAAOC;QACvB,IAAI;YACF,MAAMC,WAAW,MAAMC,MAAM,CAAC,EAAEJ,UAAU,EAAED,IAAI,qBAAqB,CAAC,EAAE;gBACtEM,MAAMC,KAAKC,SAAS,CAACL;gBACrBM,aAAa;gBACbC,SAAS;oBACP,gBAAgB;gBAClB;gBACAC,QAAQ;YACV;YAEA,IAAI,CAACP,SAASQ,EAAE,EAAE,OAAO;gBAAEC,SAAS;YAAM;YAE1C,OAAOT,SAASU,IAAI;QACtB,EAAE,OAAOC,GAAG;YACV,IAAIA,aAAaC,OAAOC,QAAQC,KAAK,CAACH,EAAEI,OAAO;YAE/C,OAAO;gBAAEN,SAAS;YAAM;QAC1B;IACF;IAEA,OAAO;QACLX;IACF;AACF,EAAE"}
@@ -1 +1 @@
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
+ {"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"],"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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/index.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,SAAU,SAAS,GAAG,MAAM,sCAMpD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/index.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,SAAU,SAAS,GAAG,MAAM,sCAMpD,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { DefaultPublishButton } from '@payloadcms/ui';
3
- import { DefaultSaveButton } from '@payloadcms/ui/elements/SaveButton';
2
+ import { DefaultPublishButton, DefaultSaveButton } from '@payloadcms/ui';
4
3
  import { CustomButtonWithTranslator } from './CustomButtonWithTranslator';
5
4
  export const CustomButton = (type)=>{
6
5
  return ()=>{
@@ -1 +1 @@
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
+ {"version":3,"sources":["../../../../src/client/components/CustomButton/index.tsx"],"sourcesContent":["import { DefaultPublishButton, DefaultSaveButton } from '@payloadcms/ui';\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"],"mappings":";AAAA,SAASA,oBAAoB,EAAEC,iBAAiB,QAAQ,iBAAiB;AAEzE,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,"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 &nbsp;&nbsp;\n <span className={`${baseClass}__current-label`}>\n {`${getTranslation(locale.label, i18n)}`}\n </span>\n &nbsp;\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
+ {"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 &nbsp;&nbsp;\n <span className={`${baseClass}__current-label`}>\n {`${getTranslation(locale.label, i18n)}`}\n </span>\n &nbsp;\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"],"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,"sources":["../../../../src/client/components/LocaleLabel/index.ts"],"sourcesContent":["export * from './LocaleLabel';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,gBAAgB"}
1
+ {"version":3,"sources":["../../../../src/client/components/LocaleLabel/index.ts"],"sourcesContent":["export * from './LocaleLabel';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB"}
@@ -1 +1 @@
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
+ {"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"],"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,"sources":["../../../../src/client/components/ResolverButton/index.ts"],"sourcesContent":["export * from './ResolverButton';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,mBAAmB"}
1
+ {"version":3,"sources":["../../../../src/client/components/ResolverButton/index.ts"],"sourcesContent":["export * from './ResolverButton';\n"],"names":[],"mappings":"AAAA,cAAc,mBAAmB"}
@@ -1 +1 @@
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
+ {"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"],"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 +1 @@
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
+ {"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"],"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,"sources":["../../../../src/client/components/TranslatorModal/index.ts"],"sourcesContent":["export * from './TranslatorModal';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,oBAAoB"}
1
+ {"version":3,"sources":["../../../../src/client/components/TranslatorModal/index.ts"],"sourcesContent":["export * from './TranslatorModal';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB"}
@@ -1 +1 @@
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
+ {"version":3,"file":"TranslatorProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,SAAS,EAAgC,MAAM,OAAO,CAAC;AASrE,eAAO,MAAM,kBAAkB,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,gCAoIvE,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { toast, useAllFormFields, useConfig, useDocumentInfo, useForm, useLocale, useModal, useTranslation } from '@payloadcms/ui';
3
- import { getFormState, reduceFieldsToValues } from '@payloadcms/ui/shared';
3
+ import { getFormState } from '@payloadcms/ui/shared';
4
+ import { reduceFieldsToValues } from 'payload/shared';
4
5
  import { useEffect, useMemo, useState } from 'react';
5
6
  import { createClient } from '../../api';
6
7
  import { TranslatorContext } from './context';
@@ -1 +1 @@
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,wBAAwB;AAC3E,SAAyBC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAIrE,SAASC,YAAY,QAAQ,YAAY;AACzC,SAASC,iBAAiB,QAAQ,YAAY;AAE9C,MAAMC,YAAY;AAElB,OAAO,MAAMC,qBAAqB,CAAC,EAAEC,QAAQ,EAA2B;IACtE,MAAM,CAACC,UAAUC,YAAY,GAAGP,SAAwB;IAExD,MAAM,CAACQ,MAAMC,SAAS,GAAGpB;IAEzB,MAAM,EAAEqB,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAE,GAAGrB;IAE3C,MAAM,EAAEsB,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,UAAU;QAEf,MAAMuC,OAAsB;YAC1BnC;YACAF,MAAMX,qBAAqBW,MAAM;YACjCoC;YACAjC;YACAC,IAAIA,OAAO,OAAOiB,YAAYjB;YAC9BM,QAAQA,OAAOkB,IAAI;YACnBU,YAAYT;YACZ/B;QACF;QAEA,MAAMyC,SAAS,MAAMtB,UAAUuB,SAAS,CAACH;QAEzC,IAAI,CAACE,OAAOE,OAAO,EAAE;YACnB7D,MAAM8D,KAAK,CAAClC,UAAU;YAEtB;QACF;QAEAP,SAAS;YACP0C,OAAO,MAAMvD,aAAa;gBACxBwD,UAAU7B;gBACV8B,MAAM;oBACJ3C;oBACAF,MAAMuC,OAAOO,cAAc;oBAC3B3C;oBACAO,QAAQA,OAAOkB,IAAI;oBACnBmB,YAAY7C,kBAAkBC,cAAc;gBAC9C;gBACAa;YACF;YACAgC,MAAM;QACR;QAEA,IAAI9B,gBAAgB;YAClBb,YAAY;YACZzB,MAAM6D,OAAO,CAACjC,UAAU;QAC1B;QACAyB;IACF;IAEA,qBACE,KAACvC,kBAAkBuD,QAAQ;QACzBC,OAAO;YACLjB;YACAJ;YACAJ;YACA9B;YACAwD,gBAAgB,CAAC,EAAEC,WAAW,EAAE;gBAC9BrD,YAAYqD;gBACZ9C,MAAM+C,SAAS,CAAC1D;YAClB;YACAG,UAAUoB;YACVV;YACAsB;YACAK;QACF;kBAECtC;;AAGP,EAAE"}
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 } from '@payloadcms/ui/shared';\nimport { reduceFieldsToValues } from 'payload/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"],"mappings":";AAAA,SACEA,KAAK,EACLC,gBAAgB,EAChBC,SAAS,EACTC,eAAe,EACfC,OAAO,EACPC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAiB;AACxB,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,oBAAoB,QAAQ,iBAAiB;AACtD,SAAyBC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAIrE,SAASC,YAAY,QAAQ,YAAY;AACzC,SAASC,iBAAiB,QAAQ,YAAY;AAE9C,MAAMC,YAAY;AAElB,OAA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AoBD,yBAAyBC,mBAAmBH,IAAI;QACxEE,yBAAyBL,cAAc,CAAC,EAAE,CAACG,IAAI;IACjD,GAAG;QAAClB;KAAO;IAEX,MAAMuB,kBAAkB,IAAM3B,MAAM4B,UAAU,CAACvC;IAE/C,MAAMwC,SAAS,OAAO,EAAEC,SAAS,EAA0B;QACzD,IAAI,CAACtC,UAAU;QAEf,MAAMuC,OAAsB;YAC1BnC;YACAF,MAAMX,qBAAqBW,MAAM;YACjCoC;YACAjC;YACAC,IAAIA,OAAO,OAAOiB,YAAYjB;YAC9BM,QAAQA,OAAOkB,IAAI;YACnBU,YAAYT;YACZ/B;QACF;QAEA,MAAMyC,SAAS,MAAMtB,UAAUuB,SAAS,CAACH;QAEzC,IAAI,CAACE,OAAOE,OAAO,EAAE;YACnB7D,MAAM8D,KAAK,CAAClC,UAAU;YAEtB;QACF;QAEAP,SAAS;YACP0C,OAAO,MAAMvD,aAAa;gBACxBwD,UAAU7B;gBACV8B,MAAM;oBACJ3C;oBACAF,MAAMuC,OAAOO,cAAc;oBAC3B3C;oBACAO,QAAQA,OAAOkB,IAAI;oBACnBmB,YAAY7C,kBAAkBC,cAAc;gBAC9C;gBACAa;YACF;YACAgC,MAAM;QACR;QAEA,IAAI9B,gBAAgB;YAClBb,YAAY;YACZzB,MAAM6D,OAAO,CAACjC,UAAU;QAC1B;QACAyB;IACF;IAEA,qBACE,KAACvC,kBAAkBuD,QAAQ;QACzBC,OAAO;YACLjB;YACAJ;YACAJ;YACA9B;YACAwD,gBAAgB,CAAC,EAAEC,WAAW,EAAE;gBAC9BrD,YAAYqD;gBACZ9C,MAAM+C,SAAS,CAAC1D;YAClB;YACAG,UAAUoB;YACVV;YACAsB;YACAK;QACF;kBAECtC;;AAGP,EAAE"}
@@ -1 +1 @@
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"}
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"],"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"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/i18n-translations.ts"],"sourcesContent":["export const translations = {\n en: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Copy from other locale',\n resolver_copy_errorMessage: 'An error occurred when trying to translate the data',\n resolver_copy_modalTitle: 'Choose the locale to copy from',\n resolver_copy_submitButtonLabelEmpty: 'Copy only empty fields',\n resolver_copy_submitButtonLabelFull: 'Copy all',\n resolver_copy_successMessage: 'Successfully copied. Press \"Save\" to apply the changes.',\n\n resolver_google_buttonLabel: 'Google Translate',\n resolver_google_errorMessage: 'An error occurred when trying to translate the data',\n resolver_google_modalTitle: 'Choose the locale to translate from',\n resolver_google_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_google_submitButtonLabelFull: 'Translate all',\n resolver_google_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n\n resolver_openai_buttonLabel: 'AI Translate',\n resolver_openai_errorMessage: 'An error occurred when trying to translate the data',\n resolver_openai_modalTitle: 'Choose the locale to translate from',\n resolver_openai_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_openai_submitButtonLabelFull: 'Translate all',\n resolver_openai_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n },\n },\n uk: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Копіювати з іншої локалі',\n resolver_copy_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_copy_modalTitle: 'Виберіть локаль для копіювання',\n resolver_copy_submitButtonLabelEmpty: 'Копіювати лише порожні поля',\n resolver_copy_submitButtonLabelFull: 'Копіювати все',\n resolver_copy_successMessage:\n 'Успішно скопійовано. Натисніть \"Зберегти\", щоб застосувати зміни.',\n resolver_google_buttonLabel: 'Переклад Google',\n resolver_google_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_google_modalTitle: 'Виберіть локаль для перекладу',\n resolver_google_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_google_submitButtonLabelFull: 'Перекласти все',\n resolver_google_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n resolver_openai_buttonLabel: 'Переклад AI',\n resolver_openai_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_openai_modalTitle: 'Виберіть локаль для перекладу',\n resolver_openai_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_openai_submitButtonLabelFull: 'Перекласти все',\n resolver_openai_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n },\n },\n zh: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: '从其他语言复制',\n resolver_copy_errorMessage: '尝试翻译数据时发生错误',\n resolver_copy_modalTitle: '选择要复制的语言',\n resolver_copy_submitButtonLabelEmpty: '仅复制空字段',\n resolver_copy_submitButtonLabelFull: '复制全部',\n resolver_copy_successMessage: '复制成功。按下“保存”以应用更改。',\n\n resolver_google_buttonLabel: '谷歌翻译',\n resolver_google_errorMessage: '尝试翻译数据时发生错误',\n resolver_google_modalTitle: '选择要翻译的语言',\n resolver_google_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_google_submitButtonLabelFull: '翻译全部',\n resolver_google_successMessage: '翻译成功。按下“保存”以应用更改。',\n\n resolver_openai_buttonLabel: 'AI翻译',\n resolver_openai_errorMessage: '尝试翻译数据时发生错误',\n resolver_openai_modalTitle: '选择要翻译的语言',\n resolver_openai_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_openai_submitButtonLabelFull: '翻译全部',\n resolver_openai_successMessage: '翻译成功。按下“保存”以应用更改。',\n },\n },\n};\n"],"names":["translations","en","resolver_copy_buttonLabel","resolver_copy_errorMessage","resolver_copy_modalTitle","resolver_copy_submitButtonLabelEmpty","resolver_copy_submitButtonLabelFull","resolver_copy_successMessage","resolver_google_buttonLabel","resolver_google_errorMessage","resolver_google_modalTitle","resolver_google_submitButtonLabelEmpty","resolver_google_submitButtonLabelFull","resolver_google_successMessage","resolver_openai_buttonLabel","resolver_openai_errorMessage","resolver_openai_modalTitle","resolver_openai_submitButtonLabelEmpty","resolver_openai_submitButtonLabelFull","resolver_openai_successMessage","uk","zh"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,eAAe;IAC1BC,IAAI;QACF,qBAAqB;YACnBC,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BAA8B;YAE9BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;YAEhCC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;QAClC;IACF;IACAC,IAAI;QACF,qBAAqB;YACnBlB,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BACE;YACFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;YACFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;QACJ;IACF;IACAE,IAAI;QACF,qBAAqB;YACnBnB,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BAA8B;YAE9BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;YAEhCC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;QAClC;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../src/i18n-translations.ts"],"sourcesContent":["export const translations = {\n en: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Copy from other locale',\n resolver_copy_errorMessage: 'An error occurred when trying to translate the data',\n resolver_copy_modalTitle: 'Choose the locale to copy from',\n resolver_copy_submitButtonLabelEmpty: 'Copy only empty fields',\n resolver_copy_submitButtonLabelFull: 'Copy all',\n resolver_copy_successMessage: 'Successfully copied. Press \"Save\" to apply the changes.',\n\n resolver_google_buttonLabel: 'Google Translate',\n resolver_google_errorMessage: 'An error occurred when trying to translate the data',\n resolver_google_modalTitle: 'Choose the locale to translate from',\n resolver_google_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_google_submitButtonLabelFull: 'Translate all',\n resolver_google_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n\n resolver_openai_buttonLabel: 'AI Translate',\n resolver_openai_errorMessage: 'An error occurred when trying to translate the data',\n resolver_openai_modalTitle: 'Choose the locale to translate from',\n resolver_openai_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_openai_submitButtonLabelFull: 'Translate all',\n resolver_openai_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n },\n },\n uk: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Копіювати з іншої локалі',\n resolver_copy_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_copy_modalTitle: 'Виберіть локаль для копіювання',\n resolver_copy_submitButtonLabelEmpty: 'Копіювати лише порожні поля',\n resolver_copy_submitButtonLabelFull: 'Копіювати все',\n resolver_copy_successMessage:\n 'Успішно скопійовано. Натисніть \"Зберегти\", щоб застосувати зміни.',\n resolver_google_buttonLabel: 'Переклад Google',\n resolver_google_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_google_modalTitle: 'Виберіть локаль для перекладу',\n resolver_google_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_google_submitButtonLabelFull: 'Перекласти все',\n resolver_google_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n resolver_openai_buttonLabel: 'Переклад AI',\n resolver_openai_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_openai_modalTitle: 'Виберіть локаль для перекладу',\n resolver_openai_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_openai_submitButtonLabelFull: 'Перекласти все',\n resolver_openai_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n },\n },\n zh: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: '从其他语言复制',\n resolver_copy_errorMessage: '尝试翻译数据时发生错误',\n resolver_copy_modalTitle: '选择要复制的语言',\n resolver_copy_submitButtonLabelEmpty: '仅复制空字段',\n resolver_copy_submitButtonLabelFull: '复制全部',\n resolver_copy_successMessage: '复制成功。按下“保存”以应用更改。',\n\n resolver_google_buttonLabel: '谷歌翻译',\n resolver_google_errorMessage: '尝试翻译数据时发生错误',\n resolver_google_modalTitle: '选择要翻译的语言',\n resolver_google_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_google_submitButtonLabelFull: '翻译全部',\n resolver_google_successMessage: '翻译成功。按下“保存”以应用更改。',\n\n resolver_openai_buttonLabel: 'AI翻译',\n resolver_openai_errorMessage: '尝试翻译数据时发生错误',\n resolver_openai_modalTitle: '选择要翻译的语言',\n resolver_openai_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_openai_submitButtonLabelFull: '翻译全部',\n resolver_openai_successMessage: '翻译成功。按下“保存”以应用更改。',\n },\n },\n};\n"],"names":["translations","en","resolver_copy_buttonLabel","resolver_copy_errorMessage","resolver_copy_modalTitle","resolver_copy_submitButtonLabelEmpty","resolver_copy_submitButtonLabelFull","resolver_copy_successMessage","resolver_google_buttonLabel","resolver_google_errorMessage","resolver_google_modalTitle","resolver_google_submitButtonLabelEmpty","resolver_google_submitButtonLabelFull","resolver_google_successMessage","resolver_openai_buttonLabel","resolver_openai_errorMessage","resolver_openai_modalTitle","resolver_openai_submitButtonLabelEmpty","resolver_openai_submitButtonLabelFull","resolver_openai_successMessage","uk","zh"],"mappings":"AAAA,OAAO,MAAMA,eAAe;IAC1BC,IAAI;QACF,qBAAqB;YACnBC,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BAA8B;YAE9BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;YAEhCC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;QAClC;IACF;IACAC,IAAI;QACF,qBAAqB;YACnBlB,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BACE;YACFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;YACFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;QACJ;IACF;IACAE,IAAI;QACF,qBAAqB;YACnBnB,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BAA8B;YAE9BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;YAEhCC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;QAClC;IACF;AACF,EAAE"}
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';\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,WAAWR,aAAaQ,SAAS,CAACC,GAAG,CAAC,CAAC,EAAEC,GAAG,EAAE,GAAM,CAAA;gCAAEA;4BAAI,CAAA;oBAC5D;gBACF;YACF;YACAC,aACEV,OAAOU,WAAW,EAAEF,IAAI,CAACG;gBACvB,IAAI,CAACZ,aAAaW,WAAW,CAACE,QAAQ,CAACD,WAAWE,IAAI,GAAG,OAAOF;gBAEhE,OAAO;oBACL,GAAGA,UAAU;oBACbN,OAAO;wBACL,GAAIM,WAAWN,KAAK,IAAI,CAAC,CAAC;wBAC1BS,YAAY;4BACV,GAAIH,WAAWN,KAAK,EAAES,cAAc,CAAC,CAAC;4BACtCC,MAAM;gCACJ,GAAIJ,WAAWN,KAAK,EAAES,YAAYC,QAAQ,CAAC,CAAC;gCAC5CC,eAAetB,aAAa;gCAC5BuB,YAAYvB,aAAa;4BAC3B;wBACF;oBACF;gBACF;YACF,MAAM,EAAE;YACVY,QAAQ;gBACN,GAAIN,OAAOM,MAAM,IAAI,CAAC,CAAC;gBACvBR,YAAY;oBACVS,WAAWR,aAAaQ,SAAS;gBACnC;YACF;YACAW,WAAW;mBACLlB,OAAOkB,SAAS,IAAI,EAAE;gBAC1B;oBACEC,SAASvB;oBACTwB,QAAQ;oBACRC,MAAM;gBACR;aACD;YACDC,SACEtB,OAAOsB,OAAO,EAAEd,IAAI,CAACe;gBACnB,IAAI,CAACxB,aAAauB,OAAO,CAACV,QAAQ,CAACW,OAAOV,IAAI,GAAG,OAAOU;gBAExD,OAAO;oBACL,GAAGA,MAAM;oBACTlB,OAAO;wBACL,GAAIkB,OAAOlB,KAAK,IAAI,CAAC,CAAC;wBACtBS,YAAY;4BACV,GAAIS,OAAOlB,KAAK,EAAES,cAAc,CAAC,CAAC;4BAClCU,UAAU;gCACR,GAAID,OAAOlB,KAAK,EAAES,YAAYU,YAAY,CAAC,CAAC;gCAC5CR,eAAetB,aAAa;gCAC5BuB,YAAYvB,aAAa;4BAC3B;wBACF;oBACF;gBACF;YACF,MAAM,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
+ {"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"],"mappings":"AAAA,mDAAm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W,WAAW;mBACLlB,OAAOkB,SAAS,IAAI,EAAE;gBAC1B;oBACEC,SAASvB;oBACTwB,QAAQ;oBACRC,MAAM;gBACR;aACD;YACDC,SACEtB,OAAOsB,OAAO,EAAEd,IAAI,CAACe;gBACnB,IAAI,CAACxB,aAAauB,OAAO,CAACV,QAAQ,CAACW,OAAOV,IAAI,GAAG,OAAOU;gBAExD,OAAO;oBACL,GAAGA,MAAM;oBACTlB,OAAO;wBACL,GAAIkB,OAAOlB,KAAK,IAAI,CAAC,CAAC;wBACtBS,YAAY;4BACV,GAAIS,OAAOlB,KAAK,EAAES,cAAc,CAAC,CAAC;4BAClCU,UAAU;gCACR,GAAID,OAAOlB,KAAK,EAAES,YAAYU,YAAY,CAAC,CAAC;gCAC5CR,eAAetB,aAAa;gCAC5BuB,YAAYvB,aAAa;4BAC3B;wBACF;oBACF;gBACF;YACF,MAAM,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,"sources":["../../src/resolvers/copy.ts"],"sourcesContent":["import type { TranslateResolver } from './types';\n\nexport const copyResolver = (): TranslateResolver => {\n return {\n key: 'copy',\n resolve: (args) => {\n const { texts } = args;\n\n return {\n success: true,\n translatedTexts: texts,\n };\n },\n };\n};\n"],"names":["copyResolver","key","resolve","args","texts","success","translatedTexts"],"rangeMappings":";;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,eAAe;IAC1B,OAAO;QACLC,KAAK;QACLC,SAAS,CAACC;YACR,MAAM,EAAEC,KAAK,EAAE,GAAGD;YAElB,OAAO;gBACLE,SAAS;gBACTC,iBAAiBF;YACnB;QACF;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/resolvers/copy.ts"],"sourcesContent":["import type { TranslateResolver } from './types';\n\nexport const copyResolver = (): TranslateResolver => {\n return {\n key: 'copy',\n resolve: (args) => {\n const { texts } = args;\n\n return {\n success: true,\n translatedTexts: texts,\n };\n },\n };\n};\n"],"names":["copyResolver","key","resolve","args","texts","success","translatedTexts"],"mappings":"AAEA,OAAO,MAAMA,eAAe;IAC1B,OAAO;QACLC,KAAK;QACLC,SAAS,CAACC;YACR,MAAM,EAAEC,KAAK,EAAE,GAAGD;YAElB,OAAO;gBACLE,SAAS;gBACTC,iBAAiBF;YACnB;QACF;IACF;AACF,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resolvers/google.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\nimport type { TranslateResolver } from './types';\n\ntype GoogleResponse = {\n data: {\n data: {\n translations: {\n detectedSourceLanguage: string;\n model: string;\n translatedText: string;\n }[];\n };\n };\n success: boolean;\n};\n\nconst localeToCountryCodeMapper = {\n ua: 'uk',\n};\n\nconst mapLocale = (incoming: string) =>\n incoming in localeToCountryCodeMapper\n ? localeToCountryCodeMapper[incoming as keyof typeof localeToCountryCodeMapper]\n : incoming;\n\nexport type GoogleResolverConfig = {\n apiKey: string;\n /**\n * How many texts to include into 1 request\n * @default 100\n */\n chunkLength?: number;\n};\n\nexport const googleResolver = ({\n apiKey,\n chunkLength = 100,\n}: GoogleResolverConfig): TranslateResolver => {\n return {\n key: 'google',\n resolve: async (args) => {\n const { localeFrom, localeTo, req, texts } = args;\n\n const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;\n\n const responses: GoogleResponse[] = await Promise.all(\n chunkArray(texts, chunkLength).map((q) =>\n fetch(apiUrl, {\n body: JSON.stringify({\n q,\n source: mapLocale(localeFrom),\n target: mapLocale(localeTo),\n }),\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n }).then(async (res) => {\n const data = await res.json();\n\n if (!res.ok)\n req.payload.logger.info({\n googleResponse: data,\n message: `An error occurred when trying to translate the data using Google API`,\n });\n\n return {\n data,\n success: res.ok,\n };\n }),\n ),\n );\n\n if (responses.some((res) => !res.success)) {\n return {\n success: false,\n };\n }\n\n const translatedTexts = responses\n .flatMap((chunk) => chunk.data.data.translations)\n .map((translation) => translation.translatedText);\n\n return {\n success: true,\n translatedTexts,\n };\n },\n };\n};\n"],"names":["chunkArray","localeToCountryCodeMapper","ua","mapLocale","incoming","googleResolver","apiKey","chunkLength","key","resolve","args","localeFrom","localeTo","req","texts","apiUrl","responses","Promise","all","map","q","fetch","body","JSON","stringify","source","target","headers","method","then","res","data","json","ok","payload","logger","info","googleResponse","message","success","some","translatedTexts","flatMap","chunk","translations","translation","translatedText"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AAgBjD,MAAMC,4BAA4B;IAChCC,IAAI;AACN;AAEA,MAAMC,YAAY,CAACC,WACjBA,YAAYH,4BACRA,yBAAyB,CAACG,SAAmD,GAC7EA;AAWN,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,cAAc,GAAG,EACI;IACrB,OAAO;QACLC,KAAK;QACLC,SAAS,OAAOC;YACd,MAAM,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAE,GAAGJ;YAE7C,MAAMK,SAAS,CAAC,6DAA6D,EAAET,OAAO,CAAC;YAEvF,MAAMU,YAA8B,MAAMC,QAAQC,GAAG,CACnDlB,WAAWc,OAAOP,aAAaY,GAAG,CAAC,CAACC,IAClCC,MAAMN,QAAQ;oBACZO,MAAMC,KAAKC,SAAS,CAAC;wBACnBJ;wBACAK,QAAQtB,UAAUQ;wBAClBe,QAAQvB,UAAUS;oBACpB;oBACAe,SAAS;wBACP,gBAAgB;oBAClB;oBACAC,QAAQ;gBACV,GAAGC,IAAI,CAAC,OAAOC;oBACb,MAAMC,OAAO,MAAMD,IAAIE,IAAI;oBAE3B,IAAI,CAACF,IAAIG,EAAE,EACTpB,IAAIqB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;wBACtBC,gBAAgBN;wBAChBO,SAAS,CAAC,oEAAoE,CAAC;oBACjF;oBAEF,OAAO;wBACLP;wBACAQ,SAAST,IAAIG,EAAE;oBACjB;gBACF;YAIJ,IAAIjB,UAAUwB,IAAI,CAAC,CAACV,MAAQ,CAACA,IAAIS,OAAO,GAAG;gBACzC,OAAO;oBACLA,SAAS;gBACX;YACF;YAEA,MAAME,kBAAkBzB,UACrB0B,OAAO,CAAC,CAACC,QAAUA,MAAMZ,IAAI,CAACA,IAAI,CAACa,YAAY,EAC/CzB,GAAG,CAAC,CAAC0B,cAAgBA,YAAYC,cAAc;YAElD,OAAO;gBACLP,SAAS;gBACTE;YACF;QACF;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/resolvers/google.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\nimport type { TranslateResolver } from './types';\n\ntype GoogleResponse = {\n data: {\n data: {\n translations: {\n detectedSourceLanguage: string;\n model: string;\n translatedText: string;\n }[];\n };\n };\n success: boolean;\n};\n\nconst localeToCountryCodeMapper = {\n ua: 'uk',\n};\n\nconst mapLocale = (incoming: string) =>\n incoming in localeToCountryCodeMapper\n ? localeToCountryCodeMapper[incoming as keyof typeof localeToCountryCodeMapper]\n : incoming;\n\nexport type GoogleResolverConfig = {\n apiKey: string;\n /**\n * How many texts to include into 1 request\n * @default 100\n */\n chunkLength?: number;\n};\n\nexport const googleResolver = ({\n apiKey,\n chunkLength = 100,\n}: GoogleResolverConfig): TranslateResolver => {\n return {\n key: 'google',\n resolve: async (args) => {\n const { localeFrom, localeTo, req, texts } = args;\n\n const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;\n\n const responses: GoogleResponse[] = await Promise.all(\n chunkArray(texts, chunkLength).map((q) =>\n fetch(apiUrl, {\n body: JSON.stringify({\n q,\n source: mapLocale(localeFrom),\n target: mapLocale(localeTo),\n }),\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n }).then(async (res) => {\n const data = await res.json();\n\n if (!res.ok)\n req.payload.logger.info({\n googleResponse: data,\n message: `An error occurred when trying to translate the data using Google API`,\n });\n\n return {\n data,\n success: res.ok,\n };\n }),\n ),\n );\n\n if (responses.some((res) => !res.success)) {\n return {\n success: false,\n };\n }\n\n const translatedTexts = responses\n .flatMap((chunk) => chunk.data.data.translations)\n .map((translation) => translation.translatedText);\n\n return {\n success: true,\n translatedTexts,\n };\n },\n };\n};\n"],"names":["chunkArray","localeToCountryCodeMapper","ua","mapLocale","incoming","googleResolver","apiKey","chunkLength","key","resolve","args","localeFrom","localeTo","req","texts","apiUrl","responses","Promise","all","map","q","fetch","body","JSON","stringify","source","target","headers","method","then","res","data","json","ok","payload","logger","info","googleResponse","message","success","some","translatedTexts","flatMap","chunk","translations","translation","translatedText"],"mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AAgBjD,MAAMC,4BAA4B;IAChCC,IAAI;AACN;AAEA,MAAMC,YAAY,CAACC,WACjBA,YAAYH,4BACRA,yBAAyB,CAACG,SAAmD,GAC7EA;AAWN,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,cAAc,GAAG,EACI;IACrB,OAAO;QACLC,KAAK;QACLC,SAAS,OAAOC;YACd,MAAM,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAE,GAAGJ;YAE7C,MAAMK,SAAS,CAAC,6DAA6D,EAAET,OAAO,CAAC;YAEvF,MAAMU,YAA8B,MAAMC,QAAQC,GAAG,CACnDlB,WAAWc,OAAOP,aAAaY,GAAG,CAAC,CAACC,IAClCC,MAAMN,QAAQ;oBACZO,MAAMC,KAAKC,SAAS,CAAC;wBACnBJ;wBACAK,QAAQtB,UAAUQ;wBAClBe,QAAQvB,UAAUS;oBACpB;oBACAe,SAAS;wBACP,gBAAgB;oBAClB;oBACAC,QAAQ;gBACV,GAAGC,IAAI,CAAC,OAAOC;oBACb,MAAMC,OAAO,MAAMD,IAAIE,IAAI;oBAE3B,IAAI,CAACF,IAAIG,EAAE,EACTpB,IAAIqB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;wBACtBC,gBAAgBN;wBAChBO,SAAS,CAAC,oEAAoE,CAAC;oBACjF;oBAEF,OAAO;wBACLP;wBACAQ,SAAST,IAAIG,EAAE;oBACjB;gBACF;YAIJ,IAAIjB,UAAUwB,IAAI,CAAC,CAACV,MAAQ,CAACA,IAAIS,OAAO,GAAG;gBACzC,OAAO;oBACLA,SAAS;gBACX;YACF;YAEA,MAAME,kBAAkBzB,UACrB0B,OAAO,CAAC,CAACC,QAAUA,MAAMZ,IAAI,CAACA,IAAI,CAACa,YAAY,EAC/CzB,GAAG,CAAC,CAAC0B,cAAgBA,YAAYC,cAAc;YAElD,OAAO;gBACLP,SAAS;gBACTE;YACF;QACF;IACF;AACF,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resolvers/openAI.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\nimport type { TranslateResolver } from './types';\n\nexport type OpenAIPrompt = (args: {\n localeFrom: string;\n localeTo: string;\n texts: string[];\n}) => string;\n\nexport type OpenAIResolverConfig = {\n apiKey: string;\n baseUrl?: string;\n /**\n * How many texts to include into 1 request\n * @default 100\n */\n chunkLength?: number;\n /**\n * @default \"gpt-3.5-turbo\"\n */\n model?: string;\n promt?: OpenAIPrompt;\n};\n\ntype OpenAIResponse = {\n choices: {\n message: {\n content: string;\n };\n }[];\n};\n\nconst defaultPromt: OpenAIPrompt = ({ localeFrom, localeTo, texts }) => {\n return `Translate me the following array: ${JSON.stringify(texts)} in locale=${localeFrom} to locale ${localeTo}, respond me with the same array structure`;\n};\n\nexport const openAIResolver = ({\n apiKey,\n baseUrl,\n chunkLength = 100,\n model = 'gpt-3.5-turbo',\n promt = defaultPromt,\n}: OpenAIResolverConfig): TranslateResolver => {\n return {\n key: 'openai',\n resolve: async ({ localeFrom, localeTo, req, texts }) => {\n const apiUrl = `${baseUrl || 'https://api.openai.com'}/v1/chat/completions`;\n\n try {\n const respones: {\n data: OpenAIResponse;\n success: boolean;\n }[] = await Promise.all(\n chunkArray(texts, chunkLength).map((texts) => {\n return fetch(apiUrl, {\n body: JSON.stringify({\n messages: [\n {\n content: promt({ localeFrom, localeTo, texts }),\n role: 'user',\n },\n ],\n model,\n }),\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n method: 'post',\n }).then(async (res) => {\n const data = await res.json();\n\n if (!res.ok)\n req.payload.logger.info({\n message: `An error occurred when trying to translate the data using OpenAI API`,\n openAIresponse: data,\n });\n\n return {\n data,\n success: res.ok,\n };\n });\n }),\n );\n\n const translated: string[] = [];\n\n for (const { data, success } of respones) {\n if (!success)\n return {\n success: false as const,\n };\n\n const content = data?.choices?.[0]?.message?.content;\n\n if (!content) {\n req.payload.logger.error(\n `An error occurred when trying to translate the data using OpenAI API - missing content in the response`,\n );\n\n return {\n success: false as const,\n };\n }\n\n const translatedChunk: string[] = JSON.parse(content);\n\n if (!Array.isArray(translatedChunk)) {\n req.payload.logger.error({\n data: translatedChunk,\n fullContent: content,\n message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not an array`,\n });\n\n return {\n success: false as const,\n };\n }\n\n for (const text of translatedChunk) {\n if (text && typeof text !== 'string') {\n req.payload.logger.error({\n chunkData: translatedChunk,\n data: text,\n fullContent: content,\n message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not a string`,\n });\n\n return {\n success: false as const,\n };\n }\n\n translated.push(text);\n }\n }\n\n return {\n success: true as const,\n translatedTexts: translated,\n };\n } catch (e) {\n if (e instanceof Error) {\n req.payload.logger.info({\n message: `An error occurred when trying to translate the data using OpenAI API`,\n originalErr: e.message,\n });\n }\n\n return { success: false as const };\n }\n },\n };\n};\n"],"names":["chunkArray","defaultPromt","localeFrom","localeTo","texts","JSON","stringify","openAIResolver","apiKey","baseUrl","chunkLength","model","promt","key","resolve","req","apiUrl","respones","Promise","all","map","fetch","body","messages","content","role","headers","Authorization","method","then","res","data","json","ok","payload","logger","info","message","openAIresponse","success","translated","choices","error","translatedChunk","parse","Array","isArray","fullContent","text","chunkData","push","translatedTexts","e","Error","originalErr"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AAgCjD,MAAMC,eAA6B,CAAC,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,KAAK,EAAE;IACjE,OAAO,CAAC,kCAAkC,EAAEC,KAAKC,SAAS,CAACF,OAAO,WAAW,EAAEF,WAAW,WAAW,EAAEC,SAAS,0CAA0C,CAAC;AAC7J;AAEA,OAAO,MAAMI,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,OAAO,EACPC,cAAc,GAAG,EACjBC,QAAQ,eAAe,EACvBC,QAAQX,YAAY,EACC;IACrB,OAAO;QACLY,KAAK;QACLC,SAAS,OAAO,EAAEZ,UAAU,EAAEC,QAAQ,EAAEY,GAAG,EAAEX,KAAK,EAAE;YAClD,MAAMY,SAAS,CAAC,EAAEP,WAAW,yBAAyB,oBAAoB,CAAC;YAE3E,IAAI;gBACF,MAAMQ,WAGA,MAAMC,QAAQC,GAAG,CACrBnB,WAAWI,OAAOM,aAAaU,GAAG,CAAC,CAAChB;oBAClC,OAAOiB,MAAML,QAAQ;wBACnBM,MAAMjB,KAAKC,SAAS,CAAC;4BACnBiB,UAAU;gCACR;oCACEC,SAASZ,MAAM;wCAAEV;wCAAYC;wCAAUC;oCAAM;oCAC7CqB,MAAM;gCACR;6BACD;4BACDd;wBACF;wBACAe,SAAS;4BACPC,eAAe,CAAC,OAAO,EAAEnB,OAAO,CAAC;4BACjC,gBAAgB;wBAClB;wBACAoB,QAAQ;oBACV,GAAGC,IAAI,CAAC,OAA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IAAIA,aAAaC,OAAO;oBACtBtC,IAAImB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;wBACtBC,SAAS,CAAC,oEAAoE,CAAC;wBAC/EiB,aAAaF,EAAEf,OAAO;oBACxB;gBACF;gBAEA,OAAO;oBAAEE,SAAS;gBAAe;YACnC;QACF;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/resolvers/openAI.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\nimport type { TranslateResolver } from './types';\n\nexport type OpenAIPrompt = (args: {\n localeFrom: string;\n localeTo: string;\n texts: string[];\n}) => string;\n\nexport type OpenAIResolverConfig = {\n apiKey: string;\n baseUrl?: string;\n /**\n * How many texts to include into 1 request\n * @default 100\n */\n chunkLength?: number;\n /**\n * @default \"gpt-3.5-turbo\"\n */\n model?: string;\n promt?: OpenAIPrompt;\n};\n\ntype OpenAIResponse = {\n choices: {\n message: {\n content: string;\n };\n }[];\n};\n\nconst defaultPromt: OpenAIPrompt = ({ localeFrom, localeTo, texts }) => {\n return `Translate me the following array: ${JSON.stringify(texts)} in locale=${localeFrom} to locale ${localeTo}, respond me with the same array structure`;\n};\n\nexport const openAIResolver = ({\n apiKey,\n baseUrl,\n chunkLength = 100,\n model = 'gpt-3.5-turbo',\n promt = defaultPromt,\n}: OpenAIResolverConfig): TranslateResolver => {\n return {\n key: 'openai',\n resolve: async ({ localeFrom, localeTo, req, texts }) => {\n const apiUrl = `${baseUrl || 'https://api.openai.com'}/v1/chat/completions`;\n\n try {\n const respones: {\n data: OpenAIResponse;\n success: boolean;\n }[] = await Promise.all(\n chunkArray(texts, chunkLength).map((texts) => {\n return fetch(apiUrl, {\n body: JSON.stringify({\n messages: [\n {\n content: promt({ localeFrom, localeTo, texts }),\n role: 'user',\n },\n ],\n model,\n }),\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n method: 'post',\n }).then(async (res) => {\n const data = await res.json();\n\n if (!res.ok)\n req.payload.logger.info({\n message: `An error occurred when trying to translate the data using OpenAI API`,\n openAIresponse: data,\n });\n\n return {\n data,\n success: res.ok,\n };\n });\n }),\n );\n\n const translated: string[] = [];\n\n for (const { data, success } of respones) {\n if (!success)\n return {\n success: false as const,\n };\n\n const content = data?.choices?.[0]?.message?.content;\n\n if (!content) {\n req.payload.logger.error(\n `An error occurred when trying to translate the data using OpenAI API - missing content in the response`,\n );\n\n return {\n success: false as const,\n };\n }\n\n const translatedChunk: string[] = JSON.parse(content);\n\n if (!Array.isArray(translatedChunk)) {\n req.payload.logger.error({\n data: translatedChunk,\n fullContent: content,\n message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not an array`,\n });\n\n return {\n success: false as const,\n };\n }\n\n for (const text of translatedChunk) {\n if (text && typeof text !== 'string') {\n req.payload.logger.error({\n chunkData: translatedChunk,\n data: text,\n fullContent: content,\n message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not a string`,\n });\n\n return {\n success: false as const,\n };\n }\n\n translated.push(text);\n }\n }\n\n return {\n success: true as const,\n translatedTexts: translated,\n };\n } catch (e) {\n if (e instanceof Error) {\n req.payload.logger.info({\n message: `An error occurred when trying to translate the data using OpenAI API`,\n originalErr: e.message,\n });\n }\n\n return { success: false as const };\n }\n },\n };\n};\n"],"names":["chunkArray","defaultPromt","localeFrom","localeTo","texts","JSON","stringify","openAIResolver","apiKey","baseUrl","chunkLength","model","promt","key","resolve","req","apiUrl","respones","Promise","all","map","fetch","body","messages","content","role","headers","Authorization","method","then","res","data","json","ok","payload","logger","info","message","openAIresponse","success","translated","choices","error","translatedChunk","parse","Array","isArray","fullContent","text","chunkData","push","translatedTexts","e","Error","originalErr"],"mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AAgCjD,MAAMC,eAA6B,CAAC,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,KAAK,EAAE;IACjE,OAAO,CAAC,kCAAkC,EAAEC,KAAKC,SAAS,CAACF,OAAO,WAAW,EAAEF,WAAW,WAAW,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AAImB,OAAO,CAACC,MAAM,CAACO,KAAK,CACtB,CAAC,sGAAsG,CAAC;wBAG1G,OAAO;4BACLH,SAAS;wBACX;oBACF;oBAEA,MAAMI,kBAA4BtC,KAAKuC,KAAK,CAACpB;oBAE7C,IAAI,CAACqB,MAAMC,OAAO,CAACH,kBAAkB;wBACnC5B,IAAImB,OAAO,CAACC,MAAM,CAACO,KAAK,CAAC;4BACvBX,MAAMY;4BACNI,aAAavB;4BACba,SAAS,CAAC,qGAAqG,CAAC;wBAClH;wBAEA,OAAO;4BACLE,SAAS;wBACX;oBACF;oBAEA,KAAK,MAAMS,QAAQL,gBAAiB;wBAClC,IAAIK,QAAQ,OAAOA,SAAS,UAAU;4BACpCjC,IAAImB,OAAO,CAACC,MAAM,CAACO,KAAK,CAAC;gCACvBO,WAAWN;gCACXZ,MAAMiB;gCACND,aAAavB;gCACba,SAAS,CAAC,qGAAqG,CAAC;4BAClH;4BAEA,OAAO;gCACLE,SAAS;4BACX;wBACF;wBAEAC,WAAWU,IAAI,CAACF;oBAClB;gBACF;gBAEA,OAAO;oBACLT,SAAS;oBACTY,iBAAiBX;gBACnB;YACF,EAAE,OAAOY,GAAG;gBACV,IAAIA,aAAaC,OAAO;oBACtBtC,IAAImB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;wBACtBC,SAAS,CAAC,oEAAoE,CAAC;wBAC/EiB,aAAaF,EAAEf,OAAO;oBACxB;gBACF;gBAEA,OAAO;oBAAEE,SAAS;gBAAe;YACnC;QACF;IACF;AACF,EAAE"}
@@ -1 +1 @@
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
+ {"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":[],"mappings":"AAoBA,WAKE"}
@@ -1 +1 @@
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
+ {"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"],"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 +1 @@
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
+ {"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) as any,\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"],"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,KAAM,MAAMN;IACd;AACF,EAAE"}
@@ -1 +1 @@
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
+ {"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,6BAuFpE,CAAC"}
@@ -18,7 +18,6 @@ export const translateOperation = async (args)=>{
18
18
  if (!resolver) throw new APIError(`Resolver with the key ${args.resolver} was not found`);
19
19
  const valuesToTranslate = [];
20
20
  let translatedData = args.data;
21
- console.log(translatedData);
22
21
  if (!translatedData) {
23
22
  const { doc } = await findEntityWithConfig({
24
23
  collectionSlug,
@@ -1 +1 @@
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,SAASC,cAAc,QAAQ,mBAAmB;AAElD,SAASC,YAAY,QAAQ,iBAAiB;AAY9C,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAMC,MACJ,SAASD,OACLA,KAAKC,GAAG,GACP;QACCC,SAASF,KAAKE,OAAO;IACvB;IAEN,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,cAAc,EAAE,GAAGR;IAE/E,MAAM,EAAES,MAAM,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EA+B,SAAS;YACPC,SAAS;YACTb;QACF;IACF;IAEA,OAAOY;AACT,EAAE"}
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 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","emptyOnly","fields","resolveResult","resolve","localeTo","texts","map","value","result","success","translatedTexts","forEach","translated","index","onTranslate","update","depth"],"mappings":"AAAA,SAASA,QAAQ,QAA2C,UAAU;AAGtE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,cAAc,QAAQ,mBAAmB;AAElD,SAASC,YAAY,QAAQ,iBAAiB;AAY9C,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAMC,MACJ,SAASD,OACLA,KAAKC,GAAG,GACP;QACCC,SAASF,KAAKE,OAAO;IACvB;IAEN,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,cAAc,EAAE,GAAGR;IAE/E,MAAM,EAAES,MAAM,EAAEC,KAAKC,QAAQ,EAAE,GAAG,MAAMf,qBAAqB;QAC3DO;QACAC;QACAC;QACAC,QAAQC;QACRN;IACF;IAEA,MAAMW,WAAW,AACf,CAAA,AAACX,IAAIC,OAAO,CAACO,MAAM,CAACI,MAAM,EAAEC,YAAYC,aAAqC,EAAE,AAAD,EAC9EC,IAAI,CAAC,CAACC,OAASA,KAAKC,GAAG,KAAKlB,KAAKY,QAAQ;IAE3C,IAAI,CAACA,UAAU,MAAM,IAAIjB,SAAS,CAAC,sBAAsB,EAAEK,KAAKY,QAAQ,CAAC,cAAc,CAAC;IAExF,MAAMO,oBAAwC,EAAE;IAEhD,IAAIC,iBAAiBpB,KAAKqB,IAAI;IAE9B,IAAI,CAACD,gBAAgB;QACnB,MAAM,EAAEV,GAAG,EAAE,GAAG,MAAMd,qBAAqB;YACzCO;YACAC;YACAC;YACAC;YACAE;YACAP;QACF;QAEAmB,iBAAiBV;IACnB;IAEAb,eAAe;QACbc;QACAW,WAAWtB,KAAKsB,SAAS;QACzBC,QAAQd,OAAOc,MAAM;QACrBH;QACAD;IACF;IAEA,MAAMK,gBAAgB,MAAMZ,SAASa,OAAO,CAAC;QAC3ClB,YAAYP,KAAKO,UAAU;QAC3BmB,UAAU1B,KAAKM,MAAM;QACrBL;QACA0B,OAAOR,kBAAkBS,GAAG,CAAC,CAACX,OAASA,KAAKY,KAAK;IACnD;IAEA,IAAIC;IAEJ,IAAI,CAACN,cAAcO,OAAO,EAAE;QAC1BD,SAAS;YACPC,SAAS;QACX;IACF,OAAO;QACLP,cAAcQ,eAAe,CAACC,OAAO,CAAC,CAACC,YAAYC;YACjDhB,iBAAiB,CAACgB,MAAM,CAACC,WAAW,CAACF;QACvC;QAEA,IAAIlC,KAAKqC,MAAM,EAAE;YACf,MAAMvC,aAAa;gBACjBK;gBACAkB,MAAMD;gBACNkB,OAAO;gBACPlC;gBACAC;gBACAC;gBACAE;gBACAP;YACF;QACF;QAEA6B,SAAS;YACPC,SAAS;YACTX;QACF;IACF;IAEA,OAAOU;AACT,EAAE"}
@@ -1 +1 @@
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;AAC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BAEpDV,qBAAqB,CAACI,MAAMM,IAAI,CAAC,GAAG2B;gBAEpC,IAAI,CAACA,kBAAkB;gBAEvB,MAAMC,UAAUC,MAAMC,OAAO,CAACH;gBAE9B,MAAMI,YAAY,UAAUJ;gBAE5B,IAAI,CAACC,WAAW,CAACG,WAAW;gBAE5B,IAAIA,WAAW;oBACb,MAAMC,OAAQ1C,qBAAqB,CAACI,MAAMM,IAAI,CAAC,EAC3CgC;oBAEJ,IAAIA,MACFjD,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
+ {"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"],"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,kBA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BAE5B,IAAIA,WAAW;oBACb,MAAMC,OAAQ1C,qBAAqB,CAACI,MAAMM,IAAI,CAAC,EAC3CgC;oBAEJ,IAAIA,MACFjD,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,"sources":["../../src/translate/traverseRichText.ts"],"sourcesContent":["export const traverseRichText = ({\n onText,\n root,\n siblingData,\n}: {\n onText: (siblingData: Record<string, unknown>) => void;\n root: Record<string, unknown>;\n siblingData?: Record<string, unknown>;\n}) => {\n siblingData = siblingData ?? root;\n\n if (siblingData.text) {\n onText(siblingData);\n }\n\n if (Array.isArray(siblingData?.children)) {\n siblingData.children.forEach((siblingData) => {\n traverseRichText({\n onText,\n root,\n siblingData,\n });\n });\n }\n};\n"],"names":["traverseRichText","onText","root","siblingData","text","Array","isArray","children","forEach"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,mBAAmB,CAAC,EAC/BC,MAAM,EACNC,IAAI,EACJC,WAAW,EAKZ;IACCA,cAAcA,eAAeD;IAE7B,IAAIC,YAAYC,IAAI,EAAE;QACpBH,OAAOE;IACT;IAEA,IAAIE,MAAMC,OAAO,CAACH,aAAaI,WAAW;QACxCJ,YAAYI,QAAQ,CAACC,OAAO,CAAC,CAACL;YAC5BH,iBAAiB;gBACfC;gBACAC;gBACAC;YACF;QACF;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/translate/traverseRichText.ts"],"sourcesContent":["export const traverseRichText = ({\n onText,\n root,\n siblingData,\n}: {\n onText: (siblingData: Record<string, unknown>) => void;\n root: Record<string, unknown>;\n siblingData?: Record<string, unknown>;\n}) => {\n siblingData = siblingData ?? root;\n\n if (siblingData.text) {\n onText(siblingData);\n }\n\n if (Array.isArray(siblingData?.children)) {\n siblingData.children.forEach((siblingData) => {\n traverseRichText({\n onText,\n root,\n siblingData,\n });\n });\n }\n};\n"],"names":["traverseRichText","onText","root","siblingData","text","Array","isArray","children","forEach"],"mappings":"AAAA,OAAO,MAAMA,mBAAmB,CAAC,EAC/BC,MAAM,EACNC,IAAI,EACJC,WAAW,EAKZ;IACCA,cAAcA,eAAeD;IAE7B,IAAIC,YAAYC,IAAI,EAAE;QACpBH,OAAOE;IACT;IAEA,IAAIE,MAAMC,OAAO,CAACH,aAAaI,WAAW;QACxCJ,YAAYI,QAAQ,CAACC,OAAO,CAAC,CAACL;YAC5BH,iBAAiB;gBACfC;gBACAC;gBACAC;YACF;QACF;IACF;AACF,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/types.ts"],"sourcesContent":["export type ValueToTranslate = {\n onTranslate: (translatedValue: any) => void;\n value: any;\n};\n\nexport type TranslateArgs = {\n collectionSlug?: string;\n data?: Record<string, any>;\n emptyOnly?: boolean;\n globalSlug?: string;\n id?: number | string;\n /** active locale */\n locale: string;\n localeFrom: string;\n overrideAccess?: boolean;\n resolver: string;\n update?: boolean;\n};\n\nexport type TranslateResult =\n | {\n success: false;\n }\n | {\n success: true;\n translatedData: Record<string, any>;\n };\n\nexport type TranslateEndpointArgs = Omit<TranslateArgs, 'update'>;\n"],"names":[],"rangeMappings":"","mappings":"AA4BA,WAAkE"}
1
+ {"version":3,"sources":["../../src/translate/types.ts"],"sourcesContent":["export type ValueToTranslate = {\n onTranslate: (translatedValue: any) => void;\n value: any;\n};\n\nexport type TranslateArgs = {\n collectionSlug?: string;\n data?: Record<string, any>;\n emptyOnly?: boolean;\n globalSlug?: string;\n id?: number | string;\n /** active locale */\n locale: string;\n localeFrom: string;\n overrideAccess?: boolean;\n resolver: string;\n update?: boolean;\n};\n\nexport type TranslateResult =\n | {\n success: false;\n }\n | {\n success: true;\n translatedData: Record<string, any>;\n };\n\nexport type TranslateEndpointArgs = Omit<TranslateArgs, 'update'>;\n"],"names":[],"mappings":"AA4BA,WAAkE"}
@@ -1 +1 @@
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"}
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 as any;\n};\n"],"names":["APIError","updateEntity","collectionSlug","data","depth","incomingDepth","globalSlug","id","locale","overrideAccess","req","isGlobal","payload","config","defaultDepth","promise","updateGlobal","slug","update","collection"],"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/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { GeneratedTypes } from 'payload';
1
+ import type { CollectionSlug, GlobalSlug } from 'payload';
2
2
  import type { TranslateResolver } from './resolvers/types';
3
3
  export type TranslatorConfig = {
4
4
  /**
5
5
  * Collections with the enabled translator in the admin UI
6
6
  */
7
- collections: (keyof GeneratedTypes['collections'])[];
7
+ collections: CollectionSlug[];
8
8
  /**
9
9
  * Disable the plugin
10
10
  */
@@ -12,7 +12,7 @@ export type TranslatorConfig = {
12
12
  /**
13
13
  * Globals with the enabled translator in the admin UI
14
14
  */
15
- globals: (keyof GeneratedTypes['globals'])[];
15
+ globals: GlobalSlug[];
16
16
  /**
17
17
  * Add resolvers that you want to include, examples on how to write your own in ./plugin/src/resolvers
18
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,WAAW,EAAE,CAAC,MAAM,cAAc,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;IACrD;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,OAAO,EAAE,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;IAC7C;;OAEG;IACH,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB;;OAEG;IACH,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC,CAAC"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { GeneratedTypes } from 'payload';\n\nimport type { TranslateResolver } from './resolvers/types';\n\nexport type TranslatorConfig = {\n /**\n * Collections with the enabled translator in the admin UI\n */\n collections: (keyof GeneratedTypes['collections'])[];\n /**\n * Disable the plugin\n */\n disabled?: boolean;\n /**\n * Globals with the enabled translator in the admin UI\n */\n globals: (keyof GeneratedTypes['globals'])[];\n /**\n * Add resolvers that you want to include, examples on how to write your own in ./plugin/src/resolvers\n */\n resolvers: TranslateResolver[];\n};\n"],"names":[],"rangeMappings":"","mappings":"AAIA,WAiBE"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionSlug, GlobalSlug } from 'payload';\n\nimport type { TranslateResolver } from './resolvers/types';\n\nexport type TranslatorConfig = {\n /**\n * Collections with the enabled translator in the admin UI\n */\n collections: CollectionSlug[];\n /**\n * Disable the plugin\n */\n disabled?: boolean;\n /**\n * Globals with the enabled translator in the admin UI\n */\n globals: GlobalSlug[];\n /**\n * Add resolvers that you want to include, examples on how to write your own in ./plugin/src/resolvers\n */\n resolvers: TranslateResolver[];\n};\n"],"names":[],"mappings":"AAIA,WAiBE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/chunkArray.ts"],"sourcesContent":["export const chunkArray = <T>(array: T[], length: number): T[][] => {\n return Array.from({ length: Math.ceil(array.length / length) }, (_, i) =>\n array.slice(i * length, i * length + length),\n );\n};\n"],"names":["chunkArray","array","length","Array","from","Math","ceil","_","i","slice"],"rangeMappings":";;;;","mappings":"AAAA,OAAO,MAAMA,aAAa,CAAIC,OAAYC;IACxC,OAAOC,MAAMC,IAAI,CAAC;QAAEF,QAAQG,KAAKC,IAAI,CAACL,MAAMC,MAAM,GAAGA;IAAQ,GAAG,CAACK,GAAGC,IAClEP,MAAMQ,KAAK,CAACD,IAAIN,QAAQM,IAAIN,SAASA;AAEzC,EAAE"}
1
+ {"version":3,"sources":["../../src/utils/chunkArray.ts"],"sourcesContent":["export const chunkArray = <T>(array: T[], length: number): T[][] => {\n return Array.from({ length: Math.ceil(array.length / length) }, (_, i) =>\n array.slice(i * length, i * length + length),\n );\n};\n"],"names":["chunkArray","array","length","Array","from","Math","ceil","_","i","slice"],"mappings":"AAAA,OAAO,MAAMA,aAAa,CAAIC,OAAYC;IACxC,OAAOC,MAAMC,IAAI,CAAC;QAAEF,QAAQG,KAAKC,IAAI,CAACL,MAAMC,MAAM,GAAGA;IAAQ,GAAG,CAACK,GAAGC,IAClEP,MAAMQ,KAAK,CAACD,IAAIN,QAAQM,IAAIN,SAASA;AAEzC,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/isEmpty.ts"],"sourcesContent":["export const isEmpty = (value: unknown) => {\n if (Array.isArray(value)) return value.length === 0;\n if (value === null || typeof value === 'undefined') return true;\n if (typeof value === 'object' && Object.keys(value).length === 0) return true;\n\n return false;\n};\n"],"names":["isEmpty","value","Array","isArray","length","Object","keys"],"rangeMappings":";;;;;","mappings":"AAAA,OAAO,MAAMA,UAAU,CAACC;IACtB,IAAIC,MAAMC,OAAO,CAACF,QAAQ,OAAOA,MAAMG,MAAM,KAAK;IAClD,IAAIH,UAAU,QAAQ,OAAOA,UAAU,aAAa,OAAO;IAC3D,IAAI,OAAOA,UAAU,YAAYI,OAAOC,IAAI,CAACL,OAAOG,MAAM,KAAK,GAAG,OAAO;IAEzE,OAAO;AACT,EAAE"}
1
+ {"version":3,"sources":["../../src/utils/isEmpty.ts"],"sourcesContent":["export const isEmpty = (value: unknown) => {\n if (Array.isArray(value)) return value.length === 0;\n if (value === null || typeof value === 'undefined') return true;\n if (typeof value === 'object' && Object.keys(value).length === 0) return true;\n\n return false;\n};\n"],"names":["isEmpty","value","Array","isArray","length","Object","keys"],"mappings":"AAAA,OAAO,MAAMA,UAAU,CAACC;IACtB,IAAIC,MAAMC,OAAO,CAACF,QAAQ,OAAOA,MAAMG,MAAM,KAAK;IAClD,IAAIH,UAAU,QAAQ,OAAOA,UAAU,aAAa,OAAO;IAC3D,IAAI,OAAOA,UAAU,YAAYI,OAAOC,IAAI,CAACL,OAAOG,MAAM,KAAK,GAAG,OAAO;IAEzE,OAAO;AACT,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payload-enchants/translator",
3
- "version": "1.2.0-pre.0",
3
+ "version": "1.2.1",
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.53",
50
- "@payloadcms/ui": "3.0.0-beta.53",
49
+ "@payloadcms/translations": "3.0.0-beta.61",
50
+ "@payloadcms/ui": "3.0.0-beta.61",
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",
54
- "typescript": "^5.4.5",
53
+ "payload": "3.0.0-beta.61",
55
54
  "react": "19.0.0-rc-f994737d14-20240522",
56
- "react-dom": "19.0.0-rc-f994737d14-20240522"
55
+ "react-dom": "19.0.0-rc-f994737d14-20240522",
56
+ "typescript": "^5.5.2"
57
57
  },
58
58
  "peerDependencies": {
59
- "@payloadcms/translations": "^3.0.0-beta.53",
60
- "@payloadcms/ui": "^3.0.0-beta.53",
61
- "payload": "^3.0.0-beta.53"
59
+ "@payloadcms/translations": "^3.0.0-beta.61",
60
+ "@payloadcms/ui": "^3.0.0-beta.61",
61
+ "payload": "^3.0.0-beta.61"
62
62
  },
63
63
  "publishConfig": {
64
64
  "registry": "https://registry.npmjs.org/"