@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.js
CHANGED
|
@@ -984,6 +984,7 @@ function useTranslate(apiClient) {
|
|
|
984
984
|
let {
|
|
985
985
|
documentId,
|
|
986
986
|
languagePath,
|
|
987
|
+
translatePath,
|
|
987
988
|
fieldLanguageMap
|
|
988
989
|
} = _ref4;
|
|
989
990
|
setLoading(true);
|
|
@@ -995,6 +996,7 @@ function useTranslate(apiClient) {
|
|
|
995
996
|
types,
|
|
996
997
|
languagePath,
|
|
997
998
|
fieldLanguageMap,
|
|
999
|
+
translatePath: translatePath.length === 0 ? documentRootKey : sanity.pathToString(translatePath),
|
|
998
1000
|
userId: user == null ? void 0 : user.id
|
|
999
1001
|
}
|
|
1000
1002
|
}).catch(e => {
|
|
@@ -3329,7 +3331,7 @@ const defaultLanguageOutputs = function (member, enclosingType, translateFromLan
|
|
|
3329
3331
|
}
|
|
3330
3332
|
return void 0;
|
|
3331
3333
|
};
|
|
3332
|
-
function
|
|
3334
|
+
function getFieldLanguageMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
|
|
3333
3335
|
var _a, _b, _c;
|
|
3334
3336
|
const translationMaps = [];
|
|
3335
3337
|
for (const member of documentMembers) {
|
|
@@ -4561,13 +4563,12 @@ const getLanguageParams = (select, document) => {
|
|
|
4561
4563
|
const FieldTranslationContext = react.createContext({
|
|
4562
4564
|
openFieldTranslation: () => {},
|
|
4563
4565
|
translationLoading: false
|
|
4564
|
-
//loadLanguages: () => {},
|
|
4565
4566
|
});
|
|
4566
4567
|
function useFieldTranslation() {
|
|
4567
4568
|
return react.useContext(FieldTranslationContext);
|
|
4568
4569
|
}
|
|
4569
4570
|
function FieldTranslationProvider(props) {
|
|
4570
|
-
var _a, _b;
|
|
4571
|
+
var _a, _b, _c;
|
|
4571
4572
|
const {
|
|
4572
4573
|
config: assistConfig
|
|
4573
4574
|
} = useAiAssistanceConfig();
|
|
@@ -4577,40 +4578,42 @@ function FieldTranslationProvider(props) {
|
|
|
4577
4578
|
translate: runTranslate
|
|
4578
4579
|
} = useTranslate(apiClient);
|
|
4579
4580
|
const [dialogOpen, setDialogOpen] = react.useState(false);
|
|
4580
|
-
const [
|
|
4581
|
-
const [documentSchema, setDocumentSchema] = react.useState();
|
|
4581
|
+
const [fieldTranslationParams, setFieldTranslationParams] = react.useState();
|
|
4582
4582
|
const [languages, setLanguages] = react.useState();
|
|
4583
4583
|
const [fromLanguage, setFromLanguage] = react.useState(void 0);
|
|
4584
4584
|
const [toLanguages, setToLanguages] = react.useState(void 0);
|
|
4585
|
-
const [
|
|
4585
|
+
const [fieldLanguageMaps, setFieldLanguageMaps] = react.useState();
|
|
4586
4586
|
const close = react.useCallback(() => {
|
|
4587
4587
|
setDialogOpen(false);
|
|
4588
4588
|
setLanguages(void 0);
|
|
4589
|
-
|
|
4590
|
-
setDocument(void 0);
|
|
4589
|
+
setFieldTranslationParams(void 0);
|
|
4591
4590
|
}, []);
|
|
4592
4591
|
const languageClient = sanity.useClient({
|
|
4593
4592
|
apiVersion: (_b = config == null ? void 0 : config.apiVersion) != null ? _b : "2022-11-27"
|
|
4594
4593
|
});
|
|
4595
|
-
const documentId = document == null ? void 0 :
|
|
4594
|
+
const documentId = (_c = fieldTranslationParams == null ? void 0 : fieldTranslationParams.document) == null ? void 0 : _c._id;
|
|
4596
4595
|
const id = react.useId();
|
|
4597
|
-
const selectFromLanguage = react.useCallback((from, languages2,
|
|
4596
|
+
const selectFromLanguage = react.useCallback((from, languages2, params) => {
|
|
4598
4597
|
var _a2, _b2;
|
|
4598
|
+
const {
|
|
4599
|
+
document,
|
|
4600
|
+
documentSchema
|
|
4601
|
+
} = params != null ? params : {};
|
|
4599
4602
|
setFromLanguage(from);
|
|
4600
|
-
if (!
|
|
4601
|
-
|
|
4603
|
+
if (!document || !documentSchema || !params || !languages2) {
|
|
4604
|
+
setFieldLanguageMaps(void 0);
|
|
4602
4605
|
return;
|
|
4603
4606
|
}
|
|
4604
4607
|
const to = languages2.filter(l => l.id !== (from == null ? void 0 : from.id));
|
|
4605
4608
|
setToLanguages(to);
|
|
4606
4609
|
const fromId = from == null ? void 0 : from.id;
|
|
4607
4610
|
const toIds = (_a2 = to == null ? void 0 : to.map(l => l.id)) != null ? _a2 : [];
|
|
4608
|
-
const docMembers = getDocumentMembersFlat(
|
|
4611
|
+
const docMembers = getDocumentMembersFlat(document, documentSchema);
|
|
4609
4612
|
if (fromId && (toIds == null ? void 0 : toIds.length)) {
|
|
4610
|
-
const transMap =
|
|
4611
|
-
|
|
4613
|
+
const transMap = getFieldLanguageMap(documentSchema, docMembers, fromId, toIds, (_b2 = config == null ? void 0 : config.translationOutputs) != null ? _b2 : defaultLanguageOutputs);
|
|
4614
|
+
setFieldLanguageMaps(transMap);
|
|
4612
4615
|
} else {
|
|
4613
|
-
|
|
4616
|
+
setFieldLanguageMaps(void 0);
|
|
4614
4617
|
}
|
|
4615
4618
|
}, [config]);
|
|
4616
4619
|
const toggleToLanguage = react.useCallback((toggledLang, toLanguages2, languages2) => {
|
|
@@ -4621,20 +4624,15 @@ function FieldTranslationProvider(props) {
|
|
|
4621
4624
|
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);
|
|
4622
4625
|
setToLanguages(newToLangs);
|
|
4623
4626
|
}, []);
|
|
4624
|
-
const openFieldTranslation = react.useCallback(async
|
|
4625
|
-
let {
|
|
4626
|
-
document: document2,
|
|
4627
|
-
documentSchema: documentSchema2
|
|
4628
|
-
} = _ref11;
|
|
4627
|
+
const openFieldTranslation = react.useCallback(async params => {
|
|
4629
4628
|
setDialogOpen(true);
|
|
4630
|
-
const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams,
|
|
4629
|
+
const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams, params.document);
|
|
4631
4630
|
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));
|
|
4632
4631
|
setLanguages(languages2);
|
|
4633
|
-
|
|
4634
|
-
setDocumentSchema(documentSchema2);
|
|
4632
|
+
setFieldTranslationParams(params);
|
|
4635
4633
|
const fromLanguage2 = languages2 == null ? void 0 : languages2[0];
|
|
4636
4634
|
if (fromLanguage2) {
|
|
4637
|
-
selectFromLanguage(fromLanguage2, languages2,
|
|
4635
|
+
selectFromLanguage(fromLanguage2, languages2, params);
|
|
4638
4636
|
} else {
|
|
4639
4637
|
console.error("No languages available for selected language params", languageParams);
|
|
4640
4638
|
}
|
|
@@ -4645,12 +4643,14 @@ function FieldTranslationProvider(props) {
|
|
|
4645
4643
|
translationLoading: false
|
|
4646
4644
|
};
|
|
4647
4645
|
}, [openFieldTranslation]);
|
|
4648
|
-
const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(
|
|
4646
|
+
const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(fieldLanguageMaps == null ? void 0 : fieldLanguageMaps.length) || !documentId;
|
|
4649
4647
|
const onRunTranslation = react.useCallback(() => {
|
|
4650
|
-
|
|
4648
|
+
const translatePath = fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath;
|
|
4649
|
+
if (fieldLanguageMaps && documentId && translatePath) {
|
|
4651
4650
|
runTranslate({
|
|
4652
4651
|
documentId,
|
|
4653
|
-
|
|
4652
|
+
translatePath: fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath,
|
|
4653
|
+
fieldLanguageMap: fieldLanguageMaps.map(map => ({
|
|
4654
4654
|
...map,
|
|
4655
4655
|
// eslint-disable-next-line max-nested-callbacks
|
|
4656
4656
|
outputs: map.outputs.filter(out => !!(toLanguages == null ? void 0 : toLanguages.find(l => l.id === out.id)))
|
|
@@ -4658,7 +4658,7 @@ function FieldTranslationProvider(props) {
|
|
|
4658
4658
|
});
|
|
4659
4659
|
}
|
|
4660
4660
|
close();
|
|
4661
|
-
}, [
|
|
4661
|
+
}, [fieldLanguageMaps, documentId, runTranslate, close, toLanguages, fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath]);
|
|
4662
4662
|
const runButton = /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
4663
4663
|
text: "Translate",
|
|
4664
4664
|
tone: "primary",
|
|
@@ -4717,7 +4717,7 @@ function FieldTranslationProvider(props) {
|
|
|
4717
4717
|
name: "fromLang",
|
|
4718
4718
|
value: l.id,
|
|
4719
4719
|
checked: l.id === (fromLanguage == null ? void 0 : fromLanguage.id),
|
|
4720
|
-
onClick: () => selectFromLanguage(l, languages,
|
|
4720
|
+
onClick: () => selectFromLanguage(l, languages, fieldTranslationParams)
|
|
4721
4721
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
4722
4722
|
children: (_a2 = l.title) != null ? _a2 : l.id
|
|
4723
4723
|
})]
|
|
@@ -4741,7 +4741,7 @@ function FieldTranslationProvider(props) {
|
|
|
4741
4741
|
value: l.id,
|
|
4742
4742
|
checked: !!(toLanguages == null ? void 0 : toLanguages.find(tl => tl.id === l.id)),
|
|
4743
4743
|
onClick: () => toggleToLanguage(l, toLanguages, languages),
|
|
4744
|
-
disabled: !(
|
|
4744
|
+
disabled: !(fieldLanguageMaps == null ? void 0 : fieldLanguageMaps.find(tm => tm.outputs.find(o => o.id === l.id)))
|
|
4745
4745
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
4746
4746
|
children: (_a2 = l.title) != null ? _a2 : l.id
|
|
4747
4747
|
})]
|
|
@@ -4806,7 +4806,10 @@ function ErrorWrapper(props) {
|
|
|
4806
4806
|
const catchError = react.useCallback(params => {
|
|
4807
4807
|
setError(params.error);
|
|
4808
4808
|
}, [setError]);
|
|
4809
|
-
const unsetValue = react.useCallback(() =>
|
|
4809
|
+
const unsetValue = react.useCallback(() => {
|
|
4810
|
+
onChange(sanity.PatchEvent.from(sanity.unset()));
|
|
4811
|
+
setError(void 0);
|
|
4812
|
+
}, [onChange]);
|
|
4810
4813
|
const dismiss = react.useCallback(() => setError(void 0), []);
|
|
4811
4814
|
const catcher = /* @__PURE__ */jsxRuntime.jsx(ui.ErrorBoundary, {
|
|
4812
4815
|
onCatch: catchError,
|
|
@@ -4938,11 +4941,11 @@ function InstructionInput(props) {
|
|
|
4938
4941
|
})]
|
|
4939
4942
|
});
|
|
4940
4943
|
}
|
|
4941
|
-
function ObjectMember(
|
|
4944
|
+
function ObjectMember(_ref11) {
|
|
4942
4945
|
let {
|
|
4943
4946
|
fieldName,
|
|
4944
4947
|
...props
|
|
4945
|
-
} =
|
|
4948
|
+
} = _ref11;
|
|
4946
4949
|
const member = findFieldMember(props.members, fieldName);
|
|
4947
4950
|
return member ? /* @__PURE__ */jsxRuntime.jsx(sanity.ObjectInputMember, {
|
|
4948
4951
|
...props,
|
|
@@ -5081,8 +5084,8 @@ function IconInput(props) {
|
|
|
5081
5084
|
onChange
|
|
5082
5085
|
} = props;
|
|
5083
5086
|
const id = react.useId();
|
|
5084
|
-
const items = react.useMemo(() => Object.entries(icons.icons).map(
|
|
5085
|
-
let [key, icon] =
|
|
5087
|
+
const items = react.useMemo(() => Object.entries(icons.icons).map(_ref12 => {
|
|
5088
|
+
let [key, icon] = _ref12;
|
|
5086
5089
|
return /* @__PURE__ */jsxRuntime.jsx(IconItem, {
|
|
5087
5090
|
iconKey: key,
|
|
5088
5091
|
icon,
|
|
@@ -5110,12 +5113,12 @@ function IconInput(props) {
|
|
|
5110
5113
|
}
|
|
5111
5114
|
});
|
|
5112
5115
|
}
|
|
5113
|
-
function IconItem(
|
|
5116
|
+
function IconItem(_ref13) {
|
|
5114
5117
|
let {
|
|
5115
5118
|
icon,
|
|
5116
5119
|
iconKey: key,
|
|
5117
5120
|
onChange
|
|
5118
|
-
} =
|
|
5121
|
+
} = _ref13;
|
|
5119
5122
|
const onClick = react.useCallback(() => onChange(sanity.set(key)), [onChange, key]);
|
|
5120
5123
|
return /* @__PURE__ */jsxRuntime.jsx(ui.MenuItem, {
|
|
5121
5124
|
icon,
|
|
@@ -5126,8 +5129,8 @@ function IconItem(_ref14) {
|
|
|
5126
5129
|
}
|
|
5127
5130
|
function getIcon(iconName) {
|
|
5128
5131
|
var _a, _b;
|
|
5129
|
-
return (_b = (_a = Object.entries(icons.icons).find(
|
|
5130
|
-
let [key] =
|
|
5132
|
+
return (_b = (_a = Object.entries(icons.icons).find(_ref14 => {
|
|
5133
|
+
let [key] = _ref14;
|
|
5131
5134
|
return key === iconName;
|
|
5132
5135
|
})) == null ? void 0 : _a[1]) != null ? _b : icons.icons.sparkles;
|
|
5133
5136
|
}
|
|
@@ -5286,11 +5289,11 @@ const contextDocumentSchema = sanity.defineType({
|
|
|
5286
5289
|
title: "title",
|
|
5287
5290
|
context: "context"
|
|
5288
5291
|
},
|
|
5289
|
-
prepare(
|
|
5292
|
+
prepare(_ref15) {
|
|
5290
5293
|
let {
|
|
5291
5294
|
title,
|
|
5292
5295
|
context
|
|
5293
|
-
} =
|
|
5296
|
+
} = _ref15;
|
|
5294
5297
|
var _a;
|
|
5295
5298
|
const text = context == null ? void 0 : context.flatMap(block => block == null ? void 0 : block.children).flatMap(child => {
|
|
5296
5299
|
var _a2;
|
|
@@ -5390,11 +5393,11 @@ function InstructionOutputField(props) {
|
|
|
5390
5393
|
children: props.children
|
|
5391
5394
|
});
|
|
5392
5395
|
}
|
|
5393
|
-
function EnabledOutputField(
|
|
5396
|
+
function EnabledOutputField(_ref16) {
|
|
5394
5397
|
let {
|
|
5395
5398
|
fieldSchema,
|
|
5396
5399
|
...props
|
|
5397
|
-
} =
|
|
5400
|
+
} = _ref16;
|
|
5398
5401
|
var _a;
|
|
5399
5402
|
const [open, setOpen] = react.useState(!!((_a = props.value) == null ? void 0 : _a.length));
|
|
5400
5403
|
const onExpand = react.useCallback(() => setOpen(true), []);
|
|
@@ -5442,11 +5445,11 @@ function useEmptySelectAllValue(value, allowedValues, onChange) {
|
|
|
5442
5445
|
}
|
|
5443
5446
|
}, [allowedValues, value, onChange]);
|
|
5444
5447
|
}
|
|
5445
|
-
function ObjectOutputInput(
|
|
5448
|
+
function ObjectOutputInput(_ref17) {
|
|
5446
5449
|
let {
|
|
5447
5450
|
fieldSchema,
|
|
5448
5451
|
...props
|
|
5449
|
-
} =
|
|
5452
|
+
} = _ref17;
|
|
5450
5453
|
const {
|
|
5451
5454
|
value,
|
|
5452
5455
|
onChange
|
|
@@ -5493,11 +5496,11 @@ function ObjectOutputInput(_ref18) {
|
|
|
5493
5496
|
})
|
|
5494
5497
|
});
|
|
5495
5498
|
}
|
|
5496
|
-
function ArrayOutputInput(
|
|
5499
|
+
function ArrayOutputInput(_ref18) {
|
|
5497
5500
|
let {
|
|
5498
5501
|
fieldSchema,
|
|
5499
5502
|
...props
|
|
5500
|
-
} =
|
|
5503
|
+
} = _ref18;
|
|
5501
5504
|
const {
|
|
5502
5505
|
value,
|
|
5503
5506
|
onChange
|
|
@@ -5542,13 +5545,13 @@ function ArrayOutputInput(_ref19) {
|
|
|
5542
5545
|
})
|
|
5543
5546
|
});
|
|
5544
5547
|
}
|
|
5545
|
-
function Selectable(
|
|
5548
|
+
function Selectable(_ref19) {
|
|
5546
5549
|
let {
|
|
5547
5550
|
title,
|
|
5548
5551
|
arrayValue,
|
|
5549
5552
|
value,
|
|
5550
5553
|
onChange
|
|
5551
|
-
} =
|
|
5554
|
+
} = _ref19;
|
|
5552
5555
|
const checked = !(arrayValue == null ? void 0 : arrayValue.length) || !!(arrayValue == null ? void 0 : arrayValue.find(v => v._key === value));
|
|
5553
5556
|
const handleChange = react.useCallback(() => onChange(checked, value), [onChange, checked, value]);
|
|
5554
5557
|
return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
@@ -5613,10 +5616,10 @@ const fieldReference = sanity.defineType({
|
|
|
5613
5616
|
select: {
|
|
5614
5617
|
path: "path"
|
|
5615
5618
|
},
|
|
5616
|
-
prepare(
|
|
5619
|
+
prepare(_ref20) {
|
|
5617
5620
|
let {
|
|
5618
5621
|
path
|
|
5619
|
-
} =
|
|
5622
|
+
} = _ref20;
|
|
5620
5623
|
return {
|
|
5621
5624
|
title: path,
|
|
5622
5625
|
path,
|
|
@@ -5761,12 +5764,12 @@ const instruction = sanity.defineType({
|
|
|
5761
5764
|
title: "title",
|
|
5762
5765
|
userId: "userId"
|
|
5763
5766
|
},
|
|
5764
|
-
prepare:
|
|
5767
|
+
prepare: _ref21 => {
|
|
5765
5768
|
let {
|
|
5766
5769
|
icon,
|
|
5767
5770
|
title,
|
|
5768
5771
|
userId
|
|
5769
|
-
} =
|
|
5772
|
+
} = _ref21;
|
|
5770
5773
|
return {
|
|
5771
5774
|
title,
|
|
5772
5775
|
icon: icon ? icons.icons[icon] : icons.SparklesIcon,
|
|
@@ -6218,21 +6221,25 @@ function node$1(node2) {
|
|
|
6218
6221
|
const translateActions = {
|
|
6219
6222
|
name: "sanity-assist-translate",
|
|
6220
6223
|
useAction(props) {
|
|
6221
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
6224
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6222
6225
|
const {
|
|
6223
6226
|
config
|
|
6224
6227
|
} = useAiAssistanceConfig();
|
|
6225
6228
|
const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
|
|
6226
|
-
const isDocumentLevel = props.path.length === 0;
|
|
6227
6229
|
const {
|
|
6228
|
-
schemaType,
|
|
6230
|
+
schemaType: fieldSchemaType,
|
|
6231
|
+
path,
|
|
6229
6232
|
documentId,
|
|
6233
|
+
documentSchemaType,
|
|
6230
6234
|
documentIsAssistable
|
|
6231
6235
|
} = props;
|
|
6232
|
-
const
|
|
6233
|
-
const docTransTypes = (
|
|
6234
|
-
const
|
|
6235
|
-
|
|
6236
|
+
const isDocumentLevel = path.length === 0;
|
|
6237
|
+
const docTransTypes = (_b = (_a = config.translate) == null ? void 0 : _a.document) == null ? void 0 : _b.documentTypes;
|
|
6238
|
+
const options = fieldSchemaType == null ? void 0 : fieldSchemaType.options;
|
|
6239
|
+
const addFieldAction = isDocumentLevel || ((_c = options == null ? void 0 : options.aiWritingAssistance) == null ? void 0 : _c.translateAction);
|
|
6240
|
+
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));
|
|
6241
|
+
const documentTranslationEnabled = addFieldAction && documentSchemaType && (!docTransTypes && isAssistSupported(fieldSchemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(documentSchemaType.name)));
|
|
6242
|
+
if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
|
|
6236
6243
|
const {
|
|
6237
6244
|
value: documentValue,
|
|
6238
6245
|
onChange: documentOnChange
|
|
@@ -6245,32 +6252,45 @@ const translateActions = {
|
|
|
6245
6252
|
task: translationApi.translate
|
|
6246
6253
|
});
|
|
6247
6254
|
docRef.current = documentValue;
|
|
6248
|
-
const languagePath = (
|
|
6249
|
-
const translateDocumentAction = react.useMemo(() =>
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6255
|
+
const languagePath = (_h = (_g = config.translate) == null ? void 0 : _g.document) == null ? void 0 : _h.languageField;
|
|
6256
|
+
const translateDocumentAction = react.useMemo(() => {
|
|
6257
|
+
var _a2;
|
|
6258
|
+
if (!languagePath || !documentTranslationEnabled) {
|
|
6259
|
+
return void 0;
|
|
6260
|
+
}
|
|
6261
|
+
const {
|
|
6262
|
+
value: languageId
|
|
6263
|
+
} = (_a2 = mutator.extractWithPath(languagePath, documentValue)[0]) != null ? _a2 : {};
|
|
6264
|
+
const title = path.length ? "Translate" : "Translate document";
|
|
6265
|
+
return node$1({
|
|
6266
|
+
type: "action",
|
|
6267
|
+
icon: translationApi.loading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
6256
6268
|
style: {
|
|
6257
|
-
|
|
6269
|
+
height: 17
|
|
6270
|
+
},
|
|
6271
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
|
|
6272
|
+
style: {
|
|
6273
|
+
transform: "translateY(6px)"
|
|
6274
|
+
}
|
|
6275
|
+
})
|
|
6276
|
+
}) : icons.TranslateIcon,
|
|
6277
|
+
title,
|
|
6278
|
+
onAction: () => {
|
|
6279
|
+
if (translationApi.loading || !languagePath || !documentId) {
|
|
6280
|
+
return;
|
|
6258
6281
|
}
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
renderAsButton: true,
|
|
6272
|
-
disabled: translationApi.loading
|
|
6273
|
-
}) : void 0, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled]);
|
|
6282
|
+
translate({
|
|
6283
|
+
languagePath,
|
|
6284
|
+
translatePath: path,
|
|
6285
|
+
documentId: documentId != null ? documentId : ""
|
|
6286
|
+
});
|
|
6287
|
+
},
|
|
6288
|
+
renderAsButton: true,
|
|
6289
|
+
disabled: translationApi.loading || !languageId ? {
|
|
6290
|
+
reason: "Language is not set for this document"
|
|
6291
|
+
} : void 0
|
|
6292
|
+
});
|
|
6293
|
+
}, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled, path]);
|
|
6274
6294
|
const fieldTranslate = useFieldTranslation();
|
|
6275
6295
|
const openFieldTranslation = useDraftDelayedTask({
|
|
6276
6296
|
documentOnChange,
|
|
@@ -6289,24 +6309,25 @@ const translateActions = {
|
|
|
6289
6309
|
}
|
|
6290
6310
|
})
|
|
6291
6311
|
}) : icons.TranslateIcon,
|
|
6292
|
-
title: "Translate fields",
|
|
6312
|
+
title: "Translate fields...",
|
|
6293
6313
|
onAction: () => {
|
|
6294
6314
|
if (fieldTranslate.translationLoading || !documentId) {
|
|
6295
6315
|
return;
|
|
6296
6316
|
}
|
|
6297
6317
|
openFieldTranslation({
|
|
6298
6318
|
document: docRef.current,
|
|
6299
|
-
documentSchema:
|
|
6319
|
+
documentSchema: documentSchemaType,
|
|
6320
|
+
translatePath: path
|
|
6300
6321
|
});
|
|
6301
6322
|
},
|
|
6302
6323
|
renderAsButton: true,
|
|
6303
6324
|
disabled: fieldTranslate.translationLoading
|
|
6304
|
-
}) : void 0, [openFieldTranslation,
|
|
6325
|
+
}) : void 0, [openFieldTranslation, documentSchemaType, documentId, fieldTranslate.translationLoading, fieldTransEnabled, path]);
|
|
6305
6326
|
return react.useMemo(() => {
|
|
6306
6327
|
return node$1({
|
|
6307
6328
|
type: "group",
|
|
6308
6329
|
icon: () => null,
|
|
6309
|
-
title: "
|
|
6330
|
+
title: "Translation",
|
|
6310
6331
|
children: [translateDocumentAction, translateFieldsAction].filter(c => !!c),
|
|
6311
6332
|
expanded: true
|
|
6312
6333
|
});
|
|
@@ -6374,7 +6395,8 @@ const assistFieldActions = {
|
|
|
6374
6395
|
const translateAction = translateActions.useAction(sanity.typed({
|
|
6375
6396
|
...props,
|
|
6376
6397
|
documentId: assistableDocumentId,
|
|
6377
|
-
documentIsAssistable
|
|
6398
|
+
documentIsAssistable,
|
|
6399
|
+
documentSchemaType
|
|
6378
6400
|
}));
|
|
6379
6401
|
const manageInstructions = react.useCallback(() => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
|
|
6380
6402
|
[fieldPathParam]: pathKey,
|
|
@@ -6429,7 +6451,7 @@ const assistFieldActions = {
|
|
|
6429
6451
|
type: "group",
|
|
6430
6452
|
icon: icons.SparklesIcon,
|
|
6431
6453
|
title: pluginTitleShort,
|
|
6432
|
-
children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c),
|
|
6454
|
+
children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c).filter(c => c.type === "group" ? c.children.length : true),
|
|
6433
6455
|
expanded: false,
|
|
6434
6456
|
renderAsButton: true,
|
|
6435
6457
|
hidden: !assistSupported && !imageCaptionAction && !translateAction
|
|
@@ -6558,18 +6580,34 @@ function AssistDocumentInputWrapper(props) {
|
|
|
6558
6580
|
documentId
|
|
6559
6581
|
});
|
|
6560
6582
|
}
|
|
6561
|
-
function AssistDocumentInput(
|
|
6583
|
+
function AssistDocumentInput(_ref22) {
|
|
6562
6584
|
let {
|
|
6563
6585
|
documentId,
|
|
6564
6586
|
...props
|
|
6565
|
-
} =
|
|
6587
|
+
} = _ref22;
|
|
6566
6588
|
useInstructionToaster(documentId, props.schemaType);
|
|
6589
|
+
const schemaType = react.useMemo(() => {
|
|
6590
|
+
if (props.schemaType.name !== assistDocumentTypeName) {
|
|
6591
|
+
return props.schemaType;
|
|
6592
|
+
}
|
|
6593
|
+
return {
|
|
6594
|
+
...props.schemaType,
|
|
6595
|
+
type: {
|
|
6596
|
+
...props.schemaType.type,
|
|
6597
|
+
// compatability with i18nArrays plugin that requires this to be document
|
|
6598
|
+
name: "document"
|
|
6599
|
+
}
|
|
6600
|
+
};
|
|
6601
|
+
}, [props.schemaType]);
|
|
6567
6602
|
return /* @__PURE__ */jsxRuntime.jsx(FirstAssistedPathProvider, {
|
|
6568
6603
|
members: props.members,
|
|
6569
6604
|
children: /* @__PURE__ */jsxRuntime.jsx(AssistDocumentContextProvider, {
|
|
6570
|
-
schemaType
|
|
6605
|
+
schemaType,
|
|
6571
6606
|
documentId,
|
|
6572
|
-
children: props.renderDefault(
|
|
6607
|
+
children: props.renderDefault({
|
|
6608
|
+
...props,
|
|
6609
|
+
schemaType
|
|
6610
|
+
})
|
|
6573
6611
|
})
|
|
6574
6612
|
});
|
|
6575
6613
|
}
|
|
@@ -6645,29 +6683,36 @@ const assist = sanity.definePlugin(config => {
|
|
|
6645
6683
|
},
|
|
6646
6684
|
document: {
|
|
6647
6685
|
inspectors: (prev, context) => {
|
|
6648
|
-
const
|
|
6686
|
+
const documentType = context.documentType;
|
|
6687
|
+
const docSchema = context.schema.get(documentType);
|
|
6649
6688
|
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
6650
6689
|
return [...prev, assistInspector];
|
|
6651
6690
|
}
|
|
6652
6691
|
return prev;
|
|
6653
6692
|
},
|
|
6654
|
-
unstable_fieldActions: (prev,
|
|
6693
|
+
unstable_fieldActions: (prev, _ref23) => {
|
|
6655
6694
|
let {
|
|
6656
6695
|
documentType,
|
|
6657
6696
|
schema
|
|
6658
|
-
} =
|
|
6697
|
+
} = _ref23;
|
|
6698
|
+
if (documentType === assistDocumentTypeName) {
|
|
6699
|
+
return [];
|
|
6700
|
+
}
|
|
6659
6701
|
const docSchema = schema.get(documentType);
|
|
6660
6702
|
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
6661
6703
|
return [...prev, assistFieldActions];
|
|
6662
6704
|
}
|
|
6663
6705
|
return prev;
|
|
6664
6706
|
},
|
|
6665
|
-
unstable_languageFilter: (prev,
|
|
6707
|
+
unstable_languageFilter: (prev, _ref24) => {
|
|
6666
6708
|
let {
|
|
6667
6709
|
documentId,
|
|
6668
6710
|
schema,
|
|
6669
6711
|
schemaType
|
|
6670
|
-
} =
|
|
6712
|
+
} = _ref24;
|
|
6713
|
+
if (schemaType === assistDocumentTypeName) {
|
|
6714
|
+
return [];
|
|
6715
|
+
}
|
|
6671
6716
|
const docSchema = schema.get(schemaType);
|
|
6672
6717
|
if (docSchema && sanity.isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
|
|
6673
6718
|
return [...prev, createAssistDocumentPresence(documentId, docSchema)];
|