@parhelia/localization 0.4.13170 → 0.4.13193
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.
- package/LICENSE +1 -1
- package/dist/LocalizeItemCommand.d.ts.map +1 -1
- package/dist/LocalizeItemCommand.js +1 -0
- package/dist/LocalizeItemDialog.d.ts.map +1 -1
- package/dist/LocalizeItemDialog.js +9 -3
- package/dist/LocalizeItemUtils.d.ts +1 -0
- package/dist/LocalizeItemUtils.d.ts.map +1 -1
- package/dist/LocalizeItemUtils.js +45 -24
- package/dist/api/discovery.d.ts +17 -3
- package/dist/api/discovery.d.ts.map +1 -1
- package/dist/api/discovery.js +35 -14
- package/dist/hooks/useTranslationWizard.d.ts.map +1 -1
- package/dist/hooks/useTranslationWizard.js +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/services/translationService.d.ts +44 -27
- package/dist/services/translationService.d.ts.map +1 -1
- package/dist/services/translationService.js +38 -32
- package/dist/services/translationSettingsService.d.ts +79 -0
- package/dist/services/translationSettingsService.d.ts.map +1 -0
- package/dist/services/translationSettingsService.js +68 -0
- package/dist/settings/ExcludedContentTypeDialog.d.ts +12 -0
- package/dist/settings/ExcludedContentTypeDialog.d.ts.map +1 -0
- package/dist/settings/ExcludedContentTypeDialog.js +29 -0
- package/dist/settings/TranslationProviderDialog.d.ts +18 -0
- package/dist/settings/TranslationProviderDialog.d.ts.map +1 -0
- package/dist/settings/TranslationProviderDialog.js +105 -0
- package/dist/settings/TranslationServicesPanel.d.ts +14 -4
- package/dist/settings/TranslationServicesPanel.d.ts.map +1 -1
- package/dist/settings/TranslationServicesPanel.js +186 -263
- package/dist/setup/LocalizationSetupStep.d.ts.map +1 -1
- package/dist/setup/LocalizationSetupStep.js +14 -33
- package/dist/sidebar/TranslationSidebar.d.ts.map +1 -1
- package/dist/sidebar/TranslationSidebar.js +35 -14
- package/dist/steps/ItemSelectionTree.d.ts +2 -2
- package/dist/steps/ItemSelectionTree.d.ts.map +1 -1
- package/dist/steps/ItemSelectionTree.js +132 -47
- package/dist/steps/ProviderStep.d.ts.map +1 -1
- package/dist/steps/ProviderStep.js +55 -42
- package/dist/steps/ServiceLanguageSelectionStep.d.ts +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.d.ts.map +1 -1
- package/dist/steps/ServiceLanguageSelectionStep.js +127 -176
- package/dist/steps/types.d.ts +3 -3
- package/dist/steps/types.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.d.ts +37 -0
- package/dist/translation-center/TranslationBatches.d.ts.map +1 -1
- package/dist/translation-center/TranslationBatches.js +255 -113
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationSidebar.d.ts","sourceRoot":"","sources":["../../src/sidebar/TranslationSidebar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TranslationSidebar.d.ts","sourceRoot":"","sources":["../../src/sidebar/TranslationSidebar.tsx"],"names":[],"mappings":"AAmBA,wBAAgB,kBAAkB,uCAwPjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, useEditContext, SimpleTable, confirmCreateVersion, Progress, } from "@parhelia/core";
|
|
2
|
+
import { Button, useEditContext, SimpleTable, confirmCreateVersion, Progress, LanguageIcon, } from "@parhelia/core";
|
|
3
3
|
import { getTranslationStatus } from "../services/translationService";
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
import { localizeItemCommand } from "../LocalizeItemCommand";
|
|
@@ -28,20 +28,33 @@ export function TranslationSidebar() {
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
const languageName = (language) => {
|
|
31
|
-
return (_jsxs("div", { className: "flex items-center gap-2 text-neutral-grey-100", children: [_jsx(
|
|
32
|
-
};
|
|
33
|
-
const loadTranslationStatus = async () => {
|
|
34
|
-
if (!item)
|
|
35
|
-
return;
|
|
36
|
-
const status = await getTranslationStatus(item.descriptor.id);
|
|
37
|
-
setTranslationStatus(status.data || []);
|
|
31
|
+
return (_jsxs("div", { className: "flex items-center gap-2 text-neutral-grey-100", children: [_jsx(LanguageIcon, { language: language, flagClassName: "h-[15px] w-5 shrink-0", globeClassName: "h-5 w-5" }), _jsx("span", { className: "font-normal", children: language.name })] }, language.languageCode));
|
|
38
32
|
};
|
|
33
|
+
// W12 phase 3 wave 15 (agentactor lane): keyed on the stable socket-listener registration and
|
|
34
|
+
// the item coordinate, not on the edit context (rebuilt on every revision, focus, selection,
|
|
35
|
+
// caret and socket message): each rebuild blanked the status table and the live progress bars
|
|
36
|
+
// and asked the server for the status again.
|
|
37
|
+
const addSocketMessageListener = editContext.addSocketMessageListener;
|
|
39
38
|
useEffect(() => {
|
|
40
|
-
|
|
39
|
+
let cancelled = false;
|
|
40
|
+
let request = 0;
|
|
41
|
+
const descriptor = item?.descriptor;
|
|
42
|
+
setTranslationStatus(null);
|
|
41
43
|
setTranslationProgress(new Map());
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
44
|
+
if (!descriptor?.database)
|
|
45
|
+
return;
|
|
46
|
+
const loadTranslationStatus = async () => {
|
|
47
|
+
const sequence = ++request;
|
|
48
|
+
const status = await getTranslationStatus(descriptor);
|
|
49
|
+
if (!cancelled && sequence === request)
|
|
50
|
+
setTranslationStatus((status.data || []).filter((row) => row.store === descriptor.database && row.itemId === descriptor.id));
|
|
51
|
+
};
|
|
52
|
+
void loadTranslationStatus();
|
|
53
|
+
const removeSocketMessageListener = addSocketMessageListener((message) => {
|
|
54
|
+
if (cancelled ||
|
|
55
|
+
message.payload?.store !== descriptor.database ||
|
|
56
|
+
message.payload?.itemId !== descriptor.id)
|
|
57
|
+
return;
|
|
45
58
|
if (message.type === "translation-started" ||
|
|
46
59
|
message.type === "translation-finished" ||
|
|
47
60
|
message.type === "translation-error") {
|
|
@@ -66,8 +79,16 @@ export function TranslationSidebar() {
|
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
});
|
|
69
|
-
return
|
|
70
|
-
|
|
82
|
+
return () => {
|
|
83
|
+
cancelled = true;
|
|
84
|
+
removeSocketMessageListener();
|
|
85
|
+
};
|
|
86
|
+
}, [
|
|
87
|
+
addSocketMessageListener,
|
|
88
|
+
item?.descriptor.database,
|
|
89
|
+
item?.descriptor.id,
|
|
90
|
+
item?.descriptor.language,
|
|
91
|
+
]);
|
|
71
92
|
const languageData = languages.map((x) => {
|
|
72
93
|
const progress = translationProgress.get(x.languageCode);
|
|
73
94
|
const status = translationStatus?.find((y) => y.targetLanguage === x.languageCode);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type EditContextType } from "@parhelia/core";
|
|
2
|
-
import type { TranslationWizardData } from "./types";
|
|
2
|
+
import type { TranslationStepProps, TranslationWizardData } from "./types";
|
|
3
3
|
type ItemSelectionTreeProps = {
|
|
4
4
|
data: TranslationWizardData;
|
|
5
|
-
setData:
|
|
5
|
+
setData: TranslationStepProps["setData"];
|
|
6
6
|
editContext: EditContextType;
|
|
7
7
|
isActive?: boolean;
|
|
8
8
|
onSelectionValidChange?: (valid: boolean) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemSelectionTree.d.ts","sourceRoot":"","sources":["../../src/steps/ItemSelectionTree.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"ItemSelectionTree.d.ts","sourceRoot":"","sources":["../../src/steps/ItemSelectionTree.tsx"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,eAAe,EAOrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAO3E,KAAK,sBAAsB,GAAG;IAC5B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACzC,WAAW,EAAE,eAAe,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B,CAAC;AAoFF,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,QAAe,EACf,sBAAsB,EACtB,MAAY,GACb,EAAE,sBAAsB,+BAqexB"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { ItemCollectionEditor, } from "@parhelia/core";
|
|
3
|
+
import { ContentStoreSelect, ItemCollectionEditor, getLanguages, useContentModel, } from "@parhelia/core";
|
|
4
4
|
import { streamSubitemCount } from "../api/discovery";
|
|
5
|
-
|
|
6
|
-
"0de95ae4-41ab-4d01-9eb0-67441b7c2450", // Content
|
|
7
|
-
"b701850a-cb8a-4943-b2bc-dddb1238c103", // Forms
|
|
8
|
-
"3d6658d8-a0bf-4e75-b3e2-d050fabcf4e1", // Media Library
|
|
9
|
-
];
|
|
5
|
+
import { translationDescriptorKey as itemKey, translationItem, } from "../services/translationService";
|
|
10
6
|
const NO_WRITE_ACCESS_TITLE = "You don't have write access to this item, so it can't be translated.";
|
|
11
7
|
/**
|
|
12
8
|
* Only items the user may write can receive a translation (the backend
|
|
@@ -22,6 +18,7 @@ function fullItemFromDescriptor(descriptor) {
|
|
|
22
18
|
language: descriptor.language,
|
|
23
19
|
version: descriptor.version,
|
|
24
20
|
descriptor: {
|
|
21
|
+
database: descriptor.database,
|
|
25
22
|
id: descriptor.id,
|
|
26
23
|
language: descriptor.language,
|
|
27
24
|
version: descriptor.version,
|
|
@@ -56,6 +53,7 @@ function fullItemFromDescriptor(descriptor) {
|
|
|
56
53
|
function fullItemToWithSubtree(item, includeSubitems) {
|
|
57
54
|
return {
|
|
58
55
|
descriptor: {
|
|
56
|
+
database: item.descriptor.database,
|
|
59
57
|
id: item.descriptor?.id ?? item.id,
|
|
60
58
|
language: item.descriptor?.language ?? item.language,
|
|
61
59
|
version: item.descriptor?.version ?? item.version,
|
|
@@ -69,9 +67,14 @@ function fullItemToWithSubtree(item, includeSubitems) {
|
|
|
69
67
|
};
|
|
70
68
|
}
|
|
71
69
|
export function ItemSelectionTree({ data, setData, editContext, isActive = true, onSelectionValidChange, height = 360, }) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const model = useContentModel();
|
|
71
|
+
const [store, setStore] = useState(editContext.currentItemDescriptor?.database ??
|
|
72
|
+
data.items[0]?.descriptor.database ??
|
|
73
|
+
"");
|
|
74
|
+
const preferredLanguage = data.sourceLanguage ||
|
|
75
|
+
editContext?.currentItemDescriptor?.language ||
|
|
76
|
+
data.items[0]?.descriptor.language ||
|
|
77
|
+
"";
|
|
75
78
|
// Seed selection: prefer previously saved tree items, then discoveredItems,
|
|
76
79
|
// then the wizard's initial `items`. Default includeSubitems = legacy flag.
|
|
77
80
|
const initialItems = useMemo(() => {
|
|
@@ -99,19 +102,17 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
99
102
|
const [subitemCounts, setSubitemCounts] = useState(() => data.subitemCounts ?? {});
|
|
100
103
|
// Mirror local subitemCounts into wizardData so later steps (e.g. the
|
|
101
104
|
// Start Translation button) can show a live total.
|
|
102
|
-
const dataRef = useRef(data);
|
|
103
|
-
dataRef.current = data;
|
|
104
105
|
useEffect(() => {
|
|
105
|
-
setData({ ...
|
|
106
|
+
setData((current) => ({ ...current, subitemCounts }));
|
|
106
107
|
}, [subitemCounts, setData]);
|
|
107
108
|
// Keep a cache of the richest FullItem we've ever seen for each id so we
|
|
108
109
|
// can rebuild discoveredItems without re-fetching.
|
|
109
110
|
const itemCacheRef = useRef(new Map());
|
|
110
111
|
if (itemCacheRef.current.size === 0) {
|
|
111
112
|
for (const it of data.items)
|
|
112
|
-
itemCacheRef.current.set(it.
|
|
113
|
+
itemCacheRef.current.set(itemKey(it.descriptor), it);
|
|
113
114
|
for (const it of data.discoveredItems || [])
|
|
114
|
-
itemCacheRef.current.set(it.
|
|
115
|
+
itemCacheRef.current.set(itemKey(it.descriptor), it);
|
|
115
116
|
}
|
|
116
117
|
// Build a combined idPath that expands every parent of the current
|
|
117
118
|
// selection (but not the items themselves). ContentTree's parser
|
|
@@ -119,7 +120,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
119
120
|
const expandIdPath = useMemo(() => {
|
|
120
121
|
const segments = [];
|
|
121
122
|
for (const entry of items) {
|
|
122
|
-
const cached = itemCacheRef.current.get(entry.descriptor
|
|
123
|
+
const cached = itemCacheRef.current.get(itemKey(entry.descriptor));
|
|
123
124
|
const idPath = cached?.idPath;
|
|
124
125
|
if (!idPath)
|
|
125
126
|
continue;
|
|
@@ -135,15 +136,70 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
135
136
|
}, [items]);
|
|
136
137
|
const commitToWizard = useCallback((nextItems) => {
|
|
137
138
|
const cache = itemCacheRef.current;
|
|
138
|
-
const discovered = nextItems.map((entry) => cache.get(entry.descriptor
|
|
139
|
+
const discovered = nextItems.map((entry) => cache.get(itemKey(entry.descriptor)) ??
|
|
139
140
|
fullItemFromDescriptor(entry.descriptor));
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
// A functional update: the Languages step writes the source language
|
|
142
|
+
// into the same wizard data.
|
|
143
|
+
setData((current) => ({
|
|
144
|
+
...current,
|
|
142
145
|
selectionTreeItems: nextItems,
|
|
143
146
|
discoveredItems: discovered,
|
|
144
147
|
includeSubitems: nextItems.some((i) => i.includeSubitems),
|
|
148
|
+
}));
|
|
149
|
+
}, [setData]);
|
|
150
|
+
// Only stores the user may write can receive a translation. With a single
|
|
151
|
+
// one there is nothing to choose: it is preselected and the picker hidden.
|
|
152
|
+
const writableStores = useMemo(() => (model?.stores ?? []).filter((candidate) => candidate.canWrite), [model?.stores]);
|
|
153
|
+
const onlyStore = writableStores.length === 1 ? writableStores[0] : undefined;
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (onlyStore && !store)
|
|
156
|
+
setStore(onlyStore.id);
|
|
157
|
+
}, [onlyStore, store]);
|
|
158
|
+
// The locales the chosen store declares. Null while loading (or with no
|
|
159
|
+
// store), so the preferred language is kept.
|
|
160
|
+
const [storeLanguages, setStoreLanguages] = useState(null);
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
setStoreLanguages(null);
|
|
163
|
+
if (!store)
|
|
164
|
+
return;
|
|
165
|
+
let cancelled = false;
|
|
166
|
+
getLanguages(store)
|
|
167
|
+
.then((res) => {
|
|
168
|
+
if (!cancelled)
|
|
169
|
+
setStoreLanguages(Array.isArray(res.data) ? res.data : []);
|
|
170
|
+
})
|
|
171
|
+
.catch((error) => {
|
|
172
|
+
console.error("Failed to load languages:", error);
|
|
173
|
+
if (!cancelled)
|
|
174
|
+
setStoreLanguages([]);
|
|
145
175
|
});
|
|
146
|
-
|
|
176
|
+
return () => {
|
|
177
|
+
cancelled = true;
|
|
178
|
+
};
|
|
179
|
+
}, [store]);
|
|
180
|
+
// The tree browses in the source language chosen in the Languages step,
|
|
181
|
+
// else the editor's language; a store that declares neither is browsed in
|
|
182
|
+
// its first language. An empty list is a failed read, not a store without
|
|
183
|
+
// languages.
|
|
184
|
+
const language = !storeLanguages?.length ||
|
|
185
|
+
storeLanguages.some((entry) => entry.languageCode === preferredLanguage)
|
|
186
|
+
? preferredLanguage
|
|
187
|
+
: storeLanguages[0].languageCode;
|
|
188
|
+
// The selected items carry the source language as their coordinate, so a
|
|
189
|
+
// new source relabels them (subitem discovery reads it from there too).
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!language)
|
|
192
|
+
return;
|
|
193
|
+
if (items.every((entry) => entry.descriptor.language === language))
|
|
194
|
+
return;
|
|
195
|
+
setSelectedInTree([]);
|
|
196
|
+
const next = items.map((entry) => ({
|
|
197
|
+
...entry,
|
|
198
|
+
descriptor: { ...entry.descriptor, language },
|
|
199
|
+
}));
|
|
200
|
+
setItems(next);
|
|
201
|
+
commitToWizard(next);
|
|
202
|
+
}, [language, items, commitToWizard]);
|
|
147
203
|
// Commit current state on first mount so wizard data reflects the seed.
|
|
148
204
|
const didInitialCommitRef = useRef(false);
|
|
149
205
|
useEffect(() => {
|
|
@@ -167,7 +223,9 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
167
223
|
const inFlightRef = useRef(new Map());
|
|
168
224
|
useEffect(() => {
|
|
169
225
|
const inFlight = inFlightRef.current;
|
|
170
|
-
const enabledIds = new Set(items
|
|
226
|
+
const enabledIds = new Set(items
|
|
227
|
+
.filter((it) => it.includeSubitems)
|
|
228
|
+
.map((it) => itemKey(it.descriptor)));
|
|
171
229
|
// Cancel any streams whose items no longer have the flag on.
|
|
172
230
|
for (const [id, ctrl] of inFlight) {
|
|
173
231
|
if (!enabledIds.has(id)) {
|
|
@@ -183,9 +241,9 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
183
241
|
.filter((it) => it.includeSubitems)
|
|
184
242
|
.map((it) => it.descriptor)
|
|
185
243
|
.filter((d) => {
|
|
186
|
-
if (inFlight.has(d
|
|
244
|
+
if (inFlight.has(itemKey(d)))
|
|
187
245
|
return false;
|
|
188
|
-
const c = subitemCounts[d
|
|
246
|
+
const c = subitemCounts[itemKey(d)];
|
|
189
247
|
if (c === undefined || c === "error")
|
|
190
248
|
return true;
|
|
191
249
|
if (c === "loading")
|
|
@@ -197,30 +255,37 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
197
255
|
setSubitemCounts((prev) => {
|
|
198
256
|
const next = { ...prev };
|
|
199
257
|
for (const d of toStart)
|
|
200
|
-
next[d
|
|
258
|
+
next[itemKey(d)] = "loading";
|
|
201
259
|
return next;
|
|
202
260
|
});
|
|
203
261
|
for (const descriptor of toStart) {
|
|
204
262
|
const controller = new AbortController();
|
|
205
|
-
|
|
263
|
+
const key = itemKey(descriptor);
|
|
264
|
+
inFlight.set(key, controller);
|
|
206
265
|
void (async () => {
|
|
207
266
|
try {
|
|
208
|
-
const finalCount = await streamSubitemCount({
|
|
267
|
+
const finalCount = await streamSubitemCount({ ...translationItem(descriptor), language: descriptor.language }, ({ count, complete, refusal }) => {
|
|
268
|
+
if (controller.signal.aborted)
|
|
269
|
+
return;
|
|
270
|
+
// multi-cms cfsmall (A15): the store's refusal on the last line travels with the count to the badge.
|
|
209
271
|
setSubitemCounts((prev) => ({
|
|
210
272
|
...prev,
|
|
211
|
-
[
|
|
273
|
+
[key]: refusal
|
|
274
|
+
? { count, complete, refusal }
|
|
275
|
+
: { count, complete },
|
|
212
276
|
}));
|
|
213
277
|
}, { sessionId, signal: controller.signal });
|
|
214
278
|
// Backend may close the stream without explicitly sending
|
|
215
279
|
// complete=true on the last line — mark complete on a clean exit.
|
|
280
|
+
if (controller.signal.aborted)
|
|
281
|
+
return;
|
|
216
282
|
setSubitemCounts((prev) => {
|
|
217
|
-
const existing = prev[
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
: finalCount;
|
|
283
|
+
const existing = prev[key];
|
|
284
|
+
if (existing && typeof existing === "object")
|
|
285
|
+
return { ...prev, [key]: { ...existing, complete: true } };
|
|
221
286
|
return {
|
|
222
287
|
...prev,
|
|
223
|
-
[
|
|
288
|
+
[key]: { count: finalCount, complete: true },
|
|
224
289
|
};
|
|
225
290
|
});
|
|
226
291
|
}
|
|
@@ -229,15 +294,15 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
229
294
|
return;
|
|
230
295
|
setSubitemCounts((prev) => {
|
|
231
296
|
// Don't overwrite a partial count with "error" — keep what we have.
|
|
232
|
-
const existing = prev[
|
|
297
|
+
const existing = prev[key];
|
|
233
298
|
if (existing && typeof existing === "object")
|
|
234
299
|
return prev;
|
|
235
|
-
return { ...prev, [
|
|
300
|
+
return { ...prev, [key]: "error" };
|
|
236
301
|
});
|
|
237
302
|
}
|
|
238
303
|
finally {
|
|
239
|
-
if (inFlight.get(
|
|
240
|
-
inFlight.delete(
|
|
304
|
+
if (inFlight.get(key) === controller) {
|
|
305
|
+
inFlight.delete(key);
|
|
241
306
|
}
|
|
242
307
|
}
|
|
243
308
|
})();
|
|
@@ -257,10 +322,11 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
257
322
|
if (!id)
|
|
258
323
|
return;
|
|
259
324
|
const cache = itemCacheRef.current;
|
|
260
|
-
if (cache.has(
|
|
325
|
+
if (cache.has(itemKey(node)))
|
|
261
326
|
return;
|
|
262
327
|
const anyNode = node;
|
|
263
|
-
cache.set(
|
|
328
|
+
cache.set(itemKey(node), fullItemFromDescriptor({
|
|
329
|
+
database: node.database,
|
|
264
330
|
id,
|
|
265
331
|
language: node.language ?? language,
|
|
266
332
|
version: node.version ?? 1,
|
|
@@ -278,10 +344,12 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
278
344
|
const source = itemsToAdd ?? selectedInTree;
|
|
279
345
|
if (!source || source.length === 0)
|
|
280
346
|
return;
|
|
281
|
-
const existing = new Set(items.map((i) => i.descriptor
|
|
347
|
+
const existing = new Set(items.map((i) => itemKey(i.descriptor)));
|
|
282
348
|
const next = [...items];
|
|
283
|
-
for (const
|
|
284
|
-
|
|
349
|
+
for (const candidate of source) {
|
|
350
|
+
// A tree node belongs to the store the tree browses.
|
|
351
|
+
const node = { ...candidate, database: candidate.database ?? store };
|
|
352
|
+
if (!node.id || !node.database || existing.has(itemKey(node)))
|
|
285
353
|
continue;
|
|
286
354
|
if (!isWritable(node))
|
|
287
355
|
continue;
|
|
@@ -289,6 +357,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
289
357
|
cacheTreeNode(node);
|
|
290
358
|
next.push({
|
|
291
359
|
descriptor: {
|
|
360
|
+
database: node.database,
|
|
292
361
|
id: node.id,
|
|
293
362
|
language: node.language ?? language,
|
|
294
363
|
version: node.version ?? 1,
|
|
@@ -299,16 +368,18 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
299
368
|
},
|
|
300
369
|
includeSubitems: false,
|
|
301
370
|
});
|
|
302
|
-
existing.add(node
|
|
371
|
+
existing.add(itemKey(node));
|
|
303
372
|
}
|
|
304
373
|
setItems(next);
|
|
305
374
|
commitToWizard(next);
|
|
306
375
|
setSelectedInTree([]);
|
|
307
376
|
setSelectedFromList([]);
|
|
308
|
-
}, [items, selectedInTree, language, cacheTreeNode, commitToWizard]);
|
|
377
|
+
}, [items, selectedInTree, store, language, cacheTreeNode, commitToWizard]);
|
|
309
378
|
const handleAddItem = useCallback(async (item) => {
|
|
310
379
|
const id = item.id;
|
|
311
|
-
if (!id ||
|
|
380
|
+
if (!id ||
|
|
381
|
+
!item.database ||
|
|
382
|
+
items.some((i) => itemKey(i.descriptor) === itemKey(item)))
|
|
312
383
|
return;
|
|
313
384
|
if (!isWritable(item))
|
|
314
385
|
return;
|
|
@@ -317,6 +388,7 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
317
388
|
...items,
|
|
318
389
|
{
|
|
319
390
|
descriptor: {
|
|
391
|
+
database: item.database,
|
|
320
392
|
id,
|
|
321
393
|
language: item.language ?? language,
|
|
322
394
|
version: item.version ?? 1,
|
|
@@ -333,8 +405,8 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
333
405
|
setSelectedFromList([]);
|
|
334
406
|
}, [items, language, cacheTreeNode, commitToWizard]);
|
|
335
407
|
const handleRemoveFromList = useCallback(() => {
|
|
336
|
-
const ids = new Set(selectedFromList.map((i) => i.descriptor
|
|
337
|
-
const next = items.filter((i) => !ids.has(i.descriptor
|
|
408
|
+
const ids = new Set(selectedFromList.map((i) => itemKey(i.descriptor)));
|
|
409
|
+
const next = items.filter((i) => !ids.has(itemKey(i.descriptor)));
|
|
338
410
|
setItems(next);
|
|
339
411
|
commitToWizard(next);
|
|
340
412
|
setSelectedFromList([]);
|
|
@@ -350,5 +422,18 @@ export function ItemSelectionTree({ data, setData, editContext, isActive = true,
|
|
|
350
422
|
setItems(next);
|
|
351
423
|
commitToWizard(next);
|
|
352
424
|
}, [items, commitToWizard]);
|
|
353
|
-
|
|
425
|
+
// A bounded column: the pickers keep their height and the editor takes the
|
|
426
|
+
// rest, so the tree and the list scroll inside it, never the whole step.
|
|
427
|
+
const storePicker = onlyStore ? undefined : (_jsxs("div", { className: "flex w-64 max-w-full flex-col gap-2", children: [_jsx("span", { className: "text-neutral-grey-50 text-xs font-medium tracking-wider", children: "Content store" }), _jsx(ContentStoreSelect, { "data-testid": "translation-content-store", value: store, placeholder: "Select a store", onValueChange: (value) => {
|
|
428
|
+
setStore(value);
|
|
429
|
+
setSelectedInTree([]);
|
|
430
|
+
}, stores: writableStores })] }));
|
|
431
|
+
return (_jsx("div", { className: "flex h-full min-h-0 flex-col", children: store && language ? (_jsx("div", { className: "min-h-0 flex-1", children: _jsx(ItemCollectionEditor, { items: items, selectedInTree: selectedInTree, onSelectedInTreeChange: setSelectedInTree, selectedFromList: selectedFromList, onSelectedFromListChange: setSelectedFromList, onAddToList: handleAddToList, onRemoveFromList: handleRemoveFromList, onAddItem: handleAddItem, onRemoveItem: handleRemoveItem, onToggleSubitems: handleToggleSubitems, language: language, database: store, rootItemIds: model?.roots
|
|
432
|
+
.filter((root) => root.storeId === store &&
|
|
433
|
+
(root.kind === "content" || root.kind === "media"))
|
|
434
|
+
.map((root) => root.id), hideRootNodes: false, isItemSelectable: isWritable, unselectableItemTitle: NO_WRITE_ACCESS_TITLE, selectedItemsLabel: "Selected", emptyMessage: "No items selected", emptyHint: "Browse or search to add items", height: height, subitemCounts: subitemCounts, subitemCountKey: itemKey, expandIdPath: expandIdPath, localStorageKey: "translation-wizard.itemCollectionSplitter", treeSearchContainerClassName: "border-b-0 p-0 pb-3", treeHeader: storePicker, frameless: true }) })) : (_jsxs("div", { className: "flex flex-col gap-4 p-6", children: [storePicker, _jsx("p", { className: "text-neutral-grey-50 text-sm", children: !store
|
|
435
|
+
? "Select a content store to choose translation items."
|
|
436
|
+
: storeLanguages === null
|
|
437
|
+
? "Loading languages..."
|
|
438
|
+
: "This store declares no languages." })] })) }));
|
|
354
439
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderStep.d.ts","sourceRoot":"","sources":["../../src/steps/ProviderStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAUf,OAAO,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"ProviderStep.d.ts","sourceRoot":"","sources":["../../src/steps/ProviderStep.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAUf,OAAO,EAAE,oBAAoB,EAAyB,MAAM,SAAS,CAAC;AAStE,wBAAgB,YAAY,CAAC,EAC3B,QAAe,EACf,IAAI,EACJ,OAAO,EACP,eAAe,EACf,WAAW,GACZ,EAAE,oBAAoB,qBAkZtB"}
|
|
@@ -4,6 +4,7 @@ import { Button, Input, Label, Select, Spinner, Textarea, } from "@parhelia/core
|
|
|
4
4
|
import { RotateCcw } from "lucide-react";
|
|
5
5
|
import { WizardStepShell } from "./WizardStepShell";
|
|
6
6
|
import { suggestBatchName } from "../api/discovery";
|
|
7
|
+
import { translationItem } from "../services/translationService";
|
|
7
8
|
const PROMPT_CUSTOMIZATION_TYPE = "replace";
|
|
8
9
|
const ResetIcon = (props) => React.createElement(RotateCcw, props);
|
|
9
10
|
export function ProviderStep({ isActive = true, data, setData, onStepCompleted, editContext, }) {
|
|
@@ -15,17 +16,29 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
15
16
|
// it with a fresh AI suggestion.
|
|
16
17
|
const userTouchedNameRef = useRef(!!data.batchName);
|
|
17
18
|
const dataRef = useRef(data);
|
|
18
|
-
|
|
19
|
+
const lastDataPropRef = useRef(data);
|
|
20
|
+
if (lastDataPropRef.current !== data) {
|
|
21
|
+
lastDataPropRef.current = data;
|
|
19
22
|
dataRef.current = data;
|
|
20
|
-
}
|
|
23
|
+
}
|
|
24
|
+
// This step has several asynchronous writers (name suggestion, prompt
|
|
25
|
+
// debounce, provider selection). Serialize them through one current-data
|
|
26
|
+
// ref so a late writer cannot rebuild wizard state from an older render and
|
|
27
|
+
// erase a newer checkbox/provider choice.
|
|
28
|
+
const commitData = useCallback((update) => {
|
|
29
|
+
const current = dataRef.current;
|
|
30
|
+
const next = update(current);
|
|
31
|
+
if (next === current)
|
|
32
|
+
return;
|
|
33
|
+
dataRef.current = next;
|
|
34
|
+
setData(next);
|
|
35
|
+
}, [setData]);
|
|
21
36
|
// Push name changes back into wizard data (debounced via simple equality).
|
|
22
37
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
return;
|
|
25
|
-
setData((current) => (current.batchName ?? "") === batchName
|
|
38
|
+
commitData((current) => (current.batchName ?? "") === batchName
|
|
26
39
|
? current
|
|
27
40
|
: { ...current, batchName });
|
|
28
|
-
}, [batchName,
|
|
41
|
+
}, [batchName, commitData]);
|
|
29
42
|
// Auto-suggest a name when the step becomes active and the user hasn't
|
|
30
43
|
// already provided/edited one. Fires once per item+language combination so
|
|
31
44
|
// navigating away and back doesn't re-fetch.
|
|
@@ -36,13 +49,17 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
36
49
|
return;
|
|
37
50
|
if (userTouchedNameRef.current)
|
|
38
51
|
return;
|
|
39
|
-
const
|
|
40
|
-
? data.selectionTreeItems.map((s) => s.descriptor
|
|
41
|
-
: data.items.map((i) => i.descriptor
|
|
52
|
+
const descriptors = (data.selectionTreeItems && data.selectionTreeItems.length > 0
|
|
53
|
+
? data.selectionTreeItems.map((s) => s.descriptor)
|
|
54
|
+
: data.items.map((i) => i.descriptor)).filter(Boolean);
|
|
42
55
|
const langs = [...data.targetLanguages].sort();
|
|
43
|
-
if (
|
|
56
|
+
if (descriptors.length === 0 ||
|
|
57
|
+
langs.length === 0 ||
|
|
58
|
+
descriptors.some((d) => !d.database || !d.language))
|
|
44
59
|
return;
|
|
45
|
-
const
|
|
60
|
+
const items = descriptors.map(translationItem);
|
|
61
|
+
const language = data.sourceLanguage || descriptors[0].language;
|
|
62
|
+
const key = JSON.stringify({ items, language, langs });
|
|
46
63
|
if (lastSuggestionKeyRef.current === key)
|
|
47
64
|
return;
|
|
48
65
|
lastSuggestionKeyRef.current = key;
|
|
@@ -51,7 +68,7 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
51
68
|
void (async () => {
|
|
52
69
|
try {
|
|
53
70
|
const includeSubitems = !!data.selectionTreeItems?.some((s) => s.includeSubitems);
|
|
54
|
-
const name = await suggestBatchName({
|
|
71
|
+
const name = await suggestBatchName({ items, language, targetLanguages: langs, includeSubitems }, sessionId);
|
|
55
72
|
if (cancelled || userTouchedNameRef.current)
|
|
56
73
|
return;
|
|
57
74
|
if (name)
|
|
@@ -70,15 +87,14 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
70
87
|
sessionId,
|
|
71
88
|
data.selectionTreeItems,
|
|
72
89
|
data.items,
|
|
90
|
+
data.sourceLanguage,
|
|
73
91
|
data.targetLanguages,
|
|
74
92
|
]);
|
|
75
93
|
const customPromptRef = useRef(customPrompt);
|
|
76
94
|
const hasInitializedRef = useRef(false);
|
|
77
95
|
const lastProviderRef = useRef(data.translationProvider);
|
|
78
96
|
const updateTimerRef = useRef(null);
|
|
79
|
-
|
|
80
|
-
customPromptRef.current = customPrompt;
|
|
81
|
-
}, [customPrompt]);
|
|
97
|
+
customPromptRef.current = customPrompt;
|
|
82
98
|
const selectedProvider = useMemo(() => data.translationProviders.find((p) => p.name === data.translationProvider), [data.translationProviders, data.translationProvider]);
|
|
83
99
|
const serviceData = useMemo(() => {
|
|
84
100
|
if (!data.serviceCustomData || !data.translationProvider)
|
|
@@ -133,7 +149,7 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
133
149
|
}, [data.translationProvider, isActive, onStepCompleted]);
|
|
134
150
|
const handleProviderChange = (e) => {
|
|
135
151
|
const newProvider = e.target.value;
|
|
136
|
-
|
|
152
|
+
commitData((current) => {
|
|
137
153
|
const newServiceCustomData = new Map();
|
|
138
154
|
current.serviceCustomData?.forEach((value, key) => {
|
|
139
155
|
if (key !== "AI" || newProvider === "AI") {
|
|
@@ -149,10 +165,9 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
149
165
|
};
|
|
150
166
|
const handleCustomPromptToggle = (enabled) => {
|
|
151
167
|
const prompt = defaultPrompt || "";
|
|
152
|
-
if (enabled)
|
|
168
|
+
if (enabled)
|
|
153
169
|
setCustomPrompt(prompt);
|
|
154
|
-
|
|
155
|
-
setData((current) => {
|
|
170
|
+
commitData((current) => {
|
|
156
171
|
const newServiceCustomData = new Map(current.serviceCustomData || new Map());
|
|
157
172
|
if (enabled) {
|
|
158
173
|
newServiceCustomData.set(current.translationProvider, {
|
|
@@ -175,36 +190,34 @@ export function ProviderStep({ isActive = true, data, setData, onStepCompleted,
|
|
|
175
190
|
};
|
|
176
191
|
const updateParentData = useCallback(() => {
|
|
177
192
|
const trimmedCustomPrompt = customPromptRef.current.trim();
|
|
178
|
-
|
|
179
|
-
|
|
193
|
+
commitData((current) => {
|
|
194
|
+
const provider = current.translationProvider;
|
|
195
|
+
if (!provider)
|
|
196
|
+
return current;
|
|
197
|
+
const currentServiceData = current.serviceCustomData?.get(provider);
|
|
198
|
+
// The toggle itself owns disabling/removal. A delayed prompt sync must
|
|
199
|
+
// never delete a choice made after its timer was scheduled.
|
|
200
|
+
if (currentServiceData?.enableCustomPrompt !== true)
|
|
201
|
+
return current;
|
|
202
|
+
const nextServiceData = {
|
|
203
|
+
enableCustomPrompt: true,
|
|
204
|
+
customPrompt: trimmedCustomPrompt,
|
|
205
|
+
promptCustomizationType: PROMPT_CUSTOMIZATION_TYPE,
|
|
206
|
+
};
|
|
207
|
+
const isSame = currentServiceData?.enableCustomPrompt === true &&
|
|
208
|
+
(currentServiceData.customPrompt || "") === trimmedCustomPrompt &&
|
|
209
|
+
currentServiceData.promptCustomizationType ===
|
|
210
|
+
PROMPT_CUSTOMIZATION_TYPE;
|
|
211
|
+
if (isSame)
|
|
180
212
|
return current;
|
|
181
213
|
const newServiceCustomData = new Map(current.serviceCustomData || new Map());
|
|
182
|
-
|
|
183
|
-
const isEnabled = currentServiceData?.enableCustomPrompt === true;
|
|
184
|
-
if (isEnabled) {
|
|
185
|
-
const nextServiceData = {
|
|
186
|
-
enableCustomPrompt: true,
|
|
187
|
-
customPrompt: trimmedCustomPrompt,
|
|
188
|
-
promptCustomizationType: PROMPT_CUSTOMIZATION_TYPE,
|
|
189
|
-
};
|
|
190
|
-
const isSame = (currentServiceData.customPrompt || "") === trimmedCustomPrompt &&
|
|
191
|
-
currentServiceData.promptCustomizationType ===
|
|
192
|
-
PROMPT_CUSTOMIZATION_TYPE;
|
|
193
|
-
if (isSame)
|
|
194
|
-
return current;
|
|
195
|
-
newServiceCustomData.set(current.translationProvider, nextServiceData);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
if (!currentServiceData)
|
|
199
|
-
return current;
|
|
200
|
-
newServiceCustomData.delete(current.translationProvider);
|
|
201
|
-
}
|
|
214
|
+
newServiceCustomData.set(provider, nextServiceData);
|
|
202
215
|
return {
|
|
203
216
|
...current,
|
|
204
217
|
serviceCustomData: newServiceCustomData,
|
|
205
218
|
};
|
|
206
219
|
});
|
|
207
|
-
}, [
|
|
220
|
+
}, [commitData]);
|
|
208
221
|
useEffect(() => {
|
|
209
222
|
if (!isActive || !supportsPromptCustomization)
|
|
210
223
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TranslationStepProps } from "./types";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Source and target languages. Item selection lives in its own step
|
|
4
4
|
* (see ItemSelectionStep). The legacy name is kept so existing imports
|
|
5
5
|
* keep working.
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceLanguageSelectionStep.d.ts","sourceRoot":"","sources":["../../src/steps/ServiceLanguageSelectionStep.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServiceLanguageSelectionStep.d.ts","sourceRoot":"","sources":["../../src/steps/ServiceLanguageSelectionStep.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAoB/C;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,QAAe,EACf,IAAI,EACJ,OAAO,EACP,eAAe,EACf,WAAW,GACZ,EAAE,oBAAoB,+BA0VtB"}
|