@sanity/assist 1.2.15-lang.2 → 1.2.15-lang.3
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/README.md +135 -22
- package/dist/index.d.ts +60 -0
- package/dist/index.esm.js +145 -100
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +145 -100
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/assistDocument/AssistDocumentInput.tsx +22 -3
- package/src/components/SafeValueInput.tsx +4 -1
- package/src/fieldActions/assistFieldActions.tsx +5 -2
- package/src/plugin.tsx +9 -1
- package/src/schemas/typeDefExtensions.ts +62 -0
- package/src/translate/FieldTranslationProvider.tsx +42 -39
- package/src/translate/paths.test.ts +4 -4
- package/src/translate/paths.ts +5 -5
- package/src/{fieldActions → translate}/translateActions.tsx +73 -40
- package/src/useApiClient.ts +13 -11
package/dist/index.esm.js
CHANGED
|
@@ -971,6 +971,7 @@ function useTranslate(apiClient) {
|
|
|
971
971
|
let {
|
|
972
972
|
documentId,
|
|
973
973
|
languagePath,
|
|
974
|
+
translatePath,
|
|
974
975
|
fieldLanguageMap
|
|
975
976
|
} = _ref4;
|
|
976
977
|
setLoading(true);
|
|
@@ -982,6 +983,7 @@ function useTranslate(apiClient) {
|
|
|
982
983
|
types,
|
|
983
984
|
languagePath,
|
|
984
985
|
fieldLanguageMap,
|
|
986
|
+
translatePath: translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
|
|
985
987
|
userId: user == null ? void 0 : user.id
|
|
986
988
|
}
|
|
987
989
|
}).catch(e => {
|
|
@@ -3316,7 +3318,7 @@ const defaultLanguageOutputs = function (member, enclosingType, translateFromLan
|
|
|
3316
3318
|
}
|
|
3317
3319
|
return void 0;
|
|
3318
3320
|
};
|
|
3319
|
-
function
|
|
3321
|
+
function getFieldLanguageMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
|
|
3320
3322
|
var _a, _b, _c;
|
|
3321
3323
|
const translationMaps = [];
|
|
3322
3324
|
for (const member of documentMembers) {
|
|
@@ -4548,13 +4550,12 @@ const getLanguageParams = (select, document) => {
|
|
|
4548
4550
|
const FieldTranslationContext = createContext({
|
|
4549
4551
|
openFieldTranslation: () => {},
|
|
4550
4552
|
translationLoading: false
|
|
4551
|
-
//loadLanguages: () => {},
|
|
4552
4553
|
});
|
|
4553
4554
|
function useFieldTranslation() {
|
|
4554
4555
|
return useContext(FieldTranslationContext);
|
|
4555
4556
|
}
|
|
4556
4557
|
function FieldTranslationProvider(props) {
|
|
4557
|
-
var _a, _b;
|
|
4558
|
+
var _a, _b, _c;
|
|
4558
4559
|
const {
|
|
4559
4560
|
config: assistConfig
|
|
4560
4561
|
} = useAiAssistanceConfig();
|
|
@@ -4564,40 +4565,42 @@ function FieldTranslationProvider(props) {
|
|
|
4564
4565
|
translate: runTranslate
|
|
4565
4566
|
} = useTranslate(apiClient);
|
|
4566
4567
|
const [dialogOpen, setDialogOpen] = useState(false);
|
|
4567
|
-
const [
|
|
4568
|
-
const [documentSchema, setDocumentSchema] = useState();
|
|
4568
|
+
const [fieldTranslationParams, setFieldTranslationParams] = useState();
|
|
4569
4569
|
const [languages, setLanguages] = useState();
|
|
4570
4570
|
const [fromLanguage, setFromLanguage] = useState(void 0);
|
|
4571
4571
|
const [toLanguages, setToLanguages] = useState(void 0);
|
|
4572
|
-
const [
|
|
4572
|
+
const [fieldLanguageMaps, setFieldLanguageMaps] = useState();
|
|
4573
4573
|
const close = useCallback(() => {
|
|
4574
4574
|
setDialogOpen(false);
|
|
4575
4575
|
setLanguages(void 0);
|
|
4576
|
-
|
|
4577
|
-
setDocument(void 0);
|
|
4576
|
+
setFieldTranslationParams(void 0);
|
|
4578
4577
|
}, []);
|
|
4579
4578
|
const languageClient = useClient({
|
|
4580
4579
|
apiVersion: (_b = config == null ? void 0 : config.apiVersion) != null ? _b : "2022-11-27"
|
|
4581
4580
|
});
|
|
4582
|
-
const documentId = document == null ? void 0 :
|
|
4581
|
+
const documentId = (_c = fieldTranslationParams == null ? void 0 : fieldTranslationParams.document) == null ? void 0 : _c._id;
|
|
4583
4582
|
const id = useId();
|
|
4584
|
-
const selectFromLanguage = useCallback((from, languages2,
|
|
4583
|
+
const selectFromLanguage = useCallback((from, languages2, params) => {
|
|
4585
4584
|
var _a2, _b2;
|
|
4585
|
+
const {
|
|
4586
|
+
document,
|
|
4587
|
+
documentSchema
|
|
4588
|
+
} = params != null ? params : {};
|
|
4586
4589
|
setFromLanguage(from);
|
|
4587
|
-
if (!
|
|
4588
|
-
|
|
4590
|
+
if (!document || !documentSchema || !params || !languages2) {
|
|
4591
|
+
setFieldLanguageMaps(void 0);
|
|
4589
4592
|
return;
|
|
4590
4593
|
}
|
|
4591
4594
|
const to = languages2.filter(l => l.id !== (from == null ? void 0 : from.id));
|
|
4592
4595
|
setToLanguages(to);
|
|
4593
4596
|
const fromId = from == null ? void 0 : from.id;
|
|
4594
4597
|
const toIds = (_a2 = to == null ? void 0 : to.map(l => l.id)) != null ? _a2 : [];
|
|
4595
|
-
const docMembers = getDocumentMembersFlat(
|
|
4598
|
+
const docMembers = getDocumentMembersFlat(document, documentSchema);
|
|
4596
4599
|
if (fromId && (toIds == null ? void 0 : toIds.length)) {
|
|
4597
|
-
const transMap =
|
|
4598
|
-
|
|
4600
|
+
const transMap = getFieldLanguageMap(documentSchema, docMembers, fromId, toIds, (_b2 = config == null ? void 0 : config.translationOutputs) != null ? _b2 : defaultLanguageOutputs);
|
|
4601
|
+
setFieldLanguageMaps(transMap);
|
|
4599
4602
|
} else {
|
|
4600
|
-
|
|
4603
|
+
setFieldLanguageMaps(void 0);
|
|
4601
4604
|
}
|
|
4602
4605
|
}, [config]);
|
|
4603
4606
|
const toggleToLanguage = useCallback((toggledLang, toLanguages2, languages2) => {
|
|
@@ -4608,20 +4611,15 @@ function FieldTranslationProvider(props) {
|
|
|
4608
4611
|
const newToLangs = languages2.filter(anyLang => !!(toLanguages2 == null ? void 0 : toLanguages2.find(selectedLang => toggledLang.id !== selectedLang.id && selectedLang.id === anyLang.id)) || toggledLang.id === anyLang.id && !wasSelected);
|
|
4609
4612
|
setToLanguages(newToLangs);
|
|
4610
4613
|
}, []);
|
|
4611
|
-
const openFieldTranslation = useCallback(async
|
|
4612
|
-
let {
|
|
4613
|
-
document: document2,
|
|
4614
|
-
documentSchema: documentSchema2
|
|
4615
|
-
} = _ref11;
|
|
4614
|
+
const openFieldTranslation = useCallback(async params => {
|
|
4616
4615
|
setDialogOpen(true);
|
|
4617
|
-
const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams,
|
|
4616
|
+
const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams, params.document);
|
|
4618
4617
|
const languages2 = await (typeof (config == null ? void 0 : config.languages) === "function" ? config == null ? void 0 : config.languages(languageClient, languageParams) : Promise.resolve(config == null ? void 0 : config.languages));
|
|
4619
4618
|
setLanguages(languages2);
|
|
4620
|
-
|
|
4621
|
-
setDocumentSchema(documentSchema2);
|
|
4619
|
+
setFieldTranslationParams(params);
|
|
4622
4620
|
const fromLanguage2 = languages2 == null ? void 0 : languages2[0];
|
|
4623
4621
|
if (fromLanguage2) {
|
|
4624
|
-
selectFromLanguage(fromLanguage2, languages2,
|
|
4622
|
+
selectFromLanguage(fromLanguage2, languages2, params);
|
|
4625
4623
|
} else {
|
|
4626
4624
|
console.error("No languages available for selected language params", languageParams);
|
|
4627
4625
|
}
|
|
@@ -4632,12 +4630,14 @@ function FieldTranslationProvider(props) {
|
|
|
4632
4630
|
translationLoading: false
|
|
4633
4631
|
};
|
|
4634
4632
|
}, [openFieldTranslation]);
|
|
4635
|
-
const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(
|
|
4633
|
+
const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(fieldLanguageMaps == null ? void 0 : fieldLanguageMaps.length) || !documentId;
|
|
4636
4634
|
const onRunTranslation = useCallback(() => {
|
|
4637
|
-
|
|
4635
|
+
const translatePath = fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath;
|
|
4636
|
+
if (fieldLanguageMaps && documentId && translatePath) {
|
|
4638
4637
|
runTranslate({
|
|
4639
4638
|
documentId,
|
|
4640
|
-
|
|
4639
|
+
translatePath: fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath,
|
|
4640
|
+
fieldLanguageMap: fieldLanguageMaps.map(map => ({
|
|
4641
4641
|
...map,
|
|
4642
4642
|
// eslint-disable-next-line max-nested-callbacks
|
|
4643
4643
|
outputs: map.outputs.filter(out => !!(toLanguages == null ? void 0 : toLanguages.find(l => l.id === out.id)))
|
|
@@ -4645,7 +4645,7 @@ function FieldTranslationProvider(props) {
|
|
|
4645
4645
|
});
|
|
4646
4646
|
}
|
|
4647
4647
|
close();
|
|
4648
|
-
}, [
|
|
4648
|
+
}, [fieldLanguageMaps, documentId, runTranslate, close, toLanguages, fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath]);
|
|
4649
4649
|
const runButton = /* @__PURE__ */jsx(Button, {
|
|
4650
4650
|
text: "Translate",
|
|
4651
4651
|
tone: "primary",
|
|
@@ -4704,7 +4704,7 @@ function FieldTranslationProvider(props) {
|
|
|
4704
4704
|
name: "fromLang",
|
|
4705
4705
|
value: l.id,
|
|
4706
4706
|
checked: l.id === (fromLanguage == null ? void 0 : fromLanguage.id),
|
|
4707
|
-
onClick: () => selectFromLanguage(l, languages,
|
|
4707
|
+
onClick: () => selectFromLanguage(l, languages, fieldTranslationParams)
|
|
4708
4708
|
}), /* @__PURE__ */jsx(Text, {
|
|
4709
4709
|
children: (_a2 = l.title) != null ? _a2 : l.id
|
|
4710
4710
|
})]
|
|
@@ -4728,7 +4728,7 @@ function FieldTranslationProvider(props) {
|
|
|
4728
4728
|
value: l.id,
|
|
4729
4729
|
checked: !!(toLanguages == null ? void 0 : toLanguages.find(tl => tl.id === l.id)),
|
|
4730
4730
|
onClick: () => toggleToLanguage(l, toLanguages, languages),
|
|
4731
|
-
disabled: !(
|
|
4731
|
+
disabled: !(fieldLanguageMaps == null ? void 0 : fieldLanguageMaps.find(tm => tm.outputs.find(o => o.id === l.id)))
|
|
4732
4732
|
}), /* @__PURE__ */jsx(Text, {
|
|
4733
4733
|
children: (_a2 = l.title) != null ? _a2 : l.id
|
|
4734
4734
|
})]
|
|
@@ -4793,7 +4793,10 @@ function ErrorWrapper(props) {
|
|
|
4793
4793
|
const catchError = useCallback(params => {
|
|
4794
4794
|
setError(params.error);
|
|
4795
4795
|
}, [setError]);
|
|
4796
|
-
const unsetValue = useCallback(() =>
|
|
4796
|
+
const unsetValue = useCallback(() => {
|
|
4797
|
+
onChange(PatchEvent.from(unset()));
|
|
4798
|
+
setError(void 0);
|
|
4799
|
+
}, [onChange]);
|
|
4797
4800
|
const dismiss = useCallback(() => setError(void 0), []);
|
|
4798
4801
|
const catcher = /* @__PURE__ */jsx(ErrorBoundary, {
|
|
4799
4802
|
onCatch: catchError,
|
|
@@ -4925,11 +4928,11 @@ function InstructionInput(props) {
|
|
|
4925
4928
|
})]
|
|
4926
4929
|
});
|
|
4927
4930
|
}
|
|
4928
|
-
function ObjectMember(
|
|
4931
|
+
function ObjectMember(_ref11) {
|
|
4929
4932
|
let {
|
|
4930
4933
|
fieldName,
|
|
4931
4934
|
...props
|
|
4932
|
-
} =
|
|
4935
|
+
} = _ref11;
|
|
4933
4936
|
const member = findFieldMember(props.members, fieldName);
|
|
4934
4937
|
return member ? /* @__PURE__ */jsx(ObjectInputMember, {
|
|
4935
4938
|
...props,
|
|
@@ -5068,8 +5071,8 @@ function IconInput(props) {
|
|
|
5068
5071
|
onChange
|
|
5069
5072
|
} = props;
|
|
5070
5073
|
const id = useId();
|
|
5071
|
-
const items = useMemo(() => Object.entries(icons).map(
|
|
5072
|
-
let [key, icon] =
|
|
5074
|
+
const items = useMemo(() => Object.entries(icons).map(_ref12 => {
|
|
5075
|
+
let [key, icon] = _ref12;
|
|
5073
5076
|
return /* @__PURE__ */jsx(IconItem, {
|
|
5074
5077
|
iconKey: key,
|
|
5075
5078
|
icon,
|
|
@@ -5097,12 +5100,12 @@ function IconInput(props) {
|
|
|
5097
5100
|
}
|
|
5098
5101
|
});
|
|
5099
5102
|
}
|
|
5100
|
-
function IconItem(
|
|
5103
|
+
function IconItem(_ref13) {
|
|
5101
5104
|
let {
|
|
5102
5105
|
icon,
|
|
5103
5106
|
iconKey: key,
|
|
5104
5107
|
onChange
|
|
5105
|
-
} =
|
|
5108
|
+
} = _ref13;
|
|
5106
5109
|
const onClick = useCallback(() => onChange(set(key)), [onChange, key]);
|
|
5107
5110
|
return /* @__PURE__ */jsx(MenuItem, {
|
|
5108
5111
|
icon,
|
|
@@ -5113,8 +5116,8 @@ function IconItem(_ref14) {
|
|
|
5113
5116
|
}
|
|
5114
5117
|
function getIcon(iconName) {
|
|
5115
5118
|
var _a, _b;
|
|
5116
|
-
return (_b = (_a = Object.entries(icons).find(
|
|
5117
|
-
let [key] =
|
|
5119
|
+
return (_b = (_a = Object.entries(icons).find(_ref14 => {
|
|
5120
|
+
let [key] = _ref14;
|
|
5118
5121
|
return key === iconName;
|
|
5119
5122
|
})) == null ? void 0 : _a[1]) != null ? _b : icons.sparkles;
|
|
5120
5123
|
}
|
|
@@ -5273,11 +5276,11 @@ const contextDocumentSchema = defineType({
|
|
|
5273
5276
|
title: "title",
|
|
5274
5277
|
context: "context"
|
|
5275
5278
|
},
|
|
5276
|
-
prepare(
|
|
5279
|
+
prepare(_ref15) {
|
|
5277
5280
|
let {
|
|
5278
5281
|
title,
|
|
5279
5282
|
context
|
|
5280
|
-
} =
|
|
5283
|
+
} = _ref15;
|
|
5281
5284
|
var _a;
|
|
5282
5285
|
const text = context == null ? void 0 : context.flatMap(block => block == null ? void 0 : block.children).flatMap(child => {
|
|
5283
5286
|
var _a2;
|
|
@@ -5377,11 +5380,11 @@ function InstructionOutputField(props) {
|
|
|
5377
5380
|
children: props.children
|
|
5378
5381
|
});
|
|
5379
5382
|
}
|
|
5380
|
-
function EnabledOutputField(
|
|
5383
|
+
function EnabledOutputField(_ref16) {
|
|
5381
5384
|
let {
|
|
5382
5385
|
fieldSchema,
|
|
5383
5386
|
...props
|
|
5384
|
-
} =
|
|
5387
|
+
} = _ref16;
|
|
5385
5388
|
var _a;
|
|
5386
5389
|
const [open, setOpen] = useState(!!((_a = props.value) == null ? void 0 : _a.length));
|
|
5387
5390
|
const onExpand = useCallback(() => setOpen(true), []);
|
|
@@ -5429,11 +5432,11 @@ function useEmptySelectAllValue(value, allowedValues, onChange) {
|
|
|
5429
5432
|
}
|
|
5430
5433
|
}, [allowedValues, value, onChange]);
|
|
5431
5434
|
}
|
|
5432
|
-
function ObjectOutputInput(
|
|
5435
|
+
function ObjectOutputInput(_ref17) {
|
|
5433
5436
|
let {
|
|
5434
5437
|
fieldSchema,
|
|
5435
5438
|
...props
|
|
5436
|
-
} =
|
|
5439
|
+
} = _ref17;
|
|
5437
5440
|
const {
|
|
5438
5441
|
value,
|
|
5439
5442
|
onChange
|
|
@@ -5480,11 +5483,11 @@ function ObjectOutputInput(_ref18) {
|
|
|
5480
5483
|
})
|
|
5481
5484
|
});
|
|
5482
5485
|
}
|
|
5483
|
-
function ArrayOutputInput(
|
|
5486
|
+
function ArrayOutputInput(_ref18) {
|
|
5484
5487
|
let {
|
|
5485
5488
|
fieldSchema,
|
|
5486
5489
|
...props
|
|
5487
|
-
} =
|
|
5490
|
+
} = _ref18;
|
|
5488
5491
|
const {
|
|
5489
5492
|
value,
|
|
5490
5493
|
onChange
|
|
@@ -5529,13 +5532,13 @@ function ArrayOutputInput(_ref19) {
|
|
|
5529
5532
|
})
|
|
5530
5533
|
});
|
|
5531
5534
|
}
|
|
5532
|
-
function Selectable(
|
|
5535
|
+
function Selectable(_ref19) {
|
|
5533
5536
|
let {
|
|
5534
5537
|
title,
|
|
5535
5538
|
arrayValue,
|
|
5536
5539
|
value,
|
|
5537
5540
|
onChange
|
|
5538
|
-
} =
|
|
5541
|
+
} = _ref19;
|
|
5539
5542
|
const checked = !(arrayValue == null ? void 0 : arrayValue.length) || !!(arrayValue == null ? void 0 : arrayValue.find(v => v._key === value));
|
|
5540
5543
|
const handleChange = useCallback(() => onChange(checked, value), [onChange, checked, value]);
|
|
5541
5544
|
return /* @__PURE__ */jsxs(Flex, {
|
|
@@ -5600,10 +5603,10 @@ const fieldReference = defineType({
|
|
|
5600
5603
|
select: {
|
|
5601
5604
|
path: "path"
|
|
5602
5605
|
},
|
|
5603
|
-
prepare(
|
|
5606
|
+
prepare(_ref20) {
|
|
5604
5607
|
let {
|
|
5605
5608
|
path
|
|
5606
|
-
} =
|
|
5609
|
+
} = _ref20;
|
|
5607
5610
|
return {
|
|
5608
5611
|
title: path,
|
|
5609
5612
|
path,
|
|
@@ -5748,12 +5751,12 @@ const instruction = defineType({
|
|
|
5748
5751
|
title: "title",
|
|
5749
5752
|
userId: "userId"
|
|
5750
5753
|
},
|
|
5751
|
-
prepare:
|
|
5754
|
+
prepare: _ref21 => {
|
|
5752
5755
|
let {
|
|
5753
5756
|
icon,
|
|
5754
5757
|
title,
|
|
5755
5758
|
userId
|
|
5756
|
-
} =
|
|
5759
|
+
} = _ref21;
|
|
5757
5760
|
return {
|
|
5758
5761
|
title,
|
|
5759
5762
|
icon: icon ? icons[icon] : SparklesIcon,
|
|
@@ -6205,21 +6208,25 @@ function node$1(node2) {
|
|
|
6205
6208
|
const translateActions = {
|
|
6206
6209
|
name: "sanity-assist-translate",
|
|
6207
6210
|
useAction(props) {
|
|
6208
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
6211
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6209
6212
|
const {
|
|
6210
6213
|
config
|
|
6211
6214
|
} = useAiAssistanceConfig();
|
|
6212
6215
|
const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
|
|
6213
|
-
const isDocumentLevel = props.path.length === 0;
|
|
6214
6216
|
const {
|
|
6215
|
-
schemaType,
|
|
6217
|
+
schemaType: fieldSchemaType,
|
|
6218
|
+
path,
|
|
6216
6219
|
documentId,
|
|
6220
|
+
documentSchemaType,
|
|
6217
6221
|
documentIsAssistable
|
|
6218
6222
|
} = props;
|
|
6219
|
-
const
|
|
6220
|
-
const docTransTypes = (
|
|
6221
|
-
const
|
|
6222
|
-
|
|
6223
|
+
const isDocumentLevel = path.length === 0;
|
|
6224
|
+
const docTransTypes = (_b = (_a = config.translate) == null ? void 0 : _a.document) == null ? void 0 : _b.documentTypes;
|
|
6225
|
+
const options = fieldSchemaType == null ? void 0 : fieldSchemaType.options;
|
|
6226
|
+
const addFieldAction = isDocumentLevel || ((_c = options == null ? void 0 : options.aiWritingAssistance) == null ? void 0 : _c.translateAction);
|
|
6227
|
+
const fieldTransEnabled = addFieldAction && documentSchemaType && ((_f = (_e = (_d = config.translate) == null ? void 0 : _d.field) == null ? void 0 : _e.documentTypes) == null ? void 0 : _f.includes(documentSchemaType.name));
|
|
6228
|
+
const documentTranslationEnabled = addFieldAction && documentSchemaType && (!docTransTypes && isAssistSupported(fieldSchemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(documentSchemaType.name)));
|
|
6229
|
+
if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
|
|
6223
6230
|
const {
|
|
6224
6231
|
value: documentValue,
|
|
6225
6232
|
onChange: documentOnChange
|
|
@@ -6232,32 +6239,45 @@ const translateActions = {
|
|
|
6232
6239
|
task: translationApi.translate
|
|
6233
6240
|
});
|
|
6234
6241
|
docRef.current = documentValue;
|
|
6235
|
-
const languagePath = (
|
|
6236
|
-
const translateDocumentAction = useMemo(() =>
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6242
|
+
const languagePath = (_h = (_g = config.translate) == null ? void 0 : _g.document) == null ? void 0 : _h.languageField;
|
|
6243
|
+
const translateDocumentAction = useMemo(() => {
|
|
6244
|
+
var _a2;
|
|
6245
|
+
if (!languagePath || !documentTranslationEnabled) {
|
|
6246
|
+
return void 0;
|
|
6247
|
+
}
|
|
6248
|
+
const {
|
|
6249
|
+
value: languageId
|
|
6250
|
+
} = (_a2 = extractWithPath(languagePath, documentValue)[0]) != null ? _a2 : {};
|
|
6251
|
+
const title = path.length ? "Translate" : "Translate document";
|
|
6252
|
+
return node$1({
|
|
6253
|
+
type: "action",
|
|
6254
|
+
icon: translationApi.loading ? () => /* @__PURE__ */jsx(Box, {
|
|
6243
6255
|
style: {
|
|
6244
|
-
|
|
6256
|
+
height: 17
|
|
6257
|
+
},
|
|
6258
|
+
children: /* @__PURE__ */jsx(Spinner, {
|
|
6259
|
+
style: {
|
|
6260
|
+
transform: "translateY(6px)"
|
|
6261
|
+
}
|
|
6262
|
+
})
|
|
6263
|
+
}) : TranslateIcon,
|
|
6264
|
+
title,
|
|
6265
|
+
onAction: () => {
|
|
6266
|
+
if (translationApi.loading || !languagePath || !documentId) {
|
|
6267
|
+
return;
|
|
6245
6268
|
}
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
renderAsButton: true,
|
|
6259
|
-
disabled: translationApi.loading
|
|
6260
|
-
}) : void 0, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled]);
|
|
6269
|
+
translate({
|
|
6270
|
+
languagePath,
|
|
6271
|
+
translatePath: path,
|
|
6272
|
+
documentId: documentId != null ? documentId : ""
|
|
6273
|
+
});
|
|
6274
|
+
},
|
|
6275
|
+
renderAsButton: true,
|
|
6276
|
+
disabled: translationApi.loading || !languageId ? {
|
|
6277
|
+
reason: "Language is not set for this document"
|
|
6278
|
+
} : void 0
|
|
6279
|
+
});
|
|
6280
|
+
}, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled, path]);
|
|
6261
6281
|
const fieldTranslate = useFieldTranslation();
|
|
6262
6282
|
const openFieldTranslation = useDraftDelayedTask({
|
|
6263
6283
|
documentOnChange,
|
|
@@ -6276,24 +6296,25 @@ const translateActions = {
|
|
|
6276
6296
|
}
|
|
6277
6297
|
})
|
|
6278
6298
|
}) : TranslateIcon,
|
|
6279
|
-
title: "Translate fields",
|
|
6299
|
+
title: "Translate fields...",
|
|
6280
6300
|
onAction: () => {
|
|
6281
6301
|
if (fieldTranslate.translationLoading || !documentId) {
|
|
6282
6302
|
return;
|
|
6283
6303
|
}
|
|
6284
6304
|
openFieldTranslation({
|
|
6285
6305
|
document: docRef.current,
|
|
6286
|
-
documentSchema:
|
|
6306
|
+
documentSchema: documentSchemaType,
|
|
6307
|
+
translatePath: path
|
|
6287
6308
|
});
|
|
6288
6309
|
},
|
|
6289
6310
|
renderAsButton: true,
|
|
6290
6311
|
disabled: fieldTranslate.translationLoading
|
|
6291
|
-
}) : void 0, [openFieldTranslation,
|
|
6312
|
+
}) : void 0, [openFieldTranslation, documentSchemaType, documentId, fieldTranslate.translationLoading, fieldTransEnabled, path]);
|
|
6292
6313
|
return useMemo(() => {
|
|
6293
6314
|
return node$1({
|
|
6294
6315
|
type: "group",
|
|
6295
6316
|
icon: () => null,
|
|
6296
|
-
title: "
|
|
6317
|
+
title: "Translation",
|
|
6297
6318
|
children: [translateDocumentAction, translateFieldsAction].filter(c => !!c),
|
|
6298
6319
|
expanded: true
|
|
6299
6320
|
});
|
|
@@ -6361,7 +6382,8 @@ const assistFieldActions = {
|
|
|
6361
6382
|
const translateAction = translateActions.useAction(typed({
|
|
6362
6383
|
...props,
|
|
6363
6384
|
documentId: assistableDocumentId,
|
|
6364
|
-
documentIsAssistable
|
|
6385
|
+
documentIsAssistable,
|
|
6386
|
+
documentSchemaType
|
|
6365
6387
|
}));
|
|
6366
6388
|
const manageInstructions = useCallback(() => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
|
|
6367
6389
|
[fieldPathParam]: pathKey,
|
|
@@ -6416,7 +6438,7 @@ const assistFieldActions = {
|
|
|
6416
6438
|
type: "group",
|
|
6417
6439
|
icon: SparklesIcon,
|
|
6418
6440
|
title: pluginTitleShort,
|
|
6419
|
-
children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c),
|
|
6441
|
+
children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c).filter(c => c.type === "group" ? c.children.length : true),
|
|
6420
6442
|
expanded: false,
|
|
6421
6443
|
renderAsButton: true,
|
|
6422
6444
|
hidden: !assistSupported && !imageCaptionAction && !translateAction
|
|
@@ -6545,18 +6567,34 @@ function AssistDocumentInputWrapper(props) {
|
|
|
6545
6567
|
documentId
|
|
6546
6568
|
});
|
|
6547
6569
|
}
|
|
6548
|
-
function AssistDocumentInput(
|
|
6570
|
+
function AssistDocumentInput(_ref22) {
|
|
6549
6571
|
let {
|
|
6550
6572
|
documentId,
|
|
6551
6573
|
...props
|
|
6552
|
-
} =
|
|
6574
|
+
} = _ref22;
|
|
6553
6575
|
useInstructionToaster(documentId, props.schemaType);
|
|
6576
|
+
const schemaType = useMemo(() => {
|
|
6577
|
+
if (props.schemaType.name !== assistDocumentTypeName) {
|
|
6578
|
+
return props.schemaType;
|
|
6579
|
+
}
|
|
6580
|
+
return {
|
|
6581
|
+
...props.schemaType,
|
|
6582
|
+
type: {
|
|
6583
|
+
...props.schemaType.type,
|
|
6584
|
+
// compatability with i18nArrays plugin that requires this to be document
|
|
6585
|
+
name: "document"
|
|
6586
|
+
}
|
|
6587
|
+
};
|
|
6588
|
+
}, [props.schemaType]);
|
|
6554
6589
|
return /* @__PURE__ */jsx(FirstAssistedPathProvider, {
|
|
6555
6590
|
members: props.members,
|
|
6556
6591
|
children: /* @__PURE__ */jsx(AssistDocumentContextProvider, {
|
|
6557
|
-
schemaType
|
|
6592
|
+
schemaType,
|
|
6558
6593
|
documentId,
|
|
6559
|
-
children: props.renderDefault(
|
|
6594
|
+
children: props.renderDefault({
|
|
6595
|
+
...props,
|
|
6596
|
+
schemaType
|
|
6597
|
+
})
|
|
6560
6598
|
})
|
|
6561
6599
|
});
|
|
6562
6600
|
}
|
|
@@ -6632,29 +6670,36 @@ const assist = definePlugin(config => {
|
|
|
6632
6670
|
},
|
|
6633
6671
|
document: {
|
|
6634
6672
|
inspectors: (prev, context) => {
|
|
6635
|
-
const
|
|
6673
|
+
const documentType = context.documentType;
|
|
6674
|
+
const docSchema = context.schema.get(documentType);
|
|
6636
6675
|
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
6637
6676
|
return [...prev, assistInspector];
|
|
6638
6677
|
}
|
|
6639
6678
|
return prev;
|
|
6640
6679
|
},
|
|
6641
|
-
unstable_fieldActions: (prev,
|
|
6680
|
+
unstable_fieldActions: (prev, _ref23) => {
|
|
6642
6681
|
let {
|
|
6643
6682
|
documentType,
|
|
6644
6683
|
schema
|
|
6645
|
-
} =
|
|
6684
|
+
} = _ref23;
|
|
6685
|
+
if (documentType === assistDocumentTypeName) {
|
|
6686
|
+
return [];
|
|
6687
|
+
}
|
|
6646
6688
|
const docSchema = schema.get(documentType);
|
|
6647
6689
|
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
6648
6690
|
return [...prev, assistFieldActions];
|
|
6649
6691
|
}
|
|
6650
6692
|
return prev;
|
|
6651
6693
|
},
|
|
6652
|
-
unstable_languageFilter: (prev,
|
|
6694
|
+
unstable_languageFilter: (prev, _ref24) => {
|
|
6653
6695
|
let {
|
|
6654
6696
|
documentId,
|
|
6655
6697
|
schema,
|
|
6656
6698
|
schemaType
|
|
6657
|
-
} =
|
|
6699
|
+
} = _ref24;
|
|
6700
|
+
if (schemaType === assistDocumentTypeName) {
|
|
6701
|
+
return [];
|
|
6702
|
+
}
|
|
6658
6703
|
const docSchema = schema.get(schemaType);
|
|
6659
6704
|
if (docSchema && isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
|
|
6660
6705
|
return [...prev, createAssistDocumentPresence(documentId, docSchema)];
|