@littlebox/strapi-suite 1.0.51 → 1.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +29 -0
  2. package/dist/_chunks/{App-C7RgdLC-.js → App-B7_8BaVG.js} +557 -35
  3. package/dist/_chunks/{App-b_1MuDrk.mjs → App-BfGB2pF_.mjs} +550 -28
  4. package/dist/_chunks/{SlugInput-DlOanbzA.mjs → SlugInput-CvgVtZza.mjs} +1 -2
  5. package/dist/_chunks/{SlugInput-DvQWzpBu.js → SlugInput-eCwgqJtH.js} +3 -4
  6. package/dist/_chunks/{en-CGJcJfk1.js → en-D89cXiov.js} +46 -1
  7. package/dist/_chunks/{en-CRSiVe4w.mjs → en-knG97mCH.mjs} +46 -1
  8. package/dist/_chunks/{index-C3MUddO-.mjs → index-97f0S4q6.mjs} +2270 -73
  9. package/dist/_chunks/{index-UZTUyNY3.js → index-DnXsi_Ar.js} +2292 -78
  10. package/dist/admin/index.js +1 -1
  11. package/dist/admin/index.mjs +2 -2
  12. package/dist/admin/src/components/DocumentTranslateBox.d.ts +5 -0
  13. package/dist/admin/src/components/DocumentTranslateModal.d.ts +11 -0
  14. package/dist/admin/src/components/TranslationAiModal.d.ts +8 -0
  15. package/dist/admin/src/components/TranslationSettingsModal.d.ts +6 -0
  16. package/dist/admin/src/contexts/settings.d.ts +1 -0
  17. package/dist/admin/src/core/config.d.ts +1 -0
  18. package/dist/admin/src/core/gateways/aiGateway.d.ts +19 -0
  19. package/dist/admin/src/core/gateways/documentGateway.d.ts +15 -0
  20. package/dist/admin/src/core/gateways/translationGateway.d.ts +13 -0
  21. package/dist/admin/src/core/usecases/translateDocument.d.ts +33 -0
  22. package/dist/admin/src/core/usecases/translateWithAi.d.ts +17 -0
  23. package/dist/admin/src/core/utils/documentFields.d.ts +23 -0
  24. package/dist/admin/src/core/utils/tabs.d.ts +53 -0
  25. package/dist/admin/src/ctb/TabSelect.d.ts +31 -0
  26. package/dist/admin/src/ctb/TabsEditor.d.ts +21 -0
  27. package/dist/admin/src/ctb/registerTabsInContentTypeBuilder.d.ts +1 -0
  28. package/dist/admin/src/ctb/tabBadges.d.ts +14 -0
  29. package/dist/admin/src/editView/TabSection.d.ts +6 -0
  30. package/dist/admin/src/editView/TabsBar.d.ts +10 -0
  31. package/dist/admin/src/editView/mutateEditViewLayout.d.ts +12 -0
  32. package/dist/admin/src/editView/sectionVisibility.d.ts +7 -0
  33. package/dist/admin/src/editView/tabsStore.d.ts +13 -0
  34. package/dist/server/index.js +812 -392
  35. package/dist/server/index.mjs +812 -392
  36. package/dist/server/src/config/index.d.ts +4 -0
  37. package/dist/server/src/controllers/index.d.ts +6 -0
  38. package/dist/server/src/controllers/modules/ai-translation.d.ts +7 -0
  39. package/dist/server/src/controllers/modules/translation.d.ts +1 -0
  40. package/dist/server/src/index.d.ts +22 -1
  41. package/dist/server/src/middlewares/tabs.d.ts +4 -0
  42. package/dist/server/src/services/app/setting.d.ts +3 -1
  43. package/dist/server/src/services/index.d.ts +16 -1
  44. package/dist/server/src/services/modules/ai-translation.d.ts +35 -0
  45. package/dist/server/src/utils/groupByContentTypeTabs.d.ts +7 -0
  46. package/dist/server/src/utils/tabs.d.ts +17 -0
  47. package/package.json +6 -3
  48. package/dist/_chunks/convertToSlug-DmgViUjP.mjs +0 -84
  49. package/dist/_chunks/convertToSlug-DqHa9ej4.js +0 -83
@@ -2,12 +2,11 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { useNavigate, useParams, Routes, Route } from "react-router-dom";
3
3
  import React__default, { useState, useEffect, createContext, useContext, Fragment as Fragment$1, useRef } from "react";
4
4
  import { Box, Loader, Main, Typography, Button, Flex, Breadcrumbs, Crumb, CrumbLink, CardBody, CardContent, CardTitle, CardBadge, CardSubtitle, Card as Card$1, Dialog, IconButton, Toggle, SingleSelect, SingleSelectOption, SearchForm, Searchbar, Table, Thead, Tr, Th, Checkbox, VisuallyHidden, Tbody, Td, EmptyStateLayout, TextInput, Field, Tooltip } from "@strapi/design-system";
5
- import { R as Registry, F as FetchSettings, g as getTranslation, c as config, S as SLUG_LANGUAGE_STRATEGY, a as SLUG_CONTENT_STRATEGY, b as FetchSlugs, f as fetchTemplates } from "./index-C3MUddO-.mjs";
6
- import { ArrowLeft, ExternalLink, WarningCircle, Cross, BulletList, Pencil, Trash, Plus, Duplicate, Drag, Check } from "@strapi/icons";
5
+ import { R as Registry, F as FetchSettings, g as getTranslation, c as config, S as SLUG_LANGUAGE_STRATEGY, a as SLUG_CONTENT_STRATEGY, b as FetchSlugs, d as FetchLocales, e as convertToSlug, A as AI_TRANSLATION_DEFAULT_MODEL, f as fetchTemplates } from "./index-97f0S4q6.mjs";
6
+ import { ArrowLeft, ExternalLink, WarningCircle, Cross, BulletList, Pencil, Trash, Plus, Duplicate, Drag, Check, Sparkle } from "@strapi/icons";
7
7
  import { useIntl } from "react-intl";
8
8
  import styled, { useTheme } from "styled-components";
9
9
  import { EmptyDocuments } from "@strapi/icons/symbols";
10
- import { F as FetchLocales, c as convertToSlug } from "./convertToSlug-DmgViUjP.mjs";
11
10
  import { DndContext, DragOverlay, pointerWithin, rectIntersection } from "@dnd-kit/core";
12
11
  import { useSortable, SortableContext, verticalListSortingStrategy, arrayMove } from "@dnd-kit/sortable";
13
12
  import { restrictToVerticalAxis, restrictToParentElement } from "@dnd-kit/modifiers";
@@ -53,7 +52,8 @@ function SettingsProvider({ children }) {
53
52
  SettingsContext.Provider,
54
53
  {
55
54
  value: {
56
- provide
55
+ provide,
56
+ refresh: fetch
57
57
  },
58
58
  children: [
59
59
  !fetchInProgress && children,
@@ -717,7 +717,7 @@ const HomePage = () => {
717
717
  style: { marginRight: "10px" },
718
718
  endIcon: /* @__PURE__ */ jsx(ExternalLink, {}),
719
719
  onClick: () => window.open("https://www.npmjs.com/package/@littlebox/strapi-suite", "_blank"),
720
- children: "v1.0.51"
720
+ children: "v1.0.54"
721
721
  }
722
722
  ),
723
723
  /* @__PURE__ */ jsx(
@@ -936,7 +936,7 @@ const ConfirmModal = ({ open, title, text, confirm, cancel }) => {
936
936
  ] }) }) })
937
937
  ] }) }) });
938
938
  };
939
- const BoxInput$7 = styled(Box)`
939
+ const BoxInput$9 = styled(Box)`
940
940
  & > div {
941
941
  width: 100%;
942
942
  }
@@ -1044,7 +1044,7 @@ const SlugSettingsModal = ({ open, close, defaultLocale }) => {
1044
1044
  })
1045
1045
  }
1046
1046
  ),
1047
- /* @__PURE__ */ jsx(BoxInput$7, { style: { flex: 1, display: "flex", width: "100%" }, children: /* @__PURE__ */ jsx(
1047
+ /* @__PURE__ */ jsx(BoxInput$9, { style: { flex: 1, display: "flex", width: "100%" }, children: /* @__PURE__ */ jsx(
1048
1048
  SingleSelect,
1049
1049
  {
1050
1050
  onChange: (value) => handleChangeSelectedContent(value),
@@ -1058,7 +1058,7 @@ const SlugSettingsModal = ({ open, close, defaultLocale }) => {
1058
1058
  ),
1059
1059
  defaultMessage: "Home page slug strategy"
1060
1060
  }) }),
1061
- /* @__PURE__ */ jsx(BoxInput$7, { style: { flex: 1, display: "flex", width: "100%" }, children: /* @__PURE__ */ jsxs(
1061
+ /* @__PURE__ */ jsx(BoxInput$9, { style: { flex: 1, display: "flex", width: "100%" }, children: /* @__PURE__ */ jsxs(
1062
1062
  SingleSelect,
1063
1063
  {
1064
1064
  onChange: (value) => setSelectedStrategy(value),
@@ -1923,7 +1923,7 @@ let CreateMenu$1 = class CreateMenu {
1923
1923
  await this.menuGateway.create(params);
1924
1924
  }
1925
1925
  };
1926
- const BoxInput$6 = styled(Box)`
1926
+ const BoxInput$8 = styled(Box)`
1927
1927
  & > div {
1928
1928
  width: 100%;
1929
1929
  }
@@ -1986,7 +1986,7 @@ const MenuCreateModal = ({ open, close, locale, currentRecords }) => {
1986
1986
  id: getTranslation(`module.${module}.modal.create.input.title`),
1987
1987
  defaultMessage: "Title"
1988
1988
  }) }),
1989
- /* @__PURE__ */ jsxs(BoxInput$6, { style: { flex: 1, display: "flex", width: "100%", marginRight: "10px" }, children: [
1989
+ /* @__PURE__ */ jsxs(BoxInput$8, { style: { flex: 1, display: "flex", width: "100%", marginRight: "10px" }, children: [
1990
1990
  /* @__PURE__ */ jsx(
1991
1991
  TextInput,
1992
1992
  {
@@ -2019,7 +2019,7 @@ const MenuCreateModal = ({ open, close, locale, currentRecords }) => {
2019
2019
  }
2020
2020
  ),
2021
2021
  /* @__PURE__ */ jsxs(
2022
- BoxInput$6,
2022
+ BoxInput$8,
2023
2023
  {
2024
2024
  style: {
2025
2025
  flex: 1,
@@ -2087,7 +2087,7 @@ class DuplicateMenu {
2087
2087
  await this.menuGateway.duplicate(documentId, locale);
2088
2088
  }
2089
2089
  }
2090
- const BoxInput$5 = styled(Box)`
2090
+ const BoxInput$7 = styled(Box)`
2091
2091
  & > div {
2092
2092
  width: 100%;
2093
2093
  }
@@ -2134,7 +2134,7 @@ const MenuDuplicateModal = ({ open, close, documentId, locales }) => {
2134
2134
  id: getTranslation(`module.${module}.duplicate.input.title`),
2135
2135
  defaultMessage: "Select language"
2136
2136
  }) }),
2137
- /* @__PURE__ */ jsx(BoxInput$5, { style: { flex: 1, display: "flex", width: "100%", marginRight: "10px" }, children: /* @__PURE__ */ jsx(
2137
+ /* @__PURE__ */ jsx(BoxInput$7, { style: { flex: 1, display: "flex", width: "100%", marginRight: "10px" }, children: /* @__PURE__ */ jsx(
2138
2138
  SingleSelect,
2139
2139
  {
2140
2140
  onChange: (value) => setSelectedLocale(value),
@@ -2841,7 +2841,7 @@ const TabBodyContainer = ({ value, children }) => {
2841
2841
  Tab.Header = TabHeaderContainer;
2842
2842
  Tab.Item = TabItemContainer;
2843
2843
  Tab.Body = TabBodyContainer;
2844
- const BoxInput$4 = styled(Box)`
2844
+ const BoxInput$6 = styled(Box)`
2845
2845
  & > div {
2846
2846
  width: 100%;
2847
2847
  }
@@ -2963,7 +2963,7 @@ function MenuEditItem(props) {
2963
2963
  id: getTranslation(`module.${module}.edit.input.title`),
2964
2964
  defaultMessage: "Title"
2965
2965
  }) }) }),
2966
- /* @__PURE__ */ jsxs(BoxInput$4, { style: { flex: 1, display: "flex", width: "100%" }, children: [
2966
+ /* @__PURE__ */ jsxs(BoxInput$6, { style: { flex: 1, display: "flex", width: "100%" }, children: [
2967
2967
  /* @__PURE__ */ jsx(
2968
2968
  TextInput,
2969
2969
  {
@@ -2984,7 +2984,7 @@ function MenuEditItem(props) {
2984
2984
  id: getTranslation(`module.${module}.edit.input.url`),
2985
2985
  defaultMessage: "Url"
2986
2986
  }) }) }),
2987
- /* @__PURE__ */ jsxs(BoxInput$4, { style: { flex: 1, display: "flex", width: "100%" }, children: [
2987
+ /* @__PURE__ */ jsxs(BoxInput$6, { style: { flex: 1, display: "flex", width: "100%" }, children: [
2988
2988
  /* @__PURE__ */ jsx(
2989
2989
  TextInput,
2990
2990
  {
@@ -3011,7 +3011,7 @@ function MenuEditItem(props) {
3011
3011
  defaultMessage: "Content"
3012
3012
  }) }) }),
3013
3013
  /* @__PURE__ */ jsxs(
3014
- BoxInput$4,
3014
+ BoxInput$6,
3015
3015
  {
3016
3016
  style: { flex: 1, display: "flex", flexDirection: "column", width: "100%" },
3017
3017
  children: [
@@ -3053,7 +3053,7 @@ function MenuEditItem(props) {
3053
3053
  id: getTranslation(`module.${module}.edit.input.target`),
3054
3054
  defaultMessage: "Target"
3055
3055
  }) }) }),
3056
- /* @__PURE__ */ jsx(BoxInput$4, { style: { flex: 1, display: "flex", width: "100%" }, children: /* @__PURE__ */ jsxs(
3056
+ /* @__PURE__ */ jsx(BoxInput$6, { style: { flex: 1, display: "flex", width: "100%" }, children: /* @__PURE__ */ jsxs(
3057
3057
  SingleSelect,
3058
3058
  {
3059
3059
  onChange: (value) => {
@@ -3256,7 +3256,7 @@ function MenuEditItem(props) {
3256
3256
  }
3257
3257
  ) });
3258
3258
  }
3259
- const BoxInput$3 = styled(Box)`
3259
+ const BoxInput$5 = styled(Box)`
3260
3260
  & > div {
3261
3261
  width: 100%;
3262
3262
  }
@@ -3460,7 +3460,7 @@ function MenuDragDrop(props) {
3460
3460
  id: getTranslation(`module.${module}.edit.input.title`),
3461
3461
  defaultMessage: "Title"
3462
3462
  }) }) }),
3463
- /* @__PURE__ */ jsxs(BoxInput$3, { style: { flex: 1, display: "flex", width: "100%", marginRight: "10px" }, children: [
3463
+ /* @__PURE__ */ jsxs(BoxInput$5, { style: { flex: 1, display: "flex", width: "100%", marginRight: "10px" }, children: [
3464
3464
  /* @__PURE__ */ jsx(
3465
3465
  TextInput,
3466
3466
  {
@@ -3493,7 +3493,7 @@ function MenuDragDrop(props) {
3493
3493
  defaultMessage: "UID"
3494
3494
  }) }) }),
3495
3495
  /* @__PURE__ */ jsxs(
3496
- BoxInput$3,
3496
+ BoxInput$5,
3497
3497
  {
3498
3498
  style: {
3499
3499
  flex: 1,
@@ -3794,7 +3794,7 @@ let EditParameter$1 = class EditParameter {
3794
3794
  await this.parameterGateway.edit(documentId, params);
3795
3795
  }
3796
3796
  };
3797
- const BoxInput$2 = styled(Box)`
3797
+ const BoxInput$4 = styled(Box)`
3798
3798
  & > div {
3799
3799
  width: 100%;
3800
3800
  }
@@ -3888,7 +3888,7 @@ const ParameterHandleDataModal = ({ open, close, data, currentRecords }) => {
3888
3888
  }
3889
3889
  ),
3890
3890
  /* @__PURE__ */ jsxs(
3891
- BoxInput$2,
3891
+ BoxInput$4,
3892
3892
  {
3893
3893
  style: {
3894
3894
  flex: 1,
@@ -3931,7 +3931,7 @@ const ParameterHandleDataModal = ({ open, close, data, currentRecords }) => {
3931
3931
  defaultMessage: "Value"
3932
3932
  }) }) }),
3933
3933
  /* @__PURE__ */ jsxs(
3934
- BoxInput$2,
3934
+ BoxInput$4,
3935
3935
  {
3936
3936
  style: {
3937
3937
  flex: 1,
@@ -3964,7 +3964,7 @@ const ParameterHandleDataModal = ({ open, close, data, currentRecords }) => {
3964
3964
  defaultMessage: "Private"
3965
3965
  }) }) }),
3966
3966
  /* @__PURE__ */ jsx(
3967
- BoxInput$2,
3967
+ BoxInput$4,
3968
3968
  {
3969
3969
  style: {
3970
3970
  flex: 1,
@@ -4370,7 +4370,7 @@ class EditParameter2 {
4370
4370
  await this.translationGateway.edit(uid, params);
4371
4371
  }
4372
4372
  }
4373
- const BoxInput$1 = styled(Box)`
4373
+ const BoxInput$3 = styled(Box)`
4374
4374
  flex: 1;
4375
4375
  display: flex;
4376
4376
  width: 100%;
@@ -4481,7 +4481,7 @@ const TranslationHandleDataModal = ({
4481
4481
  })
4482
4482
  }
4483
4483
  ),
4484
- /* @__PURE__ */ jsxs(BoxInput$1, { children: [
4484
+ /* @__PURE__ */ jsxs(BoxInput$3, { children: [
4485
4485
  /* @__PURE__ */ jsx(
4486
4486
  TextInput,
4487
4487
  {
@@ -4547,7 +4547,7 @@ const TranslationHandleDataModal = ({
4547
4547
  children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: key })
4548
4548
  }
4549
4549
  ),
4550
- /* @__PURE__ */ jsxs(BoxInput$1, { children: [
4550
+ /* @__PURE__ */ jsxs(BoxInput$3, { children: [
4551
4551
  /* @__PURE__ */ jsx(
4552
4552
  TextInput,
4553
4553
  {
@@ -4591,6 +4591,487 @@ const TranslationHandleDataModal = ({
4591
4591
  ] })
4592
4592
  ] }) }) });
4593
4593
  };
4594
+ const BoxInput$2 = styled(Box)`
4595
+ flex: 1;
4596
+ display: flex;
4597
+ width: 100%;
4598
+ flex-direction: column;
4599
+ & > div {
4600
+ width: 100%;
4601
+ }
4602
+ `;
4603
+ const TranslationSettingsModal = ({ open, close }) => {
4604
+ const [module] = useState(config.uuid.modules.translation);
4605
+ const [hidden, setHidden] = useState(true);
4606
+ const [aiEnabled, setAiEnabled] = useState(false);
4607
+ const [aiApiKey, setAiApiKey] = useState("");
4608
+ const [aiModel, setAiModel] = useState(AI_TRANSLATION_DEFAULT_MODEL);
4609
+ const [storedApiKey, setStoredApiKey] = useState("");
4610
+ const [saveInProgress, setSaveInProgress] = useState(false);
4611
+ const { formatMessage } = useIntl();
4612
+ const settings = useSettings();
4613
+ async function updateSetting(property, value) {
4614
+ const updateSetting2 = new UpdateSetting();
4615
+ await updateSetting2.execute({ property, module, value });
4616
+ }
4617
+ async function save() {
4618
+ if (saveInProgress) return;
4619
+ setSaveInProgress(true);
4620
+ await updateSetting("aiEnabled", aiEnabled);
4621
+ await updateSetting("aiModel", aiModel.trim() || AI_TRANSLATION_DEFAULT_MODEL);
4622
+ if (aiApiKey.trim().length > 0) {
4623
+ await updateSetting("aiApiKey", aiApiKey.trim());
4624
+ }
4625
+ await settings.refresh();
4626
+ setAiApiKey("");
4627
+ setSaveInProgress(false);
4628
+ close();
4629
+ }
4630
+ useEffect(() => {
4631
+ if (!open) {
4632
+ setHidden(true);
4633
+ return;
4634
+ }
4635
+ const current = settings.provide(module);
4636
+ setAiEnabled(!!current.aiEnabled);
4637
+ setAiModel(current.aiModel || AI_TRANSLATION_DEFAULT_MODEL);
4638
+ setStoredApiKey(current.aiApiKey || "");
4639
+ setAiApiKey("");
4640
+ setHidden(false);
4641
+ }, [open]);
4642
+ return /* @__PURE__ */ jsx(Fragment, { children: !hidden && /* @__PURE__ */ jsx(Dialog.Root, { defaultOpen: true, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
4643
+ /* @__PURE__ */ jsx(Dialog.Header, { style: { textAlign: "left" }, children: /* @__PURE__ */ jsxs(Flex, { style: { width: "100%", justifyContent: "space-between" }, children: [
4644
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", children: formatMessage({
4645
+ id: getTranslation(`module.${module}.modal.settings.title`),
4646
+ defaultMessage: "Settings"
4647
+ }) }),
4648
+ !saveInProgress && /* @__PURE__ */ jsx(IconButton, { variant: "tertiary", onClick: close, label: "Close", borderWidth: 0, children: /* @__PURE__ */ jsx(Cross, {}) })
4649
+ ] }) }),
4650
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Box, { style: { display: "flex", flexDirection: "column", width: "100%" }, children: [
4651
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px" }, children: formatMessage({
4652
+ id: getTranslation(`module.${module}.modal.settings.input.ai-enabled.title`),
4653
+ defaultMessage: "Translate with artificial intelligence"
4654
+ }) }),
4655
+ /* @__PURE__ */ jsx(
4656
+ Typography,
4657
+ {
4658
+ variant: "pi",
4659
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
4660
+ children: formatMessage({
4661
+ id: getTranslation(
4662
+ `module.${module}.modal.settings.input.ai-enabled.description`
4663
+ ),
4664
+ defaultMessage: "Enable the OpenAI powered translation of the entries of this module"
4665
+ })
4666
+ }
4667
+ ),
4668
+ /* @__PURE__ */ jsx(
4669
+ Toggle,
4670
+ {
4671
+ onLabel: "True",
4672
+ offLabel: "False",
4673
+ checked: aiEnabled,
4674
+ onChange: (e) => setAiEnabled(e.target.checked)
4675
+ }
4676
+ ),
4677
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px", paddingTop: "24px" }, children: formatMessage({
4678
+ id: getTranslation(`module.${module}.modal.settings.input.ai-api-key.title`),
4679
+ defaultMessage: "OpenAI API key"
4680
+ }) }),
4681
+ /* @__PURE__ */ jsx(
4682
+ Typography,
4683
+ {
4684
+ variant: "pi",
4685
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
4686
+ children: formatMessage({
4687
+ id: getTranslation(
4688
+ `module.${module}.modal.settings.input.ai-api-key.description`
4689
+ ),
4690
+ defaultMessage: "The key is stored on the server and is never shown again. Leave it empty to keep the current one"
4691
+ })
4692
+ }
4693
+ ),
4694
+ /* @__PURE__ */ jsxs(BoxInput$2, { children: [
4695
+ /* @__PURE__ */ jsx(
4696
+ TextInput,
4697
+ {
4698
+ type: "password",
4699
+ style: { width: "100%" },
4700
+ autoComplete: "new-password",
4701
+ "aria-label": formatMessage({
4702
+ id: getTranslation(`module.${module}.modal.settings.input.ai-api-key.title`),
4703
+ defaultMessage: "OpenAI API key"
4704
+ }),
4705
+ placeholder: storedApiKey || formatMessage({
4706
+ id: getTranslation(
4707
+ `module.${module}.modal.settings.input.ai-api-key.placeholder`
4708
+ ),
4709
+ defaultMessage: "No API key set"
4710
+ }),
4711
+ value: aiApiKey,
4712
+ onChange: (e) => setAiApiKey(e.target.value)
4713
+ }
4714
+ ),
4715
+ /* @__PURE__ */ jsx(Field.Hint, {}),
4716
+ /* @__PURE__ */ jsx(Field.Error, {})
4717
+ ] }),
4718
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px", paddingTop: "24px" }, children: formatMessage({
4719
+ id: getTranslation(`module.${module}.modal.settings.input.ai-model.title`),
4720
+ defaultMessage: "OpenAI model"
4721
+ }) }),
4722
+ /* @__PURE__ */ jsx(
4723
+ Typography,
4724
+ {
4725
+ variant: "pi",
4726
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
4727
+ children: formatMessage({
4728
+ id: getTranslation(`module.${module}.modal.settings.input.ai-model.description`),
4729
+ defaultMessage: "The model used to generate the translations"
4730
+ })
4731
+ }
4732
+ ),
4733
+ /* @__PURE__ */ jsxs(BoxInput$2, { children: [
4734
+ /* @__PURE__ */ jsx(
4735
+ TextInput,
4736
+ {
4737
+ style: { width: "100%" },
4738
+ "aria-label": formatMessage({
4739
+ id: getTranslation(`module.${module}.modal.settings.input.ai-model.title`),
4740
+ defaultMessage: "OpenAI model"
4741
+ }),
4742
+ placeholder: AI_TRANSLATION_DEFAULT_MODEL,
4743
+ value: aiModel,
4744
+ onChange: (e) => setAiModel(e.target.value)
4745
+ }
4746
+ ),
4747
+ /* @__PURE__ */ jsx(Field.Hint, {}),
4748
+ /* @__PURE__ */ jsx(Field.Error, {})
4749
+ ] }),
4750
+ /* @__PURE__ */ jsxs(
4751
+ Card$1,
4752
+ {
4753
+ shadow: false,
4754
+ style: {
4755
+ marginTop: "20px",
4756
+ padding: "10px",
4757
+ display: "flex",
4758
+ alignItems: "center"
4759
+ },
4760
+ children: [
4761
+ /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", fill: "none", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx(
4762
+ "path",
4763
+ {
4764
+ fill: "#7b79ff",
4765
+ d: "M12 0C5.383 0 0 5.383 0 12s5.383 12 12 12 12-5.383 12-12S18.617 0 12 0Zm1.154 18.456h-2.308V16.15h2.308v2.307Zm-.23-3.687h-1.847l-.346-9.23h2.538l-.346 9.23Z"
4766
+ }
4767
+ ) }),
4768
+ /* @__PURE__ */ jsx(
4769
+ Typography,
4770
+ {
4771
+ variant: "pi",
4772
+ style: { color: "#a5a5ba", display: "flex", marginLeft: "10px" },
4773
+ children: formatMessage({
4774
+ id: getTranslation(`module.${module}.modal.settings.hint`),
4775
+ defaultMessage: "Each translation is billed by OpenAI on the account that owns the API key"
4776
+ })
4777
+ }
4778
+ )
4779
+ ]
4780
+ }
4781
+ )
4782
+ ] }) }),
4783
+ /* @__PURE__ */ jsxs(Dialog.Footer, { style: { justifyContent: "end" }, children: [
4784
+ saveInProgress && /* @__PURE__ */ jsx(Loader, { small: true }),
4785
+ /* @__PURE__ */ jsx(Button, { style: { marginRight: "5px" }, onClick: save, disabled: saveInProgress, children: formatMessage({
4786
+ id: getTranslation(`module.${module}.modal.settings.button.save`),
4787
+ defaultMessage: "Save"
4788
+ }) })
4789
+ ] })
4790
+ ] }) }) });
4791
+ };
4792
+ class TranslateWithAi {
4793
+ translationGateway;
4794
+ constructor() {
4795
+ this.translationGateway = Registry.getInstance().inject("translationGateway");
4796
+ }
4797
+ async execute(input) {
4798
+ return await this.translationGateway.aiTranslate(input);
4799
+ }
4800
+ }
4801
+ const BoxInput$1 = styled(Box)`
4802
+ flex: 1;
4803
+ display: flex;
4804
+ width: 100%;
4805
+ flex-direction: column;
4806
+ & > div {
4807
+ width: 100%;
4808
+ }
4809
+ `;
4810
+ const TranslationAiModal = ({ open, locales, close }) => {
4811
+ const [module] = useState(config.uuid.modules.translation);
4812
+ const [hidden, setHidden] = useState(true);
4813
+ const [sourceLocale, setSourceLocale] = useState();
4814
+ const [targetLocales, setTargetLocales] = useState([]);
4815
+ const [overwrite, setOverwrite] = useState(false);
4816
+ const [translateInProgress, setTranslateInProgress] = useState(false);
4817
+ const [result, setResult] = useState();
4818
+ const [error, setError] = useState("");
4819
+ const { formatMessage } = useIntl();
4820
+ function changeSourceLocale(code) {
4821
+ setSourceLocale(code);
4822
+ setTargetLocales([]);
4823
+ setResult(void 0);
4824
+ setError("");
4825
+ }
4826
+ function toggleTargetLocale(code) {
4827
+ if (targetLocales.includes(code)) {
4828
+ setTargetLocales(targetLocales.filter((locale) => locale !== code));
4829
+ return;
4830
+ }
4831
+ setTargetLocales([...targetLocales, code]);
4832
+ }
4833
+ function selectAllTargetLocales() {
4834
+ const available = locales.filter((locale) => locale.code !== sourceLocale).map((locale) => locale.code);
4835
+ setTargetLocales(targetLocales.length === available.length ? [] : available);
4836
+ }
4837
+ async function translate() {
4838
+ if (translateInProgress || !sourceLocale || targetLocales.length === 0) return;
4839
+ setTranslateInProgress(true);
4840
+ setResult(void 0);
4841
+ setError("");
4842
+ try {
4843
+ const translateWithAi = new TranslateWithAi();
4844
+ const output = await translateWithAi.execute({ sourceLocale, targetLocales, overwrite });
4845
+ setResult(output);
4846
+ } catch (e) {
4847
+ setError(
4848
+ e?.response?.data?.error?.message || e?.message || formatMessage({
4849
+ id: getTranslation(`module.${module}.modal.ai.error`),
4850
+ defaultMessage: "The translation request failed"
4851
+ })
4852
+ );
4853
+ }
4854
+ setTranslateInProgress(false);
4855
+ }
4856
+ function handleClose() {
4857
+ if (translateInProgress) return;
4858
+ const refresh = !!result && result.translated > 0;
4859
+ setSourceLocale(void 0);
4860
+ setTargetLocales([]);
4861
+ setOverwrite(false);
4862
+ setResult(void 0);
4863
+ setError("");
4864
+ close(refresh);
4865
+ }
4866
+ useEffect(() => {
4867
+ if (!open) {
4868
+ setHidden(true);
4869
+ return;
4870
+ }
4871
+ const defaultLocale = locales.find((locale) => locale.isDefault);
4872
+ setSourceLocale(defaultLocale?.code);
4873
+ setTargetLocales([]);
4874
+ setOverwrite(false);
4875
+ setResult(void 0);
4876
+ setError("");
4877
+ setHidden(false);
4878
+ }, [open]);
4879
+ return /* @__PURE__ */ jsx(Fragment, { children: !hidden && /* @__PURE__ */ jsx(Dialog.Root, { defaultOpen: true, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
4880
+ /* @__PURE__ */ jsx(Dialog.Header, { style: { textAlign: "left" }, children: /* @__PURE__ */ jsxs(Flex, { style: { width: "100%", justifyContent: "space-between" }, children: [
4881
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", children: formatMessage({
4882
+ id: getTranslation(`module.${module}.modal.ai.title`),
4883
+ defaultMessage: "Translate with AI"
4884
+ }) }),
4885
+ !translateInProgress && /* @__PURE__ */ jsx(IconButton, { variant: "tertiary", onClick: handleClose, label: "Close", borderWidth: 0, children: /* @__PURE__ */ jsx(Cross, {}) })
4886
+ ] }) }),
4887
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Box, { style: { display: "flex", flexDirection: "column", width: "100%" }, children: [
4888
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px" }, children: formatMessage({
4889
+ id: getTranslation(`module.${module}.modal.ai.input.source.title`),
4890
+ defaultMessage: "Base language"
4891
+ }) }),
4892
+ /* @__PURE__ */ jsx(
4893
+ Typography,
4894
+ {
4895
+ variant: "pi",
4896
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
4897
+ children: formatMessage({
4898
+ id: getTranslation(`module.${module}.modal.ai.input.source.description`),
4899
+ defaultMessage: "The language the entries are translated from"
4900
+ })
4901
+ }
4902
+ ),
4903
+ /* @__PURE__ */ jsx(BoxInput$1, { children: /* @__PURE__ */ jsx(
4904
+ SingleSelect,
4905
+ {
4906
+ onChange: (value) => changeSourceLocale(value),
4907
+ value: sourceLocale,
4908
+ disabled: translateInProgress,
4909
+ children: locales.map((locale, index) => /* @__PURE__ */ jsx(SingleSelectOption, { value: locale.code, children: locale.name }, index))
4910
+ }
4911
+ ) }),
4912
+ sourceLocale && /* @__PURE__ */ jsxs(Fragment, { children: [
4913
+ /* @__PURE__ */ jsxs(
4914
+ Flex,
4915
+ {
4916
+ style: {
4917
+ justifyContent: "space-between",
4918
+ alignItems: "end",
4919
+ paddingTop: "24px",
4920
+ paddingBottom: "5px"
4921
+ },
4922
+ children: [
4923
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: formatMessage({
4924
+ id: getTranslation(`module.${module}.modal.ai.input.targets.title`),
4925
+ defaultMessage: "Languages to translate to"
4926
+ }) }),
4927
+ /* @__PURE__ */ jsx(
4928
+ Button,
4929
+ {
4930
+ variant: "tertiary",
4931
+ size: "S",
4932
+ onClick: selectAllTargetLocales,
4933
+ disabled: translateInProgress,
4934
+ children: formatMessage({
4935
+ id: getTranslation(`module.${module}.modal.ai.input.targets.select-all`),
4936
+ defaultMessage: "Select all"
4937
+ })
4938
+ }
4939
+ )
4940
+ ]
4941
+ }
4942
+ ),
4943
+ /* @__PURE__ */ jsx(Box, { style: { display: "flex", flexDirection: "column", gap: "10px" }, children: locales.filter((locale) => locale.code !== sourceLocale).map((locale) => /* @__PURE__ */ jsx(
4944
+ Checkbox,
4945
+ {
4946
+ checked: targetLocales.includes(locale.code),
4947
+ disabled: translateInProgress,
4948
+ onCheckedChange: () => toggleTargetLocale(locale.code),
4949
+ children: locale.name
4950
+ },
4951
+ locale.code
4952
+ )) }),
4953
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px", paddingTop: "24px" }, children: formatMessage({
4954
+ id: getTranslation(`module.${module}.modal.ai.input.overwrite.title`),
4955
+ defaultMessage: "Overwrite existing translations"
4956
+ }) }),
4957
+ /* @__PURE__ */ jsx(
4958
+ Typography,
4959
+ {
4960
+ variant: "pi",
4961
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
4962
+ children: formatMessage({
4963
+ id: getTranslation(`module.${module}.modal.ai.input.overwrite.description`),
4964
+ defaultMessage: "When disabled only the missing translations are generated"
4965
+ })
4966
+ }
4967
+ ),
4968
+ /* @__PURE__ */ jsx(
4969
+ Toggle,
4970
+ {
4971
+ onLabel: "True",
4972
+ offLabel: "False",
4973
+ checked: overwrite,
4974
+ disabled: translateInProgress,
4975
+ onChange: (e) => setOverwrite(e.target.checked)
4976
+ }
4977
+ )
4978
+ ] }),
4979
+ translateInProgress && /* @__PURE__ */ jsxs(
4980
+ Card$1,
4981
+ {
4982
+ shadow: false,
4983
+ style: {
4984
+ marginTop: "20px",
4985
+ padding: "10px",
4986
+ display: "flex",
4987
+ alignItems: "center"
4988
+ },
4989
+ children: [
4990
+ /* @__PURE__ */ jsx(Loader, { small: true }),
4991
+ /* @__PURE__ */ jsx(
4992
+ Typography,
4993
+ {
4994
+ variant: "pi",
4995
+ style: { color: "#a5a5ba", display: "flex", marginLeft: "10px" },
4996
+ children: formatMessage({
4997
+ id: getTranslation(`module.${module}.modal.ai.progress`),
4998
+ defaultMessage: "Translating. This can take a few minutes, please keep this window open"
4999
+ })
5000
+ }
5001
+ )
5002
+ ]
5003
+ }
5004
+ ),
5005
+ result && !translateInProgress && /* @__PURE__ */ jsxs(
5006
+ Card$1,
5007
+ {
5008
+ shadow: false,
5009
+ style: {
5010
+ marginTop: "20px",
5011
+ padding: "10px",
5012
+ display: "flex",
5013
+ flexDirection: "column",
5014
+ alignItems: "start",
5015
+ gap: "5px"
5016
+ },
5017
+ children: [
5018
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { display: "flex" }, children: formatMessage(
5019
+ {
5020
+ id: getTranslation(`module.${module}.modal.ai.result`),
5021
+ defaultMessage: "{translated} translated, {skipped} skipped, {failed} failed"
5022
+ },
5023
+ {
5024
+ translated: result.translated,
5025
+ skipped: result.skipped,
5026
+ failed: result.failed
5027
+ }
5028
+ ) }),
5029
+ result.errors.map((message, index) => /* @__PURE__ */ jsx(
5030
+ Typography,
5031
+ {
5032
+ variant: "pi",
5033
+ style: { color: "#ee5e52", display: "flex" },
5034
+ children: message
5035
+ },
5036
+ index
5037
+ ))
5038
+ ]
5039
+ }
5040
+ ),
5041
+ error && !translateInProgress && /* @__PURE__ */ jsx(
5042
+ Card$1,
5043
+ {
5044
+ shadow: false,
5045
+ style: {
5046
+ marginTop: "20px",
5047
+ padding: "10px",
5048
+ display: "flex",
5049
+ alignItems: "center"
5050
+ },
5051
+ children: /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "#ee5e52", display: "flex" }, children: error })
5052
+ }
5053
+ )
5054
+ ] }) }),
5055
+ /* @__PURE__ */ jsxs(Dialog.Footer, { style: { justifyContent: "end", gap: "5px" }, children: [
5056
+ /* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: handleClose, disabled: translateInProgress, children: formatMessage({
5057
+ id: getTranslation(`app.modal.confirm.button.cancel`),
5058
+ defaultMessage: "Cancel"
5059
+ }) }),
5060
+ /* @__PURE__ */ jsx(
5061
+ Button,
5062
+ {
5063
+ style: { marginRight: "5px" },
5064
+ onClick: translate,
5065
+ disabled: translateInProgress || !sourceLocale || targetLocales.length === 0,
5066
+ children: formatMessage({
5067
+ id: getTranslation(`module.${module}.modal.ai.button.translate`),
5068
+ defaultMessage: "Translate"
5069
+ })
5070
+ }
5071
+ )
5072
+ ] })
5073
+ ] }) }) });
5074
+ };
4594
5075
  const CustomCard = styled(Card$1)`
4595
5076
  min-width: 32px;
4596
5077
  height: 32px;
@@ -4611,6 +5092,8 @@ const TranslationSettingsPage = () => {
4611
5092
  const [selectedRecords, setSelectedRecords] = useState([]);
4612
5093
  const [selectedRecord, setSelectedRecord] = useState();
4613
5094
  const [showHandleDataModal, setShowHandleDataModal] = useState(false);
5095
+ const [showSettingsModal, setShowSettingsModal] = useState(false);
5096
+ const [showAiModal, setShowAiModal] = useState(false);
4614
5097
  const [searchTerm, setSearchTerm] = useState("");
4615
5098
  const { formatMessage } = useIntl();
4616
5099
  const settings = useSettings();
@@ -4747,6 +5230,31 @@ const TranslationSettingsPage = () => {
4747
5230
  children: formatMessage({ id: getTranslation("app.create-new-entry") })
4748
5231
  }
4749
5232
  ),
5233
+ settings.provide(module).aiEnabled && /* @__PURE__ */ jsx(
5234
+ Button,
5235
+ {
5236
+ variant: "secondary",
5237
+ size: "S",
5238
+ style: { marginRight: "10px" },
5239
+ startIcon: /* @__PURE__ */ jsx(Sparkle, {}),
5240
+ onClick: () => setShowAiModal(true),
5241
+ children: formatMessage({
5242
+ id: getTranslation(`module.${module}.button.translate-with-ai`),
5243
+ defaultMessage: "Translate with AI"
5244
+ })
5245
+ }
5246
+ ),
5247
+ /* @__PURE__ */ jsx(
5248
+ Button,
5249
+ {
5250
+ variant: "secondary",
5251
+ size: "S",
5252
+ style: { marginRight: "10px" },
5253
+ startIcon: /* @__PURE__ */ jsx(BulletList, {}),
5254
+ onClick: () => setShowSettingsModal(true),
5255
+ children: formatMessage({ id: getTranslation("app.settings") })
5256
+ }
5257
+ ),
4750
5258
  !settings.provide(module).active && /* @__PURE__ */ jsx(Button, { variant: "danger", size: "S", onClick: () => toggleState(true), children: formatMessage({ id: getTranslation("app.disabled") }) }),
4751
5259
  settings.provide(module).active && /* @__PURE__ */ jsx(Button, { size: "S", onClick: () => toggleState(false), children: formatMessage({ id: getTranslation("app.enabled") }) })
4752
5260
  ]
@@ -4955,6 +5463,20 @@ const TranslationSettingsPage = () => {
4955
5463
  }
4956
5464
  }
4957
5465
  ),
5466
+ /* @__PURE__ */ jsx(TranslationSettingsModal, { open: showSettingsModal, close: () => setShowSettingsModal(false) }),
5467
+ /* @__PURE__ */ jsx(
5468
+ TranslationAiModal,
5469
+ {
5470
+ open: showAiModal,
5471
+ locales: i18nLocales,
5472
+ close: (refresh) => {
5473
+ setShowAiModal(false);
5474
+ if (refresh) {
5475
+ fetchRecords();
5476
+ }
5477
+ }
5478
+ }
5479
+ ),
4958
5480
  /* @__PURE__ */ jsx(
4959
5481
  TranslationHandleDataModal,
4960
5482
  {