@parhelia/localization 0.4.13058 → 0.4.13170

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 (50) hide show
  1. package/LICENSE +1 -1
  2. package/dist/LocalizeItemCommand.d.ts.map +1 -1
  3. package/dist/LocalizeItemCommand.js +0 -1
  4. package/dist/LocalizeItemDialog.d.ts.map +1 -1
  5. package/dist/LocalizeItemDialog.js +3 -9
  6. package/dist/LocalizeItemUtils.d.ts +0 -1
  7. package/dist/LocalizeItemUtils.d.ts.map +1 -1
  8. package/dist/LocalizeItemUtils.js +24 -45
  9. package/dist/api/discovery.d.ts +3 -17
  10. package/dist/api/discovery.d.ts.map +1 -1
  11. package/dist/api/discovery.js +14 -35
  12. package/dist/hooks/useTranslationWizard.d.ts.map +1 -1
  13. package/dist/hooks/useTranslationWizard.js +2 -10
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +4 -6
  16. package/dist/services/translationService.d.ts +27 -43
  17. package/dist/services/translationService.d.ts.map +1 -1
  18. package/dist/services/translationService.js +32 -36
  19. package/dist/settings/TranslationServicesPanel.d.ts +4 -14
  20. package/dist/settings/TranslationServicesPanel.d.ts.map +1 -1
  21. package/dist/settings/TranslationServicesPanel.js +263 -186
  22. package/dist/setup/LocalizationSetupStep.d.ts.map +1 -1
  23. package/dist/setup/LocalizationSetupStep.js +33 -14
  24. package/dist/sidebar/TranslationSidebar.d.ts.map +1 -1
  25. package/dist/sidebar/TranslationSidebar.js +14 -35
  26. package/dist/steps/ItemSelectionTree.d.ts +2 -2
  27. package/dist/steps/ItemSelectionTree.d.ts.map +1 -1
  28. package/dist/steps/ItemSelectionTree.js +47 -132
  29. package/dist/steps/ProviderStep.d.ts.map +1 -1
  30. package/dist/steps/ProviderStep.js +42 -55
  31. package/dist/steps/ServiceLanguageSelectionStep.d.ts +1 -1
  32. package/dist/steps/ServiceLanguageSelectionStep.d.ts.map +1 -1
  33. package/dist/steps/ServiceLanguageSelectionStep.js +176 -127
  34. package/dist/steps/types.d.ts +3 -3
  35. package/dist/steps/types.d.ts.map +1 -1
  36. package/dist/translation-center/TranslationBatches.d.ts +0 -37
  37. package/dist/translation-center/TranslationBatches.d.ts.map +1 -1
  38. package/dist/translation-center/TranslationBatches.js +78 -214
  39. package/dist/types.d.ts +0 -1
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +3 -2
  42. package/dist/services/translationSettingsService.d.ts +0 -79
  43. package/dist/services/translationSettingsService.d.ts.map +0 -1
  44. package/dist/services/translationSettingsService.js +0 -68
  45. package/dist/settings/ExcludedContentTypeDialog.d.ts +0 -12
  46. package/dist/settings/ExcludedContentTypeDialog.d.ts.map +0 -1
  47. package/dist/settings/ExcludedContentTypeDialog.js +0 -29
  48. package/dist/settings/TranslationProviderDialog.d.ts +0 -18
  49. package/dist/settings/TranslationProviderDialog.d.ts.map +0 -1
  50. package/dist/settings/TranslationProviderDialog.js +0 -105
package/dist/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { SettingsPanel } from "@parhelia/core";
2
2
  import { ReactNode } from "react";
3
3
  export type TranslationStatus = {
4
- store?: string | null;
5
4
  itemId: string;
6
5
  targetLanguage: string;
7
6
  sourceLanguage: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,SAAS,CAAC;QAChB,MAAM,EAAE,aAAa,EAAE,CAAC;KACzB,EAAE,CAAC;CACL,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,SAAS,CAAC;QAChB,MAAM,EAAE,aAAa,EAAE,CAAC;KACzB,EAAE,CAAC;CACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parhelia/localization",
3
- "version": "0.4.13058",
3
+ "version": "0.4.13170",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,7 +27,8 @@
27
27
  "build:native": "tsgo -p tsconfig.build.json",
28
28
  "lint": "eslint . --max-warnings 0",
29
29
  "check-types": "tsc --noEmit",
30
- "check-types:native": "tsgo --noEmit"
30
+ "check-types:native": "tsgo --noEmit",
31
+ "test": "vitest run"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@repo/eslint-config": "*",
@@ -1,79 +0,0 @@
1
- /**
2
- * The Settings "Translation Services" page (`/parhelia/translation-settings/*`, administrators only, every host and
3
- * every CMS): the translation providers with the fields their services declare, and the translation settings.
4
- */
5
- export type TranslationProviderFieldType = "text" | "multiline" | "number" | "checkbox" | "choice" | "modelReference" | "languages" | "secret";
6
- export interface TranslationFieldOption {
7
- value: string;
8
- label: string;
9
- }
10
- export interface TranslationProviderField {
11
- name: string;
12
- label: string;
13
- type: TranslationProviderFieldType;
14
- required: boolean;
15
- help?: string | null;
16
- defaultValue?: string | null;
17
- /** A choice field's options, the chat models, or the mounted languages. */
18
- options: TranslationFieldOption[];
19
- /** The stored value; null when none is stored, and always null for a secret. */
20
- value: string | null;
21
- /** For a secret: whether one is stored. */
22
- isSet?: boolean | null;
23
- }
24
- export interface TranslationProvider {
25
- serviceName: string;
26
- displayName: string;
27
- configured: boolean;
28
- fields: TranslationProviderField[];
29
- }
30
- export interface TranslationContentType {
31
- key: string;
32
- name: string;
33
- /** Whether a mounted store describes the key (an unknown one stays listed so it can be removed). */
34
- known: boolean;
35
- store?: string | null;
36
- }
37
- export interface TranslationSettingsValues {
38
- maxConcurrentTranslationJobs: number;
39
- /** 0 sets no limit per batch. */
40
- maxConcurrentJobsPerBatch: number;
41
- skipSharedFields: boolean;
42
- displayCosts: boolean;
43
- excludedContentTypes: TranslationContentType[];
44
- }
45
- export type TranslationSettingName = Exclude<keyof TranslationSettingsValues, never>;
46
- export interface TranslationSettingsPage {
47
- providers: TranslationProvider[];
48
- settings: TranslationSettingsValues;
49
- defaults: TranslationSettingsValues;
50
- /** The settings the customer set; the others follow the shipped defaults. */
51
- customized: TranslationSettingName[];
52
- languages: {
53
- code: string;
54
- name: string;
55
- }[];
56
- }
57
- /** What a settings save sets (a member left out is not touched). */
58
- export interface TranslationSettingsSet {
59
- maxConcurrentTranslationJobs?: number;
60
- maxConcurrentJobsPerBatch?: number;
61
- skipSharedFields?: boolean;
62
- displayCosts?: boolean;
63
- excludedContentTypes?: string[];
64
- }
65
- /** The answer with every list present (the server leaves out nulls). */
66
- export declare function normalizeTranslationSettings(value: Partial<TranslationSettingsPage> | null | undefined): TranslationSettingsPage;
67
- export declare const translationSettingsService: {
68
- get(): Promise<TranslationSettingsPage>;
69
- /**
70
- * Creates the service's settings when it has none and writes the values: a field left out keeps its value, `null`
71
- * clears it. An empty `values` only creates the settings.
72
- */
73
- saveProvider: (serviceName: string, values: Record<string, string | null>) => Promise<TranslationSettingsPage>;
74
- deleteProvider: (serviceName: string) => Promise<TranslationSettingsPage>;
75
- /** Sets values and resets settings to their shipped defaults (the customer's value is removed). */
76
- saveSettings: (set: TranslationSettingsSet, reset?: TranslationSettingName[]) => Promise<TranslationSettingsPage>;
77
- contentTypeOf(store: string, itemId: string): Promise<TranslationContentType>;
78
- };
79
- //# sourceMappingURL=translationSettingsService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"translationSettingsService.d.ts","sourceRoot":"","sources":["../../src/services/translationSettingsService.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,MAAM,MAAM,4BAA4B,GACpC,MAAM,GACN,WAAW,GACX,QAAQ,GACR,UAAU,GACV,QAAQ,GACR,gBAAgB,GAChB,WAAW,GACX,QAAQ,CAAC;AAEb,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,4BAA4B,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,2EAA2E;IAC3E,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAClC,gFAAgF;IAChF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,wBAAwB,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,yBAAyB;IACxC,4BAA4B,EAAE,MAAM,CAAC;IACrC,iCAAiC;IACjC,yBAAyB,EAAE,MAAM,CAAC;IAClC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,oBAAoB,EAAE,sBAAsB,EAAE,CAAC;CAChD;AAED,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,MAAM,yBAAyB,EAAE,KAAK,CAAC,CAAC;AAErF,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,QAAQ,EAAE,yBAAyB,CAAC;IACpC,QAAQ,EAAE,yBAAyB,CAAC;IACpC,6EAA6E;IAC7E,UAAU,EAAE,sBAAsB,EAAE,CAAC;IACrC,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC7C;AAED,oEAAoE;AACpE,MAAM,WAAW,sBAAsB;IACrC,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC;AAiBD,wEAAwE;AACxE,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,GAAG,SAAS,GACzD,uBAAuB,CAkBzB;AAiBD,eAAO,MAAM,0BAA0B;IAC/B,GAAG,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAO7C;;;OAGG;IACH,YAAY,gBAAgB,MAAM,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAOzE,cAAc,gBAAgB,MAAM;IAOpC,mGAAmG;IACnG,YAAY,QAAQ,sBAAsB,UAAS,sBAAsB,EAAE;IAOrE,aAAa,QAAQ,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;CASpF,CAAC"}
@@ -1,68 +0,0 @@
1
- import { get, post } from "@parhelia/core";
2
- const emptyValues = () => ({
3
- maxConcurrentTranslationJobs: 0,
4
- maxConcurrentJobsPerBatch: 0,
5
- skipSharedFields: false,
6
- displayCosts: false,
7
- excludedContentTypes: [],
8
- });
9
- /** The values with every list present; a type key counts as known only when the server says so. */
10
- const values = (value) => ({
11
- ...emptyValues(),
12
- ...(value ?? {}),
13
- excludedContentTypes: (value?.excludedContentTypes ?? []).map((type) => ({ ...type, known: type.known === true })),
14
- });
15
- /** The answer with every list present (the server leaves out nulls). */
16
- export function normalizeTranslationSettings(value) {
17
- return {
18
- providers: (value?.providers ?? []).map((provider) => ({
19
- serviceName: provider.serviceName ?? "",
20
- displayName: provider.displayName || provider.serviceName || "",
21
- configured: provider.configured === true,
22
- fields: (provider.fields ?? []).map((field) => ({
23
- ...field,
24
- required: field.required === true,
25
- options: field.options ?? [],
26
- value: field.value ?? null,
27
- })),
28
- })),
29
- settings: values(value?.settings),
30
- defaults: values(value?.defaults),
31
- customized: value?.customized ?? [],
32
- languages: value?.languages ?? [],
33
- };
34
- }
35
- /** The server's own words for a refused save (a named refusal answers `{ summary, reason }`). */
36
- function fail(result, fallback) {
37
- throw new Error(result.summary && result.summary !== "Error"
38
- ? result.summary
39
- : result.details || fallback);
40
- }
41
- async function save(url, body, fallback) {
42
- const result = await post(url, body);
43
- if (result.type !== "success" || !result.data)
44
- fail(result, fallback);
45
- return normalizeTranslationSettings(result.data.settings);
46
- }
47
- export const translationSettingsService = {
48
- async get() {
49
- const result = await get("/parhelia/translation-settings/index");
50
- if (result.type !== "success" || !result.data)
51
- fail(result, "Failed to load the translation settings");
52
- return normalizeTranslationSettings(result.data);
53
- },
54
- /**
55
- * Creates the service's settings when it has none and writes the values: a field left out keeps its value, `null`
56
- * clears it. An empty `values` only creates the settings.
57
- */
58
- saveProvider: (serviceName, values) => save("/parhelia/translation-settings/saveProvider", { serviceName, values }, "Failed to save the provider"),
59
- deleteProvider: (serviceName) => save("/parhelia/translation-settings/deleteProvider", { serviceName }, "Failed to delete the provider"),
60
- /** Sets values and resets settings to their shipped defaults (the customer's value is removed). */
61
- saveSettings: (set, reset = []) => save("/parhelia/translation-settings/saveSettings", { set, reset }, "Failed to save the translation settings"),
62
- async contentTypeOf(store, itemId) {
63
- const result = await post("/parhelia/translation-settings/contentTypeOf", { store, itemId });
64
- if (result.type !== "success" || !result.data)
65
- fail(result, "Failed to read the content type");
66
- return { ...result.data, known: true };
67
- },
68
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * Adds a content type to the types translation skips: the person picks the content store, then an item of that type in
3
- * the store's content tree (every CMS has items; not every CMS lists its types).
4
- */
5
- export declare function ExcludedContentTypeDialog({ open, saving, error, onOpenChange, onPick, }: {
6
- open: boolean;
7
- saving: boolean;
8
- error: string | null;
9
- onOpenChange: (open: boolean) => void;
10
- onPick: (store: string, itemId: string) => void;
11
- }): import("react").JSX.Element;
12
- //# sourceMappingURL=ExcludedContentTypeDialog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExcludedContentTypeDialog.d.ts","sourceRoot":"","sources":["../../src/settings/ExcludedContentTypeDialog.tsx"],"names":[],"mappings":"AAeA;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,IAAI,EACJ,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GACP,EAAE;IACD,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD,+BAuGA"}
@@ -1,29 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
3
- import { FolderTree, Loader2 } from "lucide-react";
4
- import { Button, ContentStoreSelect, ContentTree, Dialog, DialogContent, DialogFooter, FormField, StyledDialogTitle, settingsText, useContentModel, } from "@parhelia/core";
5
- /**
6
- * Adds a content type to the types translation skips: the person picks the content store, then an item of that type in
7
- * the store's content tree (every CMS has items; not every CMS lists its types).
8
- */
9
- export function ExcludedContentTypeDialog({ open, saving, error, onOpenChange, onPick, }) {
10
- const model = useContentModel();
11
- const stores = model?.stores ?? [];
12
- const [store, setStore] = useState("");
13
- const [itemId, setItemId] = useState("");
14
- useEffect(() => {
15
- if (!open)
16
- return;
17
- setItemId("");
18
- setStore((current) => current || (stores.length === 1 ? stores[0].id : ""));
19
- // eslint-disable-next-line react-hooks/exhaustive-deps
20
- }, [open]);
21
- const roots = model?.roots
22
- .filter((root) => root.storeId === store && root.kind === "content")
23
- .map((root) => root.id) ?? [];
24
- const language = stores.find((candidate) => candidate.id === store)?.defaultLocale ?? "en";
25
- return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "max-w-xl gap-0 p-0", "data-testid": "translation-excluded-type-dialog", children: [_jsx(StyledDialogTitle, { icon: _jsx(FolderTree, { strokeWidth: 1 }), title: "Exclude a content type", subtitle: "Pick an item: its content type, and every type based on it, is not translated." }), _jsxs("div", { className: "flex flex-col gap-4 px-8 py-6", children: [_jsx(FormField, { label: "Content store", children: _jsx(ContentStoreSelect, { value: store, onValueChange: (value) => {
26
- setStore(value);
27
- setItemId("");
28
- }, stores: stores, placeholder: "Select a content store", maxWidth: "100%", "data-testid": "translation-excluded-type-store" }) }), store && roots.length === 0 && (_jsx("p", { className: settingsText.help, children: "This store shows no content tree to pick from." })), store && roots.length > 0 && (_jsx("div", { className: "border-border-default h-72 overflow-auto rounded-md border", "data-testid": "translation-excluded-type-tree", children: _jsx(ContentTree, { database: store, language: language, rootItemIds: roots, hideRootNodes: false, selectionMode: "single", selectedItemIds: itemId ? [itemId] : [], onSelectionChange: (items) => setItemId(items[0]?.id ?? "") }, JSON.stringify([store, language])) })), error && (_jsx("p", { className: settingsText.error, role: "alert", "data-testid": "translation-excluded-type-error", children: error }))] }), _jsxs(DialogFooter, { className: "border-border-default gap-2 border-t pt-5 sm:gap-3", children: [_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: saving, children: "Cancel" }), _jsxs(Button, { onClick: () => onPick(store, itemId), disabled: saving || !store || !itemId, "data-testid": "translation-excluded-type-add", children: [saving && (_jsx(Loader2, { className: "h-4 w-4 animate-spin", strokeWidth: 1 })), "Add its content type"] })] })] }) }));
29
- }
@@ -1,18 +0,0 @@
1
- import type { TranslationProvider } from "../services/translationSettingsService";
2
- /** What the form holds per field: the text to save; a secret starts empty and is only sent when typed or removed. */
3
- type Draft = Record<string, string>;
4
- /**
5
- * The values a save sends: only fields that changed. A secret is sent when something was typed, or as `null` when the
6
- * person removed it; it is never read back, so an untouched secret is not sent.
7
- */
8
- export declare function providerChanges(provider: TranslationProvider, draft: Draft, removedSecrets: ReadonlySet<string>): Record<string, string | null>;
9
- /** Edits one translation provider's settings with the fields its service declares (on every host and CMS). */
10
- export declare function TranslationProviderDialog({ provider, saving, error, onOpenChange, onSave, }: {
11
- provider: TranslationProvider | null;
12
- saving: boolean;
13
- error: string | null;
14
- onOpenChange: (open: boolean) => void;
15
- onSave: (values: Record<string, string | null>) => void;
16
- }): import("react").JSX.Element;
17
- export {};
18
- //# sourceMappingURL=TranslationProviderDialog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TranslationProviderDialog.d.ts","sourceRoot":"","sources":["../../src/settings/TranslationProviderDialog.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,wCAAwC,CAAC;AAKhD,qHAAqH;AACrH,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAepC;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAc/B;AAkKD,8GAA8G;AAC9G,wBAAgB,yBAAyB,CAAC,EACxC,QAAQ,EACR,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;CACzD,+BA6GA"}
@@ -1,105 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useMemo, useState } from "react";
3
- import { Languages, Loader2 } from "lucide-react";
4
- import { Button, Checkbox, Dialog, DialogContent, DialogFooter, FormField, Input, Select, StyledDialogTitle, Textarea, cn, settingsText, } from "@parhelia/core";
5
- /** The select value of "no model chosen" (the provider then uses the default agent profile's model). */
6
- const NO_MODEL = "translation-provider-default-model";
7
- const splitList = (value) => (value ?? "")
8
- .split(/[|\r\n]+/)
9
- .map((entry) => entry.trim())
10
- .filter(Boolean);
11
- function initialDraft(provider) {
12
- const draft = {};
13
- for (const field of provider.fields)
14
- draft[field.name] = field.type === "secret" ? "" : (field.value ?? "");
15
- return draft;
16
- }
17
- /**
18
- * The values a save sends: only fields that changed. A secret is sent when something was typed, or as `null` when the
19
- * person removed it; it is never read back, so an untouched secret is not sent.
20
- */
21
- export function providerChanges(provider, draft, removedSecrets) {
22
- const changes = {};
23
- for (const field of provider.fields) {
24
- const text = draft[field.name] ?? "";
25
- if (field.type === "secret") {
26
- if (text.length > 0)
27
- changes[field.name] = text;
28
- else if (removedSecrets.has(field.name))
29
- changes[field.name] = null;
30
- continue;
31
- }
32
- const stored = field.value ?? "";
33
- if (text.replace(/\r\n/g, "\n") === stored.replace(/\r\n/g, "\n"))
34
- continue;
35
- changes[field.name] = text.trim().length === 0 ? null : text;
36
- }
37
- return changes;
38
- }
39
- function FieldInput({ field, value, secretState, onChange, onRemoveSecret, }) {
40
- const testId = `translation-provider-field-${field.name.replace(/\s+/g, "-").toLowerCase()}`;
41
- switch (field.type) {
42
- case "multiline":
43
- return (_jsx(Textarea, { value: value, onChange: (event) => onChange(event.target.value), rows: 5, placeholder: field.defaultValue ?? undefined, "data-testid": testId }));
44
- case "number":
45
- return (_jsx(Input, { type: "number", value: value, onChange: (event) => onChange(event.target.value), placeholder: field.defaultValue ?? undefined, "data-testid": testId }));
46
- case "checkbox":
47
- return (_jsx(Checkbox, { checked: value === "1", onCheckedChange: (checked) => onChange(checked === true ? "1" : ""), "data-testid": testId }));
48
- case "choice":
49
- return (_jsx(Select, { value: value, onValueChange: onChange, options: field.options.map((option) => ({
50
- value: option.value,
51
- label: option.label,
52
- })), placeholder: field.defaultValue ?? "Not set", maxWidth: "100%", "data-testid": testId }));
53
- case "modelReference":
54
- return (_jsx(Select, { value: value || NO_MODEL, onValueChange: (next) => onChange(next === NO_MODEL ? "" : next), options: [
55
- {
56
- value: NO_MODEL,
57
- label: "Default (the model of the default agent profile)",
58
- },
59
- ...field.options.map((option) => ({
60
- value: option.value,
61
- label: option.label,
62
- })),
63
- ], searchable: true, maxWidth: "100%", "data-testid": testId }));
64
- case "languages": {
65
- const selected = new Set(splitList(value).map((code) => code.toLowerCase()));
66
- const toggle = (code, on) => {
67
- const codes = field.options
68
- .map((option) => option.value)
69
- .filter((option) => option === code ? on : selected.has(option.toLowerCase()));
70
- onChange(codes.join("|"));
71
- };
72
- if (field.options.length === 0)
73
- return (_jsx("p", { className: settingsText.meta, children: "The mounted content has no languages." }));
74
- return (_jsx("div", { className: "grid gap-1.5 sm:grid-cols-2", "data-testid": testId, children: field.options.map((option) => (_jsxs("span", { className: cn("flex items-center gap-2", settingsText.body), children: [_jsx(Checkbox, { checked: selected.has(option.value.toLowerCase()), onCheckedChange: (checked) => toggle(option.value, checked === true), "aria-label": option.label, "data-testid": `${testId}-${option.value}` }), _jsx("span", { children: option.label }), option.label !== option.value && (_jsx("span", { className: cn("text-neutral-grey-50", settingsText.mono), children: option.value }))] }, option.value))) }));
75
- }
76
- case "secret":
77
- return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Input, { type: "password", autoComplete: "new-password", value: value, onChange: (event) => onChange(event.target.value), placeholder: secretState === "set"
78
- ? "Set. Type a new value to replace it."
79
- : "Not set", "data-testid": testId }), secretState === "set" && value.length === 0 && (_jsx(Button, { variant: "outline", size: "sm", onClick: onRemoveSecret, "data-testid": `${testId}-remove`, children: "Remove" }))] }));
80
- default:
81
- return (_jsx(Input, { value: value, onChange: (event) => onChange(event.target.value), placeholder: field.defaultValue ?? undefined, "data-testid": testId }));
82
- }
83
- }
84
- /** Edits one translation provider's settings with the fields its service declares (on every host and CMS). */
85
- export function TranslationProviderDialog({ provider, saving, error, onOpenChange, onSave, }) {
86
- // The panel keys this dialog by provider, so a fresh form starts from the provider it opens for.
87
- const [draft, setDraft] = useState(() => provider ? initialDraft(provider) : {});
88
- const [removedSecrets, setRemovedSecrets] = useState(() => new Set());
89
- const changes = useMemo(() => (provider ? providerChanges(provider, draft, removedSecrets) : {}), [provider, draft, removedSecrets]);
90
- const dirty = Object.keys(changes).length > 0;
91
- return (_jsx(Dialog, { open: provider !== null, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "max-w-2xl gap-0 p-0", "data-testid": "translation-provider-dialog", children: [_jsx(StyledDialogTitle, { icon: _jsx(Languages, { strokeWidth: 1 }), title: provider ? `Settings: ${provider.displayName}` : "Settings", subtitle: provider
92
- ? `Translation service "${provider.serviceName}".`
93
- : undefined }), _jsxs("div", { className: "flex max-h-[60vh] flex-col gap-4 overflow-auto px-8 py-6", children: [provider?.fields.map((field) => {
94
- const label = field.required ? `${field.label} *` : field.label;
95
- const input = (_jsx(FieldInput, { field: field, value: draft[field.name] ?? "", secretState: field.type !== "secret"
96
- ? "unset"
97
- : removedSecrets.has(field.name)
98
- ? "removed"
99
- : field.isSet
100
- ? "set"
101
- : "unset", onChange: (value) => setDraft((current) => ({ ...current, [field.name]: value })), onRemoveSecret: () => setRemovedSecrets((current) => new Set(current).add(field.name)) }));
102
- // A group of checkboxes is several controls: a <label> around it would send every click to the first one.
103
- return field.type === "languages" ? (_jsxs("fieldset", { className: "flex flex-col gap-1.5", children: [_jsx("legend", { className: cn("mb-1.5", settingsText.label), children: label }), input, field.help && (_jsx("p", { className: settingsText.help, children: field.help }))] }, field.name)) : (_jsx(FormField, { label: label, hint: field.help ?? undefined, children: input }, field.name));
104
- }), error && (_jsx("p", { className: settingsText.error, role: "alert", "data-testid": "translation-provider-error", children: error }))] }), _jsxs(DialogFooter, { className: "border-border-default gap-2 border-t pt-5 sm:gap-3", children: [_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: saving, children: "Cancel" }), _jsxs(Button, { onClick: () => onSave(changes), disabled: saving || !dirty, "data-testid": "translation-provider-save", children: [saving && (_jsx(Loader2, { className: "h-4 w-4 animate-spin", strokeWidth: 1 })), "Save"] })] })] }) }));
105
- }