@payload-enchants/translator 0.0.1-alpha.2 → 0.0.1-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
3
  import './styles.scss';
3
4
  import { DefaultSaveButton } from '@payloadcms/ui/elements/Save';
4
5
  import { useConfig } from '@payloadcms/ui/providers/Config';
@@ -10,13 +11,19 @@ export const CustomSaveButton = ()=>{
10
11
  const config = useConfig();
11
12
  const { globalSlug, id } = useDocumentInfo();
12
13
  const resolvers = config.admin?.custom?.translator?.resolvers ?? [];
13
- if (!id && !globalSlug) return /*#__PURE__*/ React.createElement(DefaultSaveButton, null);
14
- return /*#__PURE__*/ React.createElement(TranslatorProvider, null, /*#__PURE__*/ React.createElement("div", {
15
- className: 'translator__custom-save-button'
16
- }, /*#__PURE__*/ React.createElement(TranslatorModal, null), resolvers.map((resolver)=>/*#__PURE__*/ React.createElement(ResolverButton, {
17
- key: resolver.key,
18
- resolver: resolver
19
- })), /*#__PURE__*/ React.createElement(DefaultSaveButton, null)));
14
+ if (!id && !globalSlug) return /*#__PURE__*/ _jsx(DefaultSaveButton, {});
15
+ return /*#__PURE__*/ _jsx(TranslatorProvider, {
16
+ children: /*#__PURE__*/ _jsxs("div", {
17
+ className: 'translator__custom-save-button',
18
+ children: [
19
+ /*#__PURE__*/ _jsx(TranslatorModal, {}),
20
+ resolvers.map((resolver)=>/*#__PURE__*/ _jsx(ResolverButton, {
21
+ resolver: resolver
22
+ }, resolver.key)),
23
+ /*#__PURE__*/ _jsx(DefaultSaveButton, {})
24
+ ]
25
+ })
26
+ });
20
27
  };
21
28
 
22
29
  //# sourceMappingURL=CustomSaveButton.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/CustomSaveButton/CustomSaveButton.tsx"],"sourcesContent":["'use client';\r\n\r\nimport './styles.scss';\r\n\r\nimport { DefaultSaveButton } from '@payloadcms/ui/elements/Save';\r\nimport { useConfig } from '@payloadcms/ui/providers/Config';\r\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\nimport { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';\r\nimport { ResolverButton } from '../ResolverButton';\r\nimport { TranslatorModal } from '../TranslatorModal';\r\n\r\nexport const CustomSaveButton = () => {\r\n const config = useConfig();\r\n\r\n const { globalSlug, id } = useDocumentInfo();\r\n\r\n const resolvers = (config.admin?.custom?.translator?.resolvers as TranslateResolver[]) ?? [];\r\n\r\n if (!id && !globalSlug) return <DefaultSaveButton />;\r\n\r\n return (\r\n <TranslatorProvider>\r\n <div className={'translator__custom-save-button'}>\r\n <TranslatorModal />\r\n {resolvers.map((resolver) => (\r\n <ResolverButton key={resolver.key} resolver={resolver} />\r\n ))}\r\n <DefaultSaveButton />\r\n </div>\r\n </TranslatorProvider>\r\n );\r\n};\r\n"],"names":["DefaultSaveButton","useConfig","useDocumentInfo","TranslatorProvider","ResolverButton","TranslatorModal","CustomSaveButton","config","globalSlug","id","resolvers","admin","custom","translator","div","className","map","resolver","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAEA,OAAO,gBAAgB;AAEvB,SAASA,iBAAiB,QAAQ,+BAA+B;AACjE,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,eAAe,QAAQ,wCAAwC;AAGxE,SAASC,kBAAkB,QAAQ,gDAAgD;AACnF,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,eAAe,QAAQ,qBAAqB;AAErD,OAAO,MAAMC,mBAAmB;IAC9B,MAAMC,SAASN;IAEf,MAAM,EAAEO,UAAU,EAAEC,EAAE,EAAE,GAAGP;IAE3B,MAAMQ,YAAY,AAACH,OAAOI,KAAK,EAAEC,QAAQC,YAAYH,aAAqC,EAAE;IAE5F,IAAI,CAACD,MAAM,CAACD,YAAY,qBAAO,oBAACR;IAEhC,qBACE,oBAACG,wCACC,oBAACW;QAAIC,WAAW;qBACd,oBAACV,wBACAK,UAAUM,GAAG,CAAC,CAACC,yBACd,oBAACb;YAAec,KAAKD,SAASC,GAAG;YAAED,UAAUA;2BAE/C,oBAACjB;AAIT,EAAE"}
1
+ {"version":3,"sources":["../../../../src/client/components/CustomSaveButton/CustomSaveButton.tsx"],"sourcesContent":["'use client';\r\n\r\nimport './styles.scss';\r\n\r\nimport { DefaultSaveButton } from '@payloadcms/ui/elements/Save';\r\nimport { useConfig } from '@payloadcms/ui/providers/Config';\r\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\nimport { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';\r\nimport { ResolverButton } from '../ResolverButton';\r\nimport { TranslatorModal } from '../TranslatorModal';\r\n\r\nexport const CustomSaveButton = () => {\r\n const config = useConfig();\r\n\r\n const { globalSlug, id } = useDocumentInfo();\r\n\r\n const resolvers = (config.admin?.custom?.translator?.resolvers as TranslateResolver[]) ?? [];\r\n\r\n if (!id && !globalSlug) return <DefaultSaveButton />;\r\n\r\n return (\r\n <TranslatorProvider>\r\n <div className={'translator__custom-save-button'}>\r\n <TranslatorModal />\r\n {resolvers.map((resolver) => (\r\n <ResolverButton key={resolver.key} resolver={resolver} />\r\n ))}\r\n <DefaultSaveButton />\r\n </div>\r\n </TranslatorProvider>\r\n );\r\n};\r\n"],"names":["DefaultSaveButton","useConfig","useDocumentInfo","TranslatorProvider","ResolverButton","TranslatorModal","CustomSaveButton","config","globalSlug","id","resolvers","admin","custom","translator","div","className","map","resolver","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAEA,OAAO,gBAAgB;AAEvB,SAASA,iBAAiB,QAAQ,+BAA+B;AACjE,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,eAAe,QAAQ,wCAAwC;AAGxE,SAASC,kBAAkB,QAAQ,gDAAgD;AACnF,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,eAAe,QAAQ,qBAAqB;AAErD,OAAO,MAAMC,mBAAmB;IAC9B,MAAMC,SAASN;IAEf,MAAM,EAAEO,UAAU,EAAEC,EAAE,EAAE,GAAGP;IAE3B,MAAMQ,YAAY,AAACH,OAAOI,KAAK,EAAEC,QAAQC,YAAYH,aAAqC,EAAE;IAE5F,IAAI,CAACD,MAAM,CAACD,YAAY,qBAAO,KAACR;IAEhC,qBACE,KAACG;kBACC,cAAA,MAACW;YAAIC,WAAW;;8BACd,KAACV;gBACAK,UAAUM,GAAG,CAAC,CAACC,yBACd,KAACb;wBAAkCa,UAAUA;uBAAxBA,SAASC,GAAG;8BAEnC,KAAClB;;;;AAIT,EAAE"}
@@ -1,19 +1,29 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  import { getTranslation } from '@payloadcms/translations';
2
3
  import { Chevron } from '@payloadcms/ui/icons/Chevron';
3
4
  import { useTranslation } from '@payloadcms/ui/providers/Translation';
4
5
  const baseClass = 'localizer-button';
5
6
  export const LocaleLabel = ({ locale })=>{
6
7
  const { i18n, t } = useTranslation();
7
- return /*#__PURE__*/ React.createElement("div", {
8
+ return /*#__PURE__*/ _jsxs("div", {
8
9
  "aria-label": t('general:locale'),
9
- className: baseClass
10
- }, /*#__PURE__*/ React.createElement("div", {
11
- className: `${baseClass}__label`
12
- }, `${t('general:locale')}:`), "  ", /*#__PURE__*/ React.createElement("span", {
13
- className: `${baseClass}__current-label`
14
- }, `${getTranslation(locale.label, i18n)}`), " ", /*#__PURE__*/ React.createElement(Chevron, {
15
- className: `${baseClass}__chevron`
16
- }));
10
+ className: baseClass,
11
+ children: [
12
+ /*#__PURE__*/ _jsx("div", {
13
+ className: `${baseClass}__label`,
14
+ children: `${t('general:locale')}:`
15
+ }),
16
+ "  ",
17
+ /*#__PURE__*/ _jsx("span", {
18
+ className: `${baseClass}__current-label`,
19
+ children: `${getTranslation(locale.label, i18n)}`
20
+ }),
21
+ " ",
22
+ /*#__PURE__*/ _jsx(Chevron, {
23
+ className: `${baseClass}__chevron`
24
+ })
25
+ ]
26
+ });
17
27
  };
18
28
 
19
29
  //# sourceMappingURL=LocaleLabel.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\r\nimport { Chevron } from '@payloadcms/ui/icons/Chevron';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\nimport type { Locale } from 'payload/config';\r\n\r\nconst baseClass = 'localizer-button';\r\n\r\nexport const LocaleLabel = ({ locale }: { locale: Locale }) => {\r\n const { i18n, t } = useTranslation();\r\n\r\n return (\r\n <div aria-label={t('general:locale')} className={baseClass}>\r\n <div className={`${baseClass}__label`}>{`${t('general:locale')}:`}</div>\r\n &nbsp;&nbsp;\r\n <span className={`${baseClass}__current-label`}>\r\n {`${getTranslation(locale.label, i18n)}`}\r\n </span>\r\n &nbsp;\r\n <Chevron className={`${baseClass}__chevron`} />\r\n </div>\r\n );\r\n};\r\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,oBAACM;QAAIC,cAAYF,EAAE;QAAmBG,WAAWP;qBAC/C,oBAACK;QAAIE,WAAW,CAAC,EAAEP,UAAU,OAAO,CAAC;OAAG,CAAC,EAAEI,EAAE,kBAAkB,CAAC,CAAC,GAAO,oBAExE,oBAACI;QAAKD,WAAW,CAAC,EAAEP,UAAU,eAAe,CAAC;OAC3C,CAAC,EAAEH,eAAeK,OAAOO,KAAK,EAAEN,MAAM,CAAC,GACnC,mBAEP,oBAACL;QAAQS,WAAW,CAAC,EAAEP,UAAU,SAAS,CAAC;;AAGjD,EAAE"}
1
+ {"version":3,"sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\r\nimport { Chevron } from '@payloadcms/ui/icons/Chevron';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\nimport type { Locale } from 'payload/config';\r\n\r\nconst baseClass = 'localizer-button';\r\n\r\nexport const LocaleLabel = ({ locale }: { locale: Locale }) => {\r\n const { i18n, t } = useTranslation();\r\n\r\n return (\r\n <div aria-label={t('general:locale')} className={baseClass}>\r\n <div className={`${baseClass}__label`}>{`${t('general:locale')}:`}</div>\r\n &nbsp;&nbsp;\r\n <span className={`${baseClass}__current-label`}>\r\n {`${getTranslation(locale.label, i18n)}`}\r\n </span>\r\n &nbsp;\r\n <Chevron className={`${baseClass}__chevron`} />\r\n </div>\r\n );\r\n};\r\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,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  import { Button } from '@payloadcms/ui/elements';
2
3
  import { useTranslation } from '@payloadcms/ui/providers/Translation';
3
4
  import { useTranslator } from '../../providers/Translator/context';
@@ -7,10 +8,11 @@ export const ResolverButton = ({ resolver: { key: resolverKey } })=>{
7
8
  const handleClick = ()=>openTranslator({
8
9
  resolverKey
9
10
  });
10
- return /*#__PURE__*/ React.createElement(Button, {
11
+ return /*#__PURE__*/ _jsx(Button, {
11
12
  onClick: handleClick,
12
- size: "small"
13
- }, t(`plugin-translator:resolver_${resolverKey}_buttonLabel`));
13
+ size: "small",
14
+ children: t(`plugin-translator:resolver_${resolverKey}_buttonLabel`)
15
+ });
14
16
  };
15
17
 
16
18
  //# sourceMappingURL=ResolverButton.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"sourcesContent":["import { Button } from '@payloadcms/ui/elements';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\nimport { useTranslator } from '../../providers/Translator/context';\r\n\r\nexport const ResolverButton = ({\r\n resolver: { key: resolverKey },\r\n}: {\r\n resolver: TranslateResolver;\r\n}) => {\r\n const { openTranslator } = useTranslator();\r\n\r\n const { t } = useTranslation();\r\n\r\n const handleClick = () => openTranslator({ resolverKey });\r\n\r\n return (\r\n <Button onClick={handleClick} size='small'>\r\n {t(`plugin-translator:resolver_${resolverKey}_buttonLabel`)}\r\n </Button>\r\n );\r\n};\r\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,oBAACN;QAAOU,SAASD;QAAaE,MAAK;OAChCH,EAAE,CAAC,2BAA2B,EAAEF,YAAY,YAAY,CAAC;AAGhE,EAAE"}
1
+ {"version":3,"sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"sourcesContent":["import { Button } from '@payloadcms/ui/elements';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\nimport { useTranslator } from '../../providers/Translator/context';\r\n\r\nexport const ResolverButton = ({\r\n resolver: { key: resolverKey },\r\n}: {\r\n resolver: TranslateResolver;\r\n}) => {\r\n const { openTranslator } = useTranslator();\r\n\r\n const { t } = useTranslation();\r\n\r\n const handleClick = () => openTranslator({ resolverKey });\r\n\r\n return (\r\n <Button onClick={handleClick} size='small'>\r\n {t(`plugin-translator:resolver_${resolverKey}_buttonLabel`)}\r\n </Button>\r\n );\r\n};\r\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,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  import { getTranslation } from '@payloadcms/translations';
2
3
  import { Button, Popup, PopupList } from '@payloadcms/ui/elements';
3
4
  import { useTranslation } from '@payloadcms/ui/providers/Translation';
@@ -7,36 +8,54 @@ export const Content = ()=>{
7
8
  const { localeToTranslateFrom: localeCodeToTranslateFrom, localesOptions, resolverT, setLocaleToTranslateFrom, submit } = useTranslator();
8
9
  const { i18n } = useTranslation();
9
10
  const localeToTranslateFrom = localesOptions.find((each)=>each.code === localeCodeToTranslateFrom);
10
- return /*#__PURE__*/ React.createElement("div", {
11
- className: 'translator__content'
12
- }, /*#__PURE__*/ React.createElement("h2", null, resolverT('modalTitle')), localeToTranslateFrom && /*#__PURE__*/ React.createElement(Popup, {
13
- button: /*#__PURE__*/ React.createElement(LocaleLabel, {
14
- locale: localeToTranslateFrom
15
- }),
16
- horizontalAlign: "center",
17
- render: ({ close })=>/*#__PURE__*/ React.createElement(PopupList.ButtonGroup, null, localesOptions.map((option)=>{
18
- const label = getTranslation(option.label, i18n);
19
- return /*#__PURE__*/ React.createElement(PopupList.Button, {
20
- active: option.code === localeCodeToTranslateFrom,
21
- key: option.code,
22
- onClick: ()=>{
23
- setLocaleToTranslateFrom(option.code);
24
- close();
25
- }
26
- }, label, label !== option.code && ` (${option.code})`);
27
- })),
28
- verticalAlign: "bottom"
29
- }), /*#__PURE__*/ React.createElement("div", {
30
- className: 'translator__buttons'
31
- }, /*#__PURE__*/ React.createElement(Button, {
32
- onClick: ()=>submit({
33
- emptyOnly: false
11
+ return /*#__PURE__*/ _jsxs("div", {
12
+ className: 'translator__content',
13
+ children: [
14
+ /*#__PURE__*/ _jsx("h2", {
15
+ children: resolverT('modalTitle')
16
+ }),
17
+ localeToTranslateFrom && /*#__PURE__*/ _jsx(Popup, {
18
+ button: /*#__PURE__*/ _jsx(LocaleLabel, {
19
+ locale: localeToTranslateFrom
20
+ }),
21
+ horizontalAlign: "center",
22
+ render: ({ close })=>/*#__PURE__*/ _jsx(PopupList.ButtonGroup, {
23
+ children: localesOptions.map((option)=>{
24
+ const label = getTranslation(option.label, i18n);
25
+ return /*#__PURE__*/ _jsxs(PopupList.Button, {
26
+ active: option.code === localeCodeToTranslateFrom,
27
+ onClick: ()=>{
28
+ setLocaleToTranslateFrom(option.code);
29
+ close();
30
+ },
31
+ children: [
32
+ label,
33
+ label !== option.code && ` (${option.code})`
34
+ ]
35
+ }, option.code);
36
+ })
37
+ }),
38
+ verticalAlign: "bottom"
39
+ }),
40
+ /*#__PURE__*/ _jsxs("div", {
41
+ className: 'translator__buttons',
42
+ children: [
43
+ /*#__PURE__*/ _jsx(Button, {
44
+ onClick: ()=>submit({
45
+ emptyOnly: false
46
+ }),
47
+ children: resolverT('submitButtonLabelFull')
48
+ }),
49
+ /*#__PURE__*/ _jsx(Button, {
50
+ onClick: ()=>submit({
51
+ emptyOnly: true
52
+ }),
53
+ children: resolverT('submitButtonLabelEmpty')
54
+ })
55
+ ]
34
56
  })
35
- }, resolverT('submitButtonLabelFull')), /*#__PURE__*/ React.createElement(Button, {
36
- onClick: ()=>submit({
37
- emptyOnly: true
38
- })
39
- }, resolverT('submitButtonLabelEmpty'))));
57
+ ]
58
+ });
40
59
  };
41
60
 
42
61
  //# sourceMappingURL=Content.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\r\nimport { Button, Popup, PopupList } from '@payloadcms/ui/elements';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\n\r\nimport { useTranslator } from '../../providers/Translator/context';\r\nimport { LocaleLabel } from '../LocaleLabel';\r\n\r\nexport const Content = () => {\r\n const {\r\n localeToTranslateFrom: localeCodeToTranslateFrom,\r\n localesOptions,\r\n resolverT,\r\n setLocaleToTranslateFrom,\r\n submit,\r\n } = useTranslator();\r\n\r\n const { i18n } = useTranslation();\r\n\r\n const localeToTranslateFrom = localesOptions.find(\r\n (each) => each.code === localeCodeToTranslateFrom,\r\n );\r\n\r\n return (\r\n <div className={'translator__content'}>\r\n <h2>{resolverT('modalTitle')}</h2>\r\n {localeToTranslateFrom && (\r\n <Popup\r\n button={<LocaleLabel locale={localeToTranslateFrom} />}\r\n horizontalAlign='center'\r\n render={({ close }) => (\r\n <PopupList.ButtonGroup>\r\n {localesOptions.map((option) => {\r\n const label = getTranslation(option.label, i18n);\r\n\r\n return (\r\n <PopupList.Button\r\n active={option.code === localeCodeToTranslateFrom}\r\n key={option.code}\r\n onClick={() => {\r\n setLocaleToTranslateFrom(option.code);\r\n close();\r\n }}\r\n >\r\n {label}\r\n {label !== option.code && ` (${option.code})`}\r\n </PopupList.Button>\r\n );\r\n })}\r\n </PopupList.ButtonGroup>\r\n )}\r\n verticalAlign='bottom'\r\n />\r\n )}\r\n <div className={'translator__buttons'}>\r\n <Button onClick={() => submit({ emptyOnly: false })}>\r\n {resolverT('submitButtonLabelFull')}\r\n </Button>\r\n <Button onClick={() => submit({ emptyOnly: true })}>\r\n {resolverT('submitButtonLabelEmpty')}\r\n </Button>\r\n </div>\r\n </div>\r\n );\r\n};\r\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","key","onClick","verticalAlign","emptyOnly"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","m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,"sources":["../../../../src/client/components/TranslatorModal/Content.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\r\nimport { Button, Popup, PopupList } from '@payloadcms/ui/elements';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\n\r\nimport { useTranslator } from '../../providers/Translator/context';\r\nimport { LocaleLabel } from '../LocaleLabel';\r\n\r\nexport const Content = () => {\r\n const {\r\n localeToTranslateFrom: localeCodeToTranslateFrom,\r\n localesOptions,\r\n resolverT,\r\n setLocaleToTranslateFrom,\r\n submit,\r\n } = useTranslator();\r\n\r\n const { i18n } = useTranslation();\r\n\r\n const localeToTranslateFrom = localesOptions.find(\r\n (each) => each.code === localeCodeToTranslateFrom,\r\n );\r\n\r\n return (\r\n <div className={'translator__content'}>\r\n <h2>{resolverT('modalTitle')}</h2>\r\n {localeToTranslateFrom && (\r\n <Popup\r\n button={<LocaleLabel locale={localeToTranslateFrom} />}\r\n horizontalAlign='center'\r\n render={({ close }) => (\r\n <PopupList.ButtonGroup>\r\n {localesOptions.map((option) => {\r\n const label = getTranslation(option.label, i18n);\r\n\r\n return (\r\n <PopupList.Button\r\n active={option.code === localeCodeToTranslateFrom}\r\n key={option.code}\r\n onClick={() => {\r\n setLocaleToTranslateFrom(option.code);\r\n close();\r\n }}\r\n >\r\n {label}\r\n {label !== option.code && ` (${option.code})`}\r\n </PopupList.Button>\r\n );\r\n })}\r\n </PopupList.ButtonGroup>\r\n )}\r\n verticalAlign='bottom'\r\n />\r\n )}\r\n <div className={'translator__buttons'}>\r\n <Button onClick={() => submit({ emptyOnly: false })}>\r\n {resolverT('submitButtonLabelFull')}\r\n </Button>\r\n <Button onClick={() => submit({ emptyOnly: true })}>\r\n {resolverT('submitButtonLabelEmpty')}\r\n </Button>\r\n </div>\r\n </div>\r\n );\r\n};\r\n"],"names":["getTranslation","Button","Popup","PopupList","useTranslation","useTranslator","LocaleLabel","Content","localeToTranslateFrom","localeCodeToTranslateFrom","localesOptions","resolverT","setLocaleToTranslateFrom","submit","i18n","find","each","code","div","className","h2","button","locale","horizontalAlign","render","close","ButtonGroup","map","option","label","active","onClick","verticalAlign","emptyOnly"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,MAAM,EAAEC,KAAK,EAAEC,SAAS,QAAQ,0BAA0B;AACnE,SAASC,cAAc,QAAQ,uCAAuC;AAEtE,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,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  import './styles.scss';
2
3
  import { Modal } from '@payloadcms/ui/elements';
3
4
  import { useTranslator } from '../../providers/Translator/context';
@@ -5,17 +6,22 @@ import { Content } from './Content';
5
6
  export const TranslatorModal = ()=>{
6
7
  const { closeTranslator, modalSlug, resolver } = useTranslator();
7
8
  if (!resolver) return;
8
- return /*#__PURE__*/ React.createElement(Modal, {
9
+ return /*#__PURE__*/ _jsx(Modal, {
9
10
  className: 'translator__modal',
10
- slug: modalSlug
11
- }, /*#__PURE__*/ React.createElement("div", {
12
- className: 'translator__wrapper'
13
- }, /*#__PURE__*/ React.createElement("span", {
14
- "aria-label": "Close",
15
- className: 'translator__close',
16
- onClick: closeTranslator,
17
- role: "button"
18
- }), /*#__PURE__*/ React.createElement(Content, null)));
11
+ slug: modalSlug,
12
+ children: /*#__PURE__*/ _jsxs("div", {
13
+ className: 'translator__wrapper',
14
+ children: [
15
+ /*#__PURE__*/ _jsx("span", {
16
+ "aria-label": "Close",
17
+ className: 'translator__close',
18
+ onClick: closeTranslator,
19
+ role: "button"
20
+ }),
21
+ /*#__PURE__*/ _jsx(Content, {})
22
+ ]
23
+ })
24
+ });
19
25
  };
20
26
 
21
27
  //# sourceMappingURL=TranslatorModal.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"sourcesContent":["import './styles.scss';\r\n\r\nimport { Modal } from '@payloadcms/ui/elements';\r\n\r\nimport { useTranslator } from '../../providers/Translator/context';\r\nimport { Content } from './Content';\r\n\r\nexport const TranslatorModal = () => {\r\n const { closeTranslator, modalSlug, resolver } = useTranslator();\r\n\r\n if (!resolver) return;\r\n\r\n return (\r\n <Modal className={'translator__modal'} slug={modalSlug}>\r\n <div className={'translator__wrapper'}>\r\n <span\r\n aria-label='Close'\r\n className={'translator__close'}\r\n onClick={closeTranslator}\r\n role='button'\r\n />\r\n <Content />\r\n </div>\r\n </Modal>\r\n );\r\n};\r\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,oBAACN;QAAMO,WAAW;QAAqBC,MAAMH;qBAC3C,oBAACI;QAAIF,WAAW;qBACd,oBAACG;QACCC,cAAW;QACXJ,WAAW;QACXK,SAASR;QACTS,MAAK;sBAEP,oBAACX;AAIT,EAAE"}
1
+ {"version":3,"sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"sourcesContent":["import './styles.scss';\r\n\r\nimport { Modal } from '@payloadcms/ui/elements';\r\n\r\nimport { useTranslator } from '../../providers/Translator/context';\r\nimport { Content } from './Content';\r\n\r\nexport const TranslatorModal = () => {\r\n const { closeTranslator, modalSlug, resolver } = useTranslator();\r\n\r\n if (!resolver) return;\r\n\r\n return (\r\n <Modal className={'translator__modal'} slug={modalSlug}>\r\n <div className={'translator__wrapper'}>\r\n <span\r\n aria-label='Close'\r\n className={'translator__close'}\r\n onClick={closeTranslator}\r\n role='button'\r\n />\r\n <Content />\r\n </div>\r\n </Modal>\r\n );\r\n};\r\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,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  import { toast } from '@payloadcms/ui/elements';
2
3
  import { useModal } from '@payloadcms/ui/elements/Modal';
3
4
  import { useAllFormFields } from '@payloadcms/ui/forms/Form';
@@ -79,7 +80,7 @@ export const TranslatorProvider = ({ children })=>{
79
80
  if (resolverConfig) toast.success(resolverT('successMessage'));
80
81
  closeTranslator();
81
82
  };
82
- return /*#__PURE__*/ React.createElement(TranslatorContext.Provider, {
83
+ return /*#__PURE__*/ _jsx(TranslatorContext.Provider, {
83
84
  value: {
84
85
  closeTranslator,
85
86
  localeToTranslateFrom,
@@ -93,8 +94,9 @@ export const TranslatorProvider = ({ children })=>{
93
94
  resolverT,
94
95
  setLocaleToTranslateFrom,
95
96
  submit
96
- }
97
- }, children);
97
+ },
98
+ children: children
99
+ });
98
100
  };
99
101
 
100
102
  //# sourceMappingURL=TranslatorProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import { toast } from '@payloadcms/ui/elements';\r\nimport { useModal } from '@payloadcms/ui/elements/Modal';\r\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form';\r\nimport { useConfig } from '@payloadcms/ui/providers/Config';\r\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';\r\nimport { useLocale } from '@payloadcms/ui/providers/Locale';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState';\r\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';\r\nimport { type ReactNode, useMemo, useState } from 'react';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\nimport type { TranslateArgs } from '../../../translate/types';\r\nimport { createClient } from '../../api';\r\nimport { TranslatorContext } from './context';\r\n\r\nconst modalSlug = 'translator-modal';\r\n\r\nexport const TranslatorProvider = ({ children }: { children: ReactNode }) => {\r\n const [resolver, setResolver] = useState<null | string>(null);\r\n\r\n const [data, dispatch] = useAllFormFields();\r\n\r\n const { collectionSlug, globalSlug, id } = useDocumentInfo();\r\n\r\n const modal = useModal();\r\n\r\n const { t } = useTranslation();\r\n\r\n const resolverT = (\r\n key:\r\n | 'buttonLabel'\r\n | 'errorMessage'\r\n | 'modalTitle'\r\n | 'submitButtonLabelEmpty'\r\n | 'submitButtonLabelFull'\r\n | 'successMessage',\r\n ) => {\r\n if (!resolver) return '';\r\n\r\n return t(`plugin-translator:resolver_${resolver}_${key}`);\r\n };\r\n\r\n const locale = useLocale();\r\n\r\n const {\r\n admin: { custom },\r\n localization,\r\n routes: { api },\r\n serverURL,\r\n } = useConfig();\r\n\r\n const apiClient = createClient({ api, serverURL });\r\n\r\n const resolverConfig = useMemo(() => {\r\n if (!resolver) return null;\r\n\r\n const resolvers = (custom?.translator?.resolvers as TranslateResolver[]) || undefined;\r\n\r\n if (!resolvers) return null;\r\n\r\n const resolverConfig = resolvers.find((each) => each.key === resolver);\r\n\r\n return resolverConfig ?? null;\r\n }, [custom, resolver]);\r\n\r\n if (!localization)\r\n throw new Error('Localization config is not provided and PluginTranslator is used');\r\n\r\n const localesOptions = localization.locales.filter((each) => each.code !== locale.code);\r\n\r\n const [localeToTranslateFrom, setLocaleToTranslateFrom] = useState(() => {\r\n const defaultFromOptions = localesOptions.find(\r\n (each) => localization.defaultLocale === each.code,\r\n );\r\n\r\n if (defaultFromOptions) return defaultFromOptions.code;\r\n\r\n return localesOptions[0].code;\r\n });\r\n\r\n const closeTranslator = () => modal.closeModal(modalSlug);\r\n\r\n const submit = async ({ emptyOnly }: { emptyOnly: boolean }) => {\r\n if (!resolver) return;\r\n\r\n const args: TranslateArgs = {\r\n collectionSlug,\r\n data: reduceFieldsToValues(data, true),\r\n emptyOnly,\r\n globalSlug,\r\n id: id === null ? undefined : id,\r\n locale: locale.code,\r\n localeFrom: localeToTranslateFrom,\r\n resolver,\r\n };\r\n\r\n const result = await apiClient.translate(args);\r\n\r\n if (!result.success) {\r\n toast.error(resolverT('errorMessage'));\r\n\r\n return;\r\n }\r\n\r\n dispatch({\r\n state: await getFormState({\r\n apiRoute: api,\r\n body: {\r\n collectionSlug,\r\n data: result.translatedData,\r\n globalSlug,\r\n locale: locale.code,\r\n schemaPath: collectionSlug || globalSlug || '',\r\n },\r\n serverURL,\r\n }),\r\n type: 'REPLACE_STATE',\r\n });\r\n\r\n if (resolverConfig) toast.success(resolverT('successMessage'));\r\n closeTranslator();\r\n };\r\n\r\n return (\r\n <TranslatorContext.Provider\r\n value={{\r\n closeTranslator,\r\n localeToTranslateFrom,\r\n localesOptions,\r\n modalSlug,\r\n openTranslator: ({ resolverKey }) => {\r\n setResolver(resolverKey);\r\n modal.openModal(modalSlug);\r\n },\r\n resolver: resolverConfig,\r\n resolverT,\r\n setLocaleToTranslateFrom,\r\n submit,\r\n }}\r\n >\r\n {children}\r\n </TranslatorContext.Provider>\r\n );\r\n};\r\n"],"names":["toast","useModal","useAllFormFields","useConfig","useDocumentInfo","useLocale","useTranslation","getFormState","reduceFieldsToValues","useMemo","useState","createClient","TranslatorContext","modalSlug","TranslatorProvider","children","resolver","setResolver","data","dispatch","collectionSlug","globalSlug","id","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,QAAQ,4BAA4B;AAC7D,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,eAAe,QAAQ,wCAAwC;AACxE,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,cAAc,QAAQ,uCAAuC;AACtE,SAASC,YAAY,QAAQ,wCAAwC;AACrE,SAASC,oBAAoB,QAAQ,gDAAgD;AACrF,SAAyBC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAI1D,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,GAAGjB;IAEzB,MAAM,EAAEkB,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAE,GAAGlB;IAE3C,MAAMmB,QAAQtB;IAEd,MAAM,EAAEuB,CAAC,EAAE,GAAGlB;IAEd,MAAMmB,YAAY,CAChBC;QAQA,IAAI,CAACV,UAAU,OAAO;QAEtB,OAAOQ,EAAE,CAAC,2BAA2B,EAAER,SA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QAEzC,IAAI,CAACE,OAAOE,OAAO,EAAE;YACnB1D,MAAM2D,KAAK,CAAClC,UAAU;YAEtB;QACF;QAEAN,SAAS;YACPyC,OAAO,MAAMrD,aAAa;gBACxBsD,UAAU7B;gBACV8B,MAAM;oBACJ1C;oBACAF,MAAMsC,OAAOO,cAAc;oBAC3B1C;oBACAM,QAAQA,OAAOkB,IAAI;oBACnBmB,YAAY5C,kBAAkBC,cAAc;gBAC9C;gBACAY;YACF;YACAgC,MAAM;QACR;QAEA,IAAI9B,gBAAgBnC,MAAM0D,OAAO,CAACjC,UAAU;QAC5CyB;IACF;IAEA,qBACE,oBAACtC,kBAAkBsD,QAAQ;QACzBC,OAAO;YACLjB;YACAJ;YACAJ;YACA7B;YACAuD,gBAAgB,CAAC,EAAEC,WAAW,EAAE;gBAC9BpD,YAAYoD;gBACZ9C,MAAM+C,SAAS,CAACzD;YAClB;YACAG,UAAUmB;YACVV;YACAsB;YACAK;QACF;OAECrC;AAGP,EAAE"}
1
+ {"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import { toast } from '@payloadcms/ui/elements';\r\nimport { useModal } from '@payloadcms/ui/elements/Modal';\r\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form';\r\nimport { useConfig } from '@payloadcms/ui/providers/Config';\r\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';\r\nimport { useLocale } from '@payloadcms/ui/providers/Locale';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState';\r\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';\r\nimport { type ReactNode, useMemo, useState } from 'react';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\nimport type { TranslateArgs } from '../../../translate/types';\r\nimport { createClient } from '../../api';\r\nimport { TranslatorContext } from './context';\r\n\r\nconst modalSlug = 'translator-modal';\r\n\r\nexport const TranslatorProvider = ({ children }: { children: ReactNode }) => {\r\n const [resolver, setResolver] = useState<null | string>(null);\r\n\r\n const [data, dispatch] = useAllFormFields();\r\n\r\n const { collectionSlug, globalSlug, id } = useDocumentInfo();\r\n\r\n const modal = useModal();\r\n\r\n const { t } = useTranslation();\r\n\r\n const resolverT = (\r\n key:\r\n | 'buttonLabel'\r\n | 'errorMessage'\r\n | 'modalTitle'\r\n | 'submitButtonLabelEmpty'\r\n | 'submitButtonLabelFull'\r\n | 'successMessage',\r\n ) => {\r\n if (!resolver) return '';\r\n\r\n return t(`plugin-translator:resolver_${resolver}_${key}`);\r\n };\r\n\r\n const locale = useLocale();\r\n\r\n const {\r\n admin: { custom },\r\n localization,\r\n routes: { api },\r\n serverURL,\r\n } = useConfig();\r\n\r\n const apiClient = createClient({ api, serverURL });\r\n\r\n const resolverConfig = useMemo(() => {\r\n if (!resolver) return null;\r\n\r\n const resolvers = (custom?.translator?.resolvers as TranslateResolver[]) || undefined;\r\n\r\n if (!resolvers) return null;\r\n\r\n const resolverConfig = resolvers.find((each) => each.key === resolver);\r\n\r\n return resolverConfig ?? null;\r\n }, [custom, resolver]);\r\n\r\n if (!localization)\r\n throw new Error('Localization config is not provided and PluginTranslator is used');\r\n\r\n const localesOptions = localization.locales.filter((each) => each.code !== locale.code);\r\n\r\n const [localeToTranslateFrom, setLocaleToTranslateFrom] = useState(() => {\r\n const defaultFromOptions = localesOptions.find(\r\n (each) => localization.defaultLocale === each.code,\r\n );\r\n\r\n if (defaultFromOptions) return defaultFromOptions.code;\r\n\r\n return localesOptions[0].code;\r\n });\r\n\r\n const closeTranslator = () => modal.closeModal(modalSlug);\r\n\r\n const submit = async ({ emptyOnly }: { emptyOnly: boolean }) => {\r\n if (!resolver) return;\r\n\r\n const args: TranslateArgs = {\r\n collectionSlug,\r\n data: reduceFieldsToValues(data, true),\r\n emptyOnly,\r\n globalSlug,\r\n id: id === null ? undefined : id,\r\n locale: locale.code,\r\n localeFrom: localeToTranslateFrom,\r\n resolver,\r\n };\r\n\r\n const result = await apiClient.translate(args);\r\n\r\n if (!result.success) {\r\n toast.error(resolverT('errorMessage'));\r\n\r\n return;\r\n }\r\n\r\n dispatch({\r\n state: await getFormState({\r\n apiRoute: api,\r\n body: {\r\n collectionSlug,\r\n data: result.translatedData,\r\n globalSlug,\r\n locale: locale.code,\r\n schemaPath: collectionSlug || globalSlug || '',\r\n },\r\n serverURL,\r\n }),\r\n type: 'REPLACE_STATE',\r\n });\r\n\r\n if (resolverConfig) toast.success(resolverT('successMessage'));\r\n closeTranslator();\r\n };\r\n\r\n return (\r\n <TranslatorContext.Provider\r\n value={{\r\n closeTranslator,\r\n localeToTranslateFrom,\r\n localesOptions,\r\n modalSlug,\r\n openTranslator: ({ resolverKey }) => {\r\n setResolver(resolverKey);\r\n modal.openModal(modalSlug);\r\n },\r\n resolver: resolverConfig,\r\n resolverT,\r\n setLocaleToTranslateFrom,\r\n submit,\r\n }}\r\n >\r\n {children}\r\n </TranslatorContext.Provider>\r\n );\r\n};\r\n"],"names":["toast","useModal","useAllFormFields","useConfig","useDocumentInfo","useLocale","useTranslation","getFormState","reduceFieldsToValues","useMemo","useState","createClient","TranslatorContext","modalSlug","TranslatorProvider","children","resolver","setResolver","data","dispatch","collectionSlug","globalSlug","id","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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CAAC,EAAEC,WAAW,EAAE;gBAC9BpD,YAAYoD;gBACZ9C,MAAM+C,SAAS,CAACzD;YAClB;YACAG,UAAUmB;YACVV;YACAsB;YACAK;QACF;kBAECrC;;AAGP,EAAE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@payload-enchants/translator",
3
3
  "private": false,
4
- "version": "0.0.1-alpha.2",
4
+ "version": "0.0.1-alpha.3",
5
5
  "repository": "https://github.com/r1tsuu/payload-plugin-translator",
6
6
  "author": "r1tsuu",
7
7
  "bugs": "https://github.com/r1tsuu/payload-plugin-translator/issues",