@payload-enchants/translator 1.1.41 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. package/dist/client/api/index.js.map +1 -1
  2. package/dist/client/components/CustomButton/CustomButtonWithTranslator.d.ts.map +1 -1
  3. package/dist/client/components/CustomButton/CustomButtonWithTranslator.js +1 -2
  4. package/dist/client/components/CustomButton/CustomButtonWithTranslator.js.map +1 -1
  5. package/dist/client/components/CustomButton/index.d.ts.map +1 -1
  6. package/dist/client/components/CustomButton/index.js +1 -2
  7. package/dist/client/components/CustomButton/index.js.map +1 -1
  8. package/dist/client/components/LocaleLabel/LocaleLabel.d.ts +1 -1
  9. package/dist/client/components/LocaleLabel/LocaleLabel.d.ts.map +1 -1
  10. package/dist/client/components/LocaleLabel/LocaleLabel.js +2 -3
  11. package/dist/client/components/LocaleLabel/LocaleLabel.js.map +1 -1
  12. package/dist/client/components/LocaleLabel/index.js.map +1 -1
  13. package/dist/client/components/ResolverButton/ResolverButton.d.ts.map +1 -1
  14. package/dist/client/components/ResolverButton/ResolverButton.js +1 -2
  15. package/dist/client/components/ResolverButton/ResolverButton.js.map +1 -1
  16. package/dist/client/components/ResolverButton/index.js.map +1 -1
  17. package/dist/client/components/TranslatorModal/Content.d.ts.map +1 -1
  18. package/dist/client/components/TranslatorModal/Content.js +1 -2
  19. package/dist/client/components/TranslatorModal/Content.js.map +1 -1
  20. package/dist/client/components/TranslatorModal/TranslatorModal.js +1 -1
  21. package/dist/client/components/TranslatorModal/TranslatorModal.js.map +1 -1
  22. package/dist/client/components/TranslatorModal/index.js.map +1 -1
  23. package/dist/client/providers/Translator/TranslatorProvider.d.ts.map +1 -1
  24. package/dist/client/providers/Translator/TranslatorProvider.js +2 -9
  25. package/dist/client/providers/Translator/TranslatorProvider.js.map +1 -1
  26. package/dist/client/providers/Translator/context.d.ts +1 -1
  27. package/dist/client/providers/Translator/context.d.ts.map +1 -1
  28. package/dist/client/providers/Translator/context.js.map +1 -1
  29. package/dist/i18n-translations.js.map +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/resolvers/copy.js.map +1 -1
  35. package/dist/resolvers/google.js.map +1 -1
  36. package/dist/resolvers/openAI.js.map +1 -1
  37. package/dist/resolvers/types.d.ts +1 -1
  38. package/dist/resolvers/types.d.ts.map +1 -1
  39. package/dist/resolvers/types.js.map +1 -1
  40. package/dist/translate/endpoint.d.ts +1 -1
  41. package/dist/translate/endpoint.d.ts.map +1 -1
  42. package/dist/translate/endpoint.js +1 -1
  43. package/dist/translate/endpoint.js.map +1 -1
  44. package/dist/translate/findEntityWithConfig.d.ts +1 -1
  45. package/dist/translate/findEntityWithConfig.d.ts.map +1 -1
  46. package/dist/translate/findEntityWithConfig.js +1 -1
  47. package/dist/translate/findEntityWithConfig.js.map +1 -1
  48. package/dist/translate/operation.d.ts +1 -1
  49. package/dist/translate/operation.d.ts.map +1 -1
  50. package/dist/translate/operation.js +1 -1
  51. package/dist/translate/operation.js.map +1 -1
  52. package/dist/translate/traverseFields.d.ts +1 -1
  53. package/dist/translate/traverseFields.d.ts.map +1 -1
  54. package/dist/translate/traverseFields.js +1 -1
  55. package/dist/translate/traverseFields.js.map +1 -1
  56. package/dist/translate/traverseRichText.js.map +1 -1
  57. package/dist/translate/types.js.map +1 -1
  58. package/dist/translate/updateEntity.d.ts +1 -1
  59. package/dist/translate/updateEntity.d.ts.map +1 -1
  60. package/dist/translate/updateEntity.js +1 -1
  61. package/dist/translate/updateEntity.js.map +1 -1
  62. package/dist/types.d.ts +3 -3
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/types.js.map +1 -1
  65. package/dist/utils/chunkArray.js.map +1 -1
  66. package/dist/utils/isEmpty.js.map +1 -1
  67. 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,"file":"CustomButtonWithTranslator.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC,eAAO,MAAM,0BAA0B,sBAAuB;IAAE,aAAa,EAAE,SAAS,CAAA;CAAE,gUAoBzF,CAAC"}
1
+ {"version":3,"file":"CustomButtonWithTranslator.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC,eAAO,MAAM,0BAA0B,sBAAuB;IAAE,aAAa,EAAE,SAAS,CAAA;CAAE,gUAoBzF,CAAC"}
@@ -1,8 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import './styles.scss';
4
- import { useConfig } from '@payloadcms/ui/providers/Config';
5
- import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
4
+ import { useConfig, useDocumentInfo } from '@payloadcms/ui';
6
5
  import { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';
7
6
  import { ResolverButton } from '../ResolverButton';
8
7
  import { TranslatorModal } from '../TranslatorModal';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"sourcesContent":["'use client';\n\nimport './styles.scss';\n\nimport { useConfig } from '@payloadcms/ui/providers/Config';\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';\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,QAAQ,kCAAkC;AAC5D,SAASC,eAAe,QAAQ,wCAAwC;AAIxE,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/elements/PublishButton';
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/elements/PublishButton';\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,wCAAwC;AAC7E,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,4 +1,4 @@
1
- import type { Locale } from 'payload/config';
1
+ import type { Locale } from 'payload';
2
2
  export declare const LocaleLabel: ({ locale }: {
3
3
  locale: Locale;
4
4
  }) => import("react").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"LocaleLabel.d.ts","sourceRoot":"","sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAI7C,eAAO,MAAM,WAAW,eAAgB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,gCAczD,CAAC"}
1
+ {"version":3,"file":"LocaleLabel.d.ts","sourceRoot":"","sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,eAAO,MAAM,WAAW,eAAgB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,gCAczD,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { getTranslation } from '@payloadcms/translations';
3
- import { Chevron } from '@payloadcms/ui/icons/Chevron';
4
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
3
+ import { ChevronIcon, useTranslation } from '@payloadcms/ui';
5
4
  const baseClass = 'localizer-button';
6
5
  export const LocaleLabel = ({ locale })=>{
7
6
  const { i18n, t } = useTranslation();
@@ -19,7 +18,7 @@ export const LocaleLabel = ({ locale })=>{
19
18
  children: `${getTranslation(locale.label, i18n)}`
20
19
  }),
21
20
  " ",
22
- /*#__PURE__*/ _jsx(Chevron, {
21
+ /*#__PURE__*/ _jsx(ChevronIcon, {
23
22
  className: `${baseClass}__chevron`
24
23
  })
25
24
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport { Chevron } from '@payloadcms/ui/icons/Chevron';\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\nimport type { Locale } from 'payload/config';\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 <Chevron className={`${baseClass}__chevron`} />\n </div>\n );\n};\n"],"names":["getTranslation","Chevron","useTranslation","baseClass","LocaleLabel","locale","i18n","t","div","aria-label","className","span","label"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,OAAO,QAAQ,+BAA+B;AACvD,SAASC,cAAc,QAAQ,uCAAuC;AAGtE,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;gBAAQS,WAAW,CAAC,EAAEP,UAAU,SAAS,CAAC;;;;AAGjD,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,"file":"ResolverButton.d.ts","sourceRoot":"","sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,eAAO,MAAM,cAAc,wCAExB;IACD,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,gCAYA,CAAC"}
1
+ {"version":3,"file":"ResolverButton.d.ts","sourceRoot":"","sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,eAAO,MAAM,cAAc,wCAExB;IACD,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,gCAYA,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Button } from '@payloadcms/ui/elements';
3
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
2
+ import { Button, useTranslation } from '@payloadcms/ui';
4
3
  import { useTranslator } from '../../providers/Translator/context';
5
4
  export const ResolverButton = ({ resolver: { key: resolverKey } })=>{
6
5
  const { openTranslator } = useTranslator();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"sourcesContent":["import { Button } from '@payloadcms/ui/elements';\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\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,QAAQ,0BAA0B;AACjD,SAASC,cAAc,QAAQ,uCAAuC;AAGtE,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,"file":"Content.d.ts","sourceRoot":"","sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,mCAwDnB,CAAC"}
1
+ {"version":3,"file":"Content.d.ts","sourceRoot":"","sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,mCAwDnB,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { getTranslation } from '@payloadcms/translations';
3
- import { Button, Popup, PopupList } from '@payloadcms/ui/elements';
4
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
3
+ import { Button, Popup, PopupList, useTranslation } from '@payloadcms/ui';
5
4
  import { useTranslator } from '../../providers/Translator/context';
6
5
  import { LocaleLabel } from '../LocaleLabel';
7
6
  export const Content = ()=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport { Button, Popup, PopupList } from '@payloadcms/ui/elements';\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\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,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cesContent":["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,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import './styles.scss';
3
- import { Modal } from '@payloadcms/ui/elements';
3
+ import { Modal } from '@payloadcms/ui';
4
4
  import { useTranslator } from '../../providers/Translator/context';
5
5
  import { Content } from './Content';
6
6
  export const TranslatorModal = ()=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"sourcesContent":["import './styles.scss';\n\nimport { Modal } from '@payloadcms/ui/elements';\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,0BAA0B;AAEhD,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":"AASA,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":"AAWA,OAAO,EAAE,KAAK,SAAS,EAAgC,MAAM,OAAO,CAAC;AASrE,eAAO,MAAM,kBAAkB,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,gCAoIvE,CAAC"}
@@ -1,13 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { toast } from '@payloadcms/ui/elements';
3
- import { useModal } from '@payloadcms/ui/elements/Modal';
4
- import { useAllFormFields, useForm } from '@payloadcms/ui/forms/Form';
5
- import { useConfig } from '@payloadcms/ui/providers/Config';
6
- import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
7
- import { useLocale } from '@payloadcms/ui/providers/Locale';
8
- import { useTranslation } from '@payloadcms/ui/providers/Translation';
9
- import { getFormState } from '@payloadcms/ui/utilities/getFormState';
10
- import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
2
+ import { toast, useAllFormFields, useConfig, useDocumentInfo, useForm, useLocale, useModal, useTranslation } from '@payloadcms/ui';
3
+ import { getFormState, reduceFieldsToValues } from '@payloadcms/ui/shared';
11
4
  import { useEffect, useMemo, useState } from 'react';
12
5
  import { createClient } from '../../api';
13
6
  import { TranslatorContext } from './context';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import { toast } from '@payloadcms/ui/elements';\nimport { useModal } from '@payloadcms/ui/elements/Modal';\nimport { useAllFormFields, useForm } from '@payloadcms/ui/forms/Form';\nimport { useConfig } from '@payloadcms/ui/providers/Config';\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';\nimport { useLocale } from '@payloadcms/ui/providers/Locale';\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState';\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';\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","useModal","useAllFormFields","useForm","useConfig","useDocumentInfo","useLocale","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,SAASA,KAAK,QAAQ,0BAA0B;AAChD,SAASC,QAAQ,QAAQ,gCAAgC;AACzD,SAASC,gBAAgB,EAAEC,OAAO,QAAQ,4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,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, 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"],"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,WAAW,EAAE,GAAGrB;IAExB,MAAMsB,QAAQpB;IAEd,MAAM,EAAEqB,CAAC,EAAE,GAAGpB;IAEd,MAAMqB,YAAY,CAChBC;QAQA,IAAI,CAACX,UAAU,OAAO;QAEtB,OAAOS,EAAE,CAAC,2BAA2B,EAAET,SAAS,CAAC,EAAEW,IAAI,CAAC;IAC1D;IAEA,MAAMC,SAASzB;IAEf,MAAM,EACJ0B,OAAO,EAAEC,MAAM,EAAE,EACjBC,YAAY,EACZC,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,GAAGlC;IAEJ,MAAMmC,YAAYxB,aAAa;QAAEsB;QAAKC;IAAU;IAEhD,MAAME,iBAAiB3B,QAAQ;QAC7B,IA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AAOkB,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,4 +1,4 @@
1
- import type { Locale } from 'payload/config';
1
+ import type { Locale } from 'payload';
2
2
  import type { TranslateResolver } from '../../../resolvers/types';
3
3
  type TranslatorContextData = {
4
4
  closeTranslator: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,KAAK,qBAAqB,GAAG;IAC3B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,CACT,GAAG,EACC,aAAa,GACb,cAAc,GACd,YAAY,GACZ,wBAAwB,GACxB,uBAAuB,GACvB,gBAAgB,KACjB,MAAM,CAAC;IACZ,wBAAwB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAEF,eAAO,MAAM,iBAAiB,uDAAoD,CAAC;AAEnF,eAAO,MAAM,aAAa,6BAMzB,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,KAAK,qBAAqB,GAAG;IAC3B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,CACT,GAAG,EACC,aAAa,GACb,cAAc,GACd,YAAY,GACZ,wBAAwB,GACxB,uBAAuB,GACvB,gBAAgB,KACjB,MAAM,CAAC;IACZ,wBAAwB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAEF,eAAO,MAAM,iBAAiB,uDAAoD,CAAC;AAEnF,eAAO,MAAM,aAAa,6BAMzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/providers/Translator/context.ts"],"sourcesContent":["import type { Locale } from 'payload/config';\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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'payload/config';
1
+ import type { Plugin } from 'payload';
2
2
  import { translateOperation } from './translate/operation';
3
3
  import type { TranslatorConfig } from './types';
4
4
  export { translateOperation };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAM7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,UAAU,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,MA4E5D,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAMtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,UAAU,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,MA4E5D,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable perfectionist/sort-named-exports */ import { deepMerge } from 'payload/utilities';
1
+ /* eslint-disable perfectionist/sort-named-exports */ import { deepMerge } from 'payload/shared';
2
2
  import { CustomButton } from './client/components/CustomButton';
3
3
  import { translations } from './i18n-translations';
4
4
  import { translateEndpoint } from './translate/endpoint';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-named-exports */\nimport type { Plugin } from 'payload/config';\nimport { deepMerge } from 'payload/utilities';\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,oBAAoB;AAE9C,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,mDAAmD,GAEnD,SAASA,SAAS,QAAQ,iBAAiB;AAE3C,SAASC,YAAY,QAAQ,mCAAmC;AAChE,SAASC,YAAY,QAAQ,sBAAsB;A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ACDC,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,OAAOC;wBACb,MAAMC,OAAO,MAAMD,IAAIE,IAAI;wBAE3B,IAAI,CAACF,IAAIG,EAAE,EACTlB,IAAImB,OAAO,CAACC,MAA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;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,EAAEC,SAAS,0CAA0C,CAAC;AAC7J;AAEA,OAAO,MAAMI,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,OAAO,EACPC,cAAc,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A,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,4 +1,4 @@
1
- import type { PayloadRequest } from 'payload/types';
1
+ import type { PayloadRequest } from 'payload';
2
2
  export type TranslateResolverArgs = {
3
3
  /** Locale to translate from */
4
4
  localeFrom: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolvers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,MAAM,qBAAqB,GAAG;IAClC,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC;IACE,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,OAAO,EAAE,IAAI,CAAC;IACd,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,CACP,IAAI,EAAE,qBAAqB,KACxB,OAAO,CAAC,yBAAyB,CAAC,GAAG,yBAAyB,CAAC;CACrE,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolvers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,qBAAqB,GAAG;IAClC,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC;IACE,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,OAAO,EAAE,IAAI,CAAC;IACd,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,CACP,IAAI,EAAE,qBAAqB,KACxB,OAAO,CAAC,yBAAyB,CAAC,GAAG,yBAAyB,CAAC;CACrE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resolvers/types.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload/types';\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,3 +1,3 @@
1
- import type { PayloadHandler } from 'payload/config';
1
+ import type { PayloadHandler } from 'payload';
2
2
  export declare const translateEndpoint: PayloadHandler;
3
3
  //# sourceMappingURL=endpoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/translate/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAMrD,eAAO,MAAM,iBAAiB,EAAE,cAsB/B,CAAC"}
1
+ {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/translate/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM9C,eAAO,MAAM,iBAAiB,EAAE,cAsB/B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { APIError } from 'payload/errors';
1
+ import { APIError } from 'payload';
2
2
  import { translateOperation } from './operation';
3
3
  export const translateEndpoint = async (req)=>{
4
4
  if (!req.json) throw new APIError('Content-Type should be json');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/endpoint.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload/config';\nimport { APIError } from 'payload/errors';\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,iBAAiB;AAE1C,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,4 +1,4 @@
1
- import type { PayloadRequest, SanitizedCollectionConfig, SanitizedGlobalConfig, TypeWithID } from 'payload/types';
1
+ import type { PayloadRequest, SanitizedCollectionConfig, SanitizedGlobalConfig, TypeWithID } from 'payload';
2
2
  type Args = {
3
3
  collectionSlug?: string;
4
4
  globalSlug?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"findEntityWithConfig.d.ts","sourceRoot":"","sources":["../../src/translate/findEntityWithConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAOF,eAAO,MAAM,oBAAoB,SACzB,IAAI,KACT,OAAO,CAAC;IACT,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAC;IAC1D,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC;CAC3C,CA0CA,CAAC"}
1
+ {"version":3,"file":"findEntityWithConfig.d.ts","sourceRoot":"","sources":["../../src/translate/findEntityWithConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,UAAU,EACX,MAAM,SAAS,CAAC;AAGjB,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAOF,eAAO,MAAM,oBAAoB,SACzB,IAAI,KACT,OAAO,CAAC;IACT,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAC;IAC1D,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC;CAC3C,CA0CA,CAAC"}
@@ -1,4 +1,4 @@
1
- import { APIError } from 'payload/errors';
1
+ import { APIError } from 'payload';
2
2
  const findConfigBySlug = (slug, enities)=>enities.find((entity)=>entity.slug === slug);
3
3
  export const findEntityWithConfig = async (args)=>{
4
4
  const { collectionSlug, globalSlug, id, locale, overrideAccess, req } = args;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/findEntityWithConfig.ts"],"sourcesContent":["import { APIError } from 'payload/errors';\nimport type {\n PayloadRequest,\n SanitizedCollectionConfig,\n SanitizedGlobalConfig,\n TypeWithID,\n} from 'payload/types';\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":"AAAA,SAASA,QAAQ,QAAQ,iBAAiB;AAiB1C,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,4 +1,4 @@
1
- import type { Payload, PayloadRequest } from 'payload/types';
1
+ import { type Payload, type PayloadRequest } from 'payload';
2
2
  import type { TranslateArgs, TranslateResult } from './types';
3
3
  export type TranslateOperationArgs = ({
4
4
  payload: Payload;
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/translate/operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK7D,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,6BAyFpE,CAAC"}
@@ -1,4 +1,4 @@
1
- import { APIError } from 'payload/errors';
1
+ import { APIError } from 'payload';
2
2
  import { findEntityWithConfig } from './findEntityWithConfig';
3
3
  import { traverseFields } from './traverseFields';
4
4
  import { updateEntity } from './updateEntity';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/operation.ts"],"sourcesContent":["import { APIError } from 'payload/errors';\nimport type { Payload, PayloadRequest } from 'payload/types';\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,QAAQ,iBAAiB;AAI1C,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,MA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C,MAAM,EAAE;YACf,MAAMzC,aAAa;gBACjBK;gBACAkB,MAAMD;gBACNoB,OAAO;gBACPpC;gBACAC;gBACAC;gBACAE;gBACAP;YACF;QACF;QAEA+B,SAAS;YACPC,SAAS;YACTb;QACF;IACF;IAEA,OAAOY;AACT,EAAE"}
1
+ {"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"],"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;IAE9BC,QAAQC,GAAG,CAACH;IAEZ,IAAI,CAACA,gBAAgB;QACnB,MAAM,EAAEV,GAAG,EAAE,GAAG,MAAMd,qBAAqB;YACzCO;YACAC;YACAC;YACAC;YACAE;YACAP;QACF;QAEAmB,iBAAiBV;IACnB;IAEAb,eAAe;QACbc;QACAa,WAAWxB,KAAKwB,SAAS;QACzBC,QAAQhB,OAAOgB,MAAM;QACrBL;QACAD;IACF;IAEA,MAAMO,gBAAgB,MAAMd,SAASe,OAAO,CAAC;QAC3CpB,YAAYP,KAAKO,UAAU;QAC3BqB,UAAU5B,KAAKM,MAAM;QACrBL;QACA4B,OAAOV,kBAAkBW,GAAG,CAAC,CAACb,OAASA,KAAKc,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;YACjDlB,iBAAiB,CAACkB,MAAM,CAACC,WAAW,CAACF;QACvC;QAEA,IAAIpC,KAAKuC,MAAM,EAAE;YACf,MAAMzC,aAAa;gBACjBK;gBACAkB,MAAMD;gBACNoB,OAAO;gBACPpC;gBACAC;gBACAC;gBACAE;gBACAP;YACF;QACF;QAEA+B,SAAS;YACPC,SAAS;YACTb;QACF;IACF;IAEA,OAAOY;AACT,EAAE"}
@@ -1,4 +1,4 @@
1
- import { type Field } from 'payload/types';
1
+ import type { Field } from 'payload';
2
2
  import type { ValueToTranslate } from './types';
3
3
  export declare const traverseFields: ({ dataFrom, emptyOnly, fields, localizedParent, siblingDataFrom, siblingDataTranslated, translatedData, valuesToTranslate, }: {
4
4
  dataFrom: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/translate/traverseFields.ts"],"names":[],"mappings":"AACA,OAA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
1
1
  import ObjectID from 'bson-objectid';
2
- import { tabHasName } from 'payload/types';
2
+ import { tabHasName } from 'payload/shared';
3
3
  import { isEmpty } from '../utils/isEmpty';
4
4
  import { traverseRichText } from './traverseRichText';
5
5
  export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, siblingDataFrom, siblingDataTranslated, translatedData, valuesToTranslate })=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/traverseFields.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\nimport { type Field, tabHasName } from 'payload/types';\n\nimport { isEmpty } from '../utils/isEmpty';\nimport { traverseRichText } from './traverseRichText';\nimport type { ValueToTranslate } from './types';\n\nexport const traverseFields = ({\n dataFrom,\n emptyOnly,\n fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n}: {\n dataFrom: Record<string, unknown>;\n emptyOnly?: boolean;\n fields: Field[];\n localizedParent?: boolean;\n siblingDataFrom?: Record<string, unknown>;\n siblingDataTranslated?: Record<string, unknown>;\n translatedData: Record<string, unknown>;\n valuesToTranslate: ValueToTranslate[];\n}) => {\n siblingDataFrom = siblingDataFrom ?? dataFrom;\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\n\n fields.forEach((field) => {\n switch (field.type) {\n case 'tabs':\n field.tabs.forEach((tab) => {\n const hasName = tabHasName(tab);\n\n const tabDataFrom = hasName\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\n : siblingDataFrom;\n\n if (!tabDataFrom) return;\n\n const tabDataTranslated = hasName\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\n : siblingDataTranslated;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: tab.fields,\n localizedParent: tab.localized,\n siblingDataFrom: tabDataFrom,\n siblingDataTranslated: tabDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n });\n\n break;\n\n case 'group':\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\n\n if (!groupDataFrom) break;\n\n const groupDataTranslated =\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: field.localized,\n siblingDataFrom: groupDataFrom,\n siblingDataTranslated: groupDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n\n break;\n\n case 'array':\n const arrayDataFrom = siblingDataFrom[field.name] as {\n id: string;\n }[];\n\n if (isEmpty(arrayDataFrom)) break;\n\n let arrayDataTranslated =\n (siblingDataTranslated[field.name] as { id: string }[] | undefined) ?? [];\n\n if (field.localized || localizedParent) {\n if (arrayDataTranslated.length > 0 && emptyOnly) break;\n\n arrayDataTranslated = arrayDataFrom.map(() => ({\n id: ObjectID().toHexString(),\n }));\n }\n\n arrayDataTranslated.forEach((item, index) => {\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: arrayDataFrom[index],\n siblingDataTranslated: item,\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = arrayDataTranslated;\n\n break;\n\n case 'blocks':\n const blocksDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\n\n if (isEmpty(blocksDataFrom)) break;\n\n let blocksDataTranslated =\n (siblingDataTranslated[field.name] as { blockType: string; id: string }[] | undefined) ??\n [];\n\n if (field.localized || localizedParent) {\n if (blocksDataTranslated.length > 0 && emptyOnly) break;\n\n blocksDataTranslated = blocksDataFrom.map(({ blockType }) => ({\n blockType,\n id: ObjectID().toHexString(),\n }));\n }\n\n blocksDataTranslated.forEach((item, index) => {\n const block = field.blocks.find((each) => each.slug === item.blockType);\n\n if (!block) return;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: block.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: blocksDataFrom[index],\n siblingDataTranslated: item,\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = blocksDataTranslated;\n\n break;\n\n case 'collapsible':\n case 'row':\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n break;\n\n // long ass cases here we have\n case 'date':\n case 'checkbox':\n case 'json':\n case 'code':\n case 'email':\n case 'number':\n case 'point':\n case 'radio':\n case 'relationship':\n case 'select':\n case 'upload':\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\n\n break;\n\n case 'text':\n case 'textarea':\n if (field.custom && typeof field.custom === 'object' && field.custom.translatorSkip) break;\n\n if (!(field.localized || localizedParent) || isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) break;\n\n // do not translate the block ID or admin-facing label\n if (field.name === 'blockName' || field.name === 'id') {\n break;\n }\n\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingDataTranslated[field.name] = translated;\n },\n value: siblingDataFrom[field.name],\n });\n break;\n\n case 'richText':\n if (!(field.localized || localizedParent) || isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) break;\n\n const richTextDataFrom = siblingDataFrom[field.name] as object;\n\n siblingDataTranslated[field.name] = richTextDataFrom;\n\n if (!richTextDataFrom) break;\n\n const isSlate = Array.isArray(richTextDataFrom);\n\n const isLexical = 'root' in richTextDataFrom;\n\n if (!isSlate && !isLexical) break;\n\n if (isLexical) {\n const root = (siblingDataTranslated[field.name] as Record<string, unknown>)\n ?.root as Record<string, unknown>;\n\n if (root)\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root,\n });\n } else {\n for (const root of siblingDataTranslated[field.name] as unknown[]) {\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root: root as Record<string, unknown>,\n });\n }\n }\n\n break;\n\n default:\n break;\n }\n });\n};\n"],"names":["ObjectID","tabHasName","isEmpty","traverseRichText","traverseFields","dataFrom","emptyOnly","fields","localizedParent","siblingDataFrom","siblingDataTranslated","translatedData","valuesToTranslate","forEach","field","type","tabs","tab","hasName","tabDataFrom","name","tabDataTranslated","localized","groupDataFrom","groupDataTranslated","arrayDataFrom","arrayDataTranslated","length","map","id","toHexString","item","index","blocksDataFrom","blocksDataTranslated","blockType","block","blocks","find","each","slug","custom","translatorSkip","push","onTranslate","translated","value","richTextDataFrom","isSlate","Array","isArray","isLexical","root","onText","siblingData","text"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,cAAc,gBAAgB;AACrC,SAAqBC,UAAU,QAAQ,gBAAgB;AAEvD,SAASC,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,gBAAgB,QAAQ,qBAAqB;AAGtD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,eAAe,EACfC,qBAAqB,EACrBC,cAAc,EACdC,iBAAiB,EAUlB;IACCH,kBAAkBA,mBAAmBJ;IACrCK,wBAAwBA,yBAAyBC;IAEjDJ,OAAOM,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBACHD,MAAME,IAAI,CAACH,OAAO,CAAC,CAACI;oBAClB,MAAMC,UAAUjB,WAAWgB;oBAE3B,MAAME,cAAcD,UACfT,eAAe,CAACQ,IAAIG,IAAI,CAAC,GAC1BX;oBAEJ,IAAI,CAACU,aAAa;oBAElB,MAAME,oBAAoBH,UACtB,AAACR,qBAAqB,CAACO,IAAIG,IAA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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,kBAAkBA,mBAAmBJ;IACrCK,wBAAwBA,yBAAyBC;IAEjDJ,OAAOM,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBACHD,MAAME,IAAI,CAACH,OAAO,CAAC,CAACI;oBAClB,MAAMC,UAAUjB,WAAWgB;oBAE3B,MAAME,cAAcD,UACfT,eAAe,CAACQ,IAAIG,IAAI,CAAC,GAC1BX;oBAEJ,IAAI,CAACU,aAAa;oBAElB,MAAME,oBAAoBH,UACtB,AAACR,qBAAqB,CAACO,IAAIG,IAAI,CAAC,IAAgC,CAAC,IACjEV;oBAEJN,eAAe;wBACbC;wBACAC;wBACAC,QAAQU,IAAIV,MAAM;wBAClBC,iBAAiBS,IAAIK,SAAS;wBAC9Bb,iBAAiBU;wBACjBT,uBAAuBW;wBACvBV;wBACAC;oBACF;gBACF;gBAEA;Y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H,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,4 +1,4 @@
1
- import type { PayloadRequest, TypeWithID } from 'payload/types';
1
+ import type { PayloadRequest, TypeWithID } from 'payload';
2
2
  type Args = {
3
3
  collectionSlug?: string;
4
4
  data: Record<string, any>;
@@ -1 +1 @@
1
- {"version":3,"file":"updateEntity.d.ts","sourceRoot":"","sources":["../../src/translate/updateEntity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhE,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,YAAY,iGAStB,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CA6BrD,CAAC"}
1
+ {"version":3,"file":"updateEntity.d.ts","sourceRoot":"","sources":["../../src/translate/updateEntity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1D,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,YAAY,iGAStB,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CA6BrD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { APIError } from 'payload/errors';
1
+ import { APIError } from 'payload';
2
2
  export const updateEntity = ({ collectionSlug, data, depth: incomingDepth, globalSlug, id, locale, overrideAccess, req })=>{
3
3
  if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);
4
4
  const isGlobal = !!globalSlug;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/updateEntity.ts"],"sourcesContent":["import { APIError } from 'payload/errors';\nimport type { PayloadRequest, TypeWithID } from 'payload/types';\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":"AAAA,SAASA,QAAQ,QAAQ,iBAAiB;AAc1C,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.1.41",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "bugs": "https://github.com/r1tsuu/payload-enchants/issues",
6
6
  "repository": "https://github.com/r1tsuu/payload-enchants",
@@ -46,19 +46,19 @@
46
46
  "bson-objectid": "^2.0.4"
47
47
  },
48
48
  "devDependencies": {
49
- "@payloadcms/translations": "3.0.0-beta.41",
50
- "@payloadcms/ui": "3.0.0-beta.41",
49
+ "@payloadcms/translations": "3.0.0-beta.58",
50
+ "@payloadcms/ui": "3.0.0-beta.58",
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.41",
54
- "typescript": "^5.4.5",
53
+ "payload": "3.0.0-beta.58",
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.41",
60
- "@payloadcms/ui": "^3.0.0-beta.41",
61
- "payload": "^3.0.0-beta.41"
59
+ "@payloadcms/translations": "^3.0.0-beta.58",
60
+ "@payloadcms/ui": "^3.0.0-beta.58",
61
+ "payload": "^3.0.0-beta.58"
62
62
  },
63
63
  "publishConfig": {
64
64
  "registry": "https://registry.npmjs.org/"