@sanity/assist 1.2.15-lang.2 → 1.2.15-lang.4
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 +142 -22
- package/dist/index.d.ts +60 -0
- package/dist/index.esm.js +269 -101
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +269 -101
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/assistDocument/AssistDocumentInput.tsx +22 -3
- package/src/components/ImageContext.tsx +11 -5
- package/src/components/SafeValueInput.tsx +4 -1
- package/src/fieldActions/assistFieldActions.tsx +13 -5
- package/src/fieldActions/generateImageActions.tsx +58 -0
- package/src/helpers/typeUtils.ts +11 -0
- package/src/plugin.tsx +9 -1
- package/src/schemas/typeDefExtensions.ts +62 -0
- package/src/translate/FieldTranslationProvider.tsx +53 -44
- package/src/translate/languageStore.ts +18 -0
- 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 +66 -11
package/dist/index.js
CHANGED
|
@@ -150,6 +150,17 @@ function getCaptionFieldOption(schemaType) {
|
|
|
150
150
|
}
|
|
151
151
|
return getCaptionFieldOption(schemaType.type);
|
|
152
152
|
}
|
|
153
|
+
function getImagePromptFieldOption(schemaType) {
|
|
154
|
+
var _a;
|
|
155
|
+
if (!schemaType) {
|
|
156
|
+
return void 0;
|
|
157
|
+
}
|
|
158
|
+
const imagePromptField = (_a = schemaType.options) == null ? void 0 : _a.imagePromptField;
|
|
159
|
+
if (imagePromptField) {
|
|
160
|
+
return imagePromptField;
|
|
161
|
+
}
|
|
162
|
+
return getImagePromptFieldOption(schemaType.type);
|
|
163
|
+
}
|
|
153
164
|
function isSchemaAssistEnabled(type) {
|
|
154
165
|
var _a, _b;
|
|
155
166
|
return !((_b = (_a = type.options) == null ? void 0 : _a.aiWritingAssistance) == null ? void 0 : _b.exclude);
|
|
@@ -984,6 +995,7 @@ function useTranslate(apiClient) {
|
|
|
984
995
|
let {
|
|
985
996
|
documentId,
|
|
986
997
|
languagePath,
|
|
998
|
+
translatePath,
|
|
987
999
|
fieldLanguageMap
|
|
988
1000
|
} = _ref4;
|
|
989
1001
|
setLoading(true);
|
|
@@ -995,6 +1007,7 @@ function useTranslate(apiClient) {
|
|
|
995
1007
|
types,
|
|
996
1008
|
languagePath,
|
|
997
1009
|
fieldLanguageMap,
|
|
1010
|
+
translatePath: translatePath.length === 0 ? documentRootKey : sanity.pathToString(translatePath),
|
|
998
1011
|
userId: user == null ? void 0 : user.id
|
|
999
1012
|
}
|
|
1000
1013
|
}).catch(e => {
|
|
@@ -1058,6 +1071,48 @@ function useGenerateCaption(apiClient) {
|
|
|
1058
1071
|
loading
|
|
1059
1072
|
}), [generateCaption, loading]);
|
|
1060
1073
|
}
|
|
1074
|
+
function useGenerateImage(apiClient) {
|
|
1075
|
+
const [loading, setLoading] = react.useState(false);
|
|
1076
|
+
const user = sanity.useCurrentUser();
|
|
1077
|
+
const schema = sanity.useSchema();
|
|
1078
|
+
const types = react.useMemo(() => serializeSchema(schema, {
|
|
1079
|
+
leanFormat: true
|
|
1080
|
+
}), [schema]);
|
|
1081
|
+
const toast = ui.useToast();
|
|
1082
|
+
const generateImage = react.useCallback(_ref6 => {
|
|
1083
|
+
let {
|
|
1084
|
+
path,
|
|
1085
|
+
documentId
|
|
1086
|
+
} = _ref6;
|
|
1087
|
+
setLoading(true);
|
|
1088
|
+
return apiClient.request({
|
|
1089
|
+
method: "POST",
|
|
1090
|
+
url: "/assist/tasks/generate-image/".concat(apiClient.config().dataset, "?projectId=").concat(apiClient.config().projectId),
|
|
1091
|
+
body: {
|
|
1092
|
+
path,
|
|
1093
|
+
documentId,
|
|
1094
|
+
types,
|
|
1095
|
+
userId: user == null ? void 0 : user.id
|
|
1096
|
+
}
|
|
1097
|
+
}).catch(e => {
|
|
1098
|
+
toast.push({
|
|
1099
|
+
status: "error",
|
|
1100
|
+
title: "Generate image from prompt failed",
|
|
1101
|
+
description: e.message
|
|
1102
|
+
});
|
|
1103
|
+
setLoading(false);
|
|
1104
|
+
throw e;
|
|
1105
|
+
}).finally(() => {
|
|
1106
|
+
setTimeout(() => {
|
|
1107
|
+
setLoading(false);
|
|
1108
|
+
}, 2e3);
|
|
1109
|
+
});
|
|
1110
|
+
}, [setLoading, apiClient, toast, user, types]);
|
|
1111
|
+
return react.useMemo(() => ({
|
|
1112
|
+
generateImage,
|
|
1113
|
+
loading
|
|
1114
|
+
}), [generateImage, loading]);
|
|
1115
|
+
}
|
|
1061
1116
|
function useGetInstructStatus(apiClient) {
|
|
1062
1117
|
const [loading, setLoading] = react.useState(true);
|
|
1063
1118
|
const getInstructStatus = react.useCallback(async () => {
|
|
@@ -1247,8 +1302,8 @@ function RunInstructionProvider(props) {
|
|
|
1247
1302
|
runInstructionRequest({
|
|
1248
1303
|
...request,
|
|
1249
1304
|
instructionKey: instruction._key,
|
|
1250
|
-
userTexts: Object.entries(inputs).map(
|
|
1251
|
-
let [key, value] =
|
|
1305
|
+
userTexts: Object.entries(inputs).map(_ref7 => {
|
|
1306
|
+
let [key, value] = _ref7;
|
|
1252
1307
|
return {
|
|
1253
1308
|
blockKey: key,
|
|
1254
1309
|
userInput: value
|
|
@@ -1261,8 +1316,8 @@ function RunInstructionProvider(props) {
|
|
|
1261
1316
|
const open = !!runRequest;
|
|
1262
1317
|
const runDisabled = react.useMemo(() => {
|
|
1263
1318
|
var _a2, _b;
|
|
1264
|
-
return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(
|
|
1265
|
-
let [, value] =
|
|
1319
|
+
return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(_ref8 => {
|
|
1320
|
+
let [, value] = _ref8;
|
|
1266
1321
|
return !!value;
|
|
1267
1322
|
}).length;
|
|
1268
1323
|
}, [runRequest == null ? void 0 : runRequest.userInputBlocks, inputs]);
|
|
@@ -1654,13 +1709,13 @@ function useSelectedSchema(fieldPath, documentSchema) {
|
|
|
1654
1709
|
return currentSchema;
|
|
1655
1710
|
}, [documentSchema, fieldPath]);
|
|
1656
1711
|
}
|
|
1657
|
-
function FieldsInitializer(
|
|
1712
|
+
function FieldsInitializer(_ref9) {
|
|
1658
1713
|
let {
|
|
1659
1714
|
pathKey,
|
|
1660
1715
|
activePath,
|
|
1661
1716
|
fieldExists,
|
|
1662
1717
|
onChange
|
|
1663
|
-
} =
|
|
1718
|
+
} = _ref9;
|
|
1664
1719
|
const initialized = react.useRef(false);
|
|
1665
1720
|
react.useEffect(() => {
|
|
1666
1721
|
if (initialized.current || fieldExists || activePath || !pathKey) {
|
|
@@ -2188,10 +2243,10 @@ const assistInspector = {
|
|
|
2188
2243
|
showAsAction: false
|
|
2189
2244
|
}),
|
|
2190
2245
|
component: AssistInspectorWrapper,
|
|
2191
|
-
onClose(
|
|
2246
|
+
onClose(_ref10) {
|
|
2192
2247
|
let {
|
|
2193
2248
|
params
|
|
2194
|
-
} =
|
|
2249
|
+
} = _ref10;
|
|
2195
2250
|
return {
|
|
2196
2251
|
params: sanity.typed({
|
|
2197
2252
|
...params,
|
|
@@ -2264,11 +2319,11 @@ var __template$3 = (cooked, raw) => __freeze$3(__defProp$3(cooked, "raw", {
|
|
|
2264
2319
|
var _a$3, _b$1;
|
|
2265
2320
|
const fadeIn = styled.keyframes(_a$3 || (_a$3 = __template$3(["\n 0% {\n opacity: 0;\n transform: scale(0.75);\n }\n 40% {\n opacity: 0;\n transform: scale(0.75);\n }\n 100% {\n opacity: 1;\n transform: scale(1);\n }\n"])));
|
|
2266
2321
|
const FadeInDiv = styled__default.default.div(_b$1 || (_b$1 = __template$3(["\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n"])), fadeIn);
|
|
2267
|
-
const FadeInContent = react.forwardRef(function FadeInContent2(
|
|
2322
|
+
const FadeInContent = react.forwardRef(function FadeInContent2(_ref11, ref) {
|
|
2268
2323
|
let {
|
|
2269
2324
|
children,
|
|
2270
2325
|
durationMs = 250
|
|
2271
|
-
} =
|
|
2326
|
+
} = _ref11;
|
|
2272
2327
|
return /* @__PURE__ */jsxRuntime.jsx(FadeInDiv, {
|
|
2273
2328
|
ref,
|
|
2274
2329
|
style: {
|
|
@@ -3329,7 +3384,7 @@ const defaultLanguageOutputs = function (member, enclosingType, translateFromLan
|
|
|
3329
3384
|
}
|
|
3330
3385
|
return void 0;
|
|
3331
3386
|
};
|
|
3332
|
-
function
|
|
3387
|
+
function getFieldLanguageMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
|
|
3333
3388
|
var _a, _b, _c;
|
|
3334
3389
|
const translationMaps = [];
|
|
3335
3390
|
for (const member of documentMembers) {
|
|
@@ -4558,16 +4613,29 @@ const getLanguageParams = (select, document) => {
|
|
|
4558
4613
|
}
|
|
4559
4614
|
return selectedValue;
|
|
4560
4615
|
};
|
|
4616
|
+
const toFieldLanguagesKeyPrefix = "sanityStudio:assist:field-languages:from:";
|
|
4617
|
+
function getPreferredToFieldLanguages(fromLanguageId) {
|
|
4618
|
+
if (typeof localStorage === "undefined") {
|
|
4619
|
+
return [];
|
|
4620
|
+
}
|
|
4621
|
+
const value = localStorage.getItem("".concat(toFieldLanguagesKeyPrefix).concat(fromLanguageId));
|
|
4622
|
+
return value ? JSON.parse(value) : [];
|
|
4623
|
+
}
|
|
4624
|
+
function setPreferredToFieldLanguages(fromLanguageId, languageIds) {
|
|
4625
|
+
if (typeof localStorage === "undefined") {
|
|
4626
|
+
return;
|
|
4627
|
+
}
|
|
4628
|
+
localStorage.setItem("".concat(toFieldLanguagesKeyPrefix).concat(fromLanguageId), JSON.stringify(languageIds));
|
|
4629
|
+
}
|
|
4561
4630
|
const FieldTranslationContext = react.createContext({
|
|
4562
4631
|
openFieldTranslation: () => {},
|
|
4563
4632
|
translationLoading: false
|
|
4564
|
-
//loadLanguages: () => {},
|
|
4565
4633
|
});
|
|
4566
4634
|
function useFieldTranslation() {
|
|
4567
4635
|
return react.useContext(FieldTranslationContext);
|
|
4568
4636
|
}
|
|
4569
4637
|
function FieldTranslationProvider(props) {
|
|
4570
|
-
var _a, _b;
|
|
4638
|
+
var _a, _b, _c;
|
|
4571
4639
|
const {
|
|
4572
4640
|
config: assistConfig
|
|
4573
4641
|
} = useAiAssistanceConfig();
|
|
@@ -4577,64 +4645,63 @@ function FieldTranslationProvider(props) {
|
|
|
4577
4645
|
translate: runTranslate
|
|
4578
4646
|
} = useTranslate(apiClient);
|
|
4579
4647
|
const [dialogOpen, setDialogOpen] = react.useState(false);
|
|
4580
|
-
const [
|
|
4581
|
-
const [documentSchema, setDocumentSchema] = react.useState();
|
|
4648
|
+
const [fieldTranslationParams, setFieldTranslationParams] = react.useState();
|
|
4582
4649
|
const [languages, setLanguages] = react.useState();
|
|
4583
4650
|
const [fromLanguage, setFromLanguage] = react.useState(void 0);
|
|
4584
4651
|
const [toLanguages, setToLanguages] = react.useState(void 0);
|
|
4585
|
-
const [
|
|
4652
|
+
const [fieldLanguageMaps, setFieldLanguageMaps] = react.useState();
|
|
4586
4653
|
const close = react.useCallback(() => {
|
|
4587
4654
|
setDialogOpen(false);
|
|
4588
4655
|
setLanguages(void 0);
|
|
4589
|
-
|
|
4590
|
-
setDocument(void 0);
|
|
4656
|
+
setFieldTranslationParams(void 0);
|
|
4591
4657
|
}, []);
|
|
4592
4658
|
const languageClient = sanity.useClient({
|
|
4593
4659
|
apiVersion: (_b = config == null ? void 0 : config.apiVersion) != null ? _b : "2022-11-27"
|
|
4594
4660
|
});
|
|
4595
|
-
const documentId = document == null ? void 0 :
|
|
4661
|
+
const documentId = (_c = fieldTranslationParams == null ? void 0 : fieldTranslationParams.document) == null ? void 0 : _c._id;
|
|
4596
4662
|
const id = react.useId();
|
|
4597
|
-
const selectFromLanguage = react.useCallback((from, languages2,
|
|
4663
|
+
const selectFromLanguage = react.useCallback((from, languages2, params) => {
|
|
4598
4664
|
var _a2, _b2;
|
|
4665
|
+
const {
|
|
4666
|
+
document,
|
|
4667
|
+
documentSchema
|
|
4668
|
+
} = params != null ? params : {};
|
|
4599
4669
|
setFromLanguage(from);
|
|
4600
|
-
if (!
|
|
4601
|
-
|
|
4670
|
+
if (!document || !documentSchema || !params || !languages2) {
|
|
4671
|
+
setFieldLanguageMaps(void 0);
|
|
4602
4672
|
return;
|
|
4603
4673
|
}
|
|
4604
|
-
const
|
|
4674
|
+
const preferred = getPreferredToFieldLanguages(from.id);
|
|
4675
|
+
const to = languages2.filter(l => l.id !== (from == null ? void 0 : from.id)).filter(l => !preferred.length || preferred.includes(l.id));
|
|
4605
4676
|
setToLanguages(to);
|
|
4606
4677
|
const fromId = from == null ? void 0 : from.id;
|
|
4607
4678
|
const toIds = (_a2 = to == null ? void 0 : to.map(l => l.id)) != null ? _a2 : [];
|
|
4608
|
-
const docMembers = getDocumentMembersFlat(
|
|
4679
|
+
const docMembers = getDocumentMembersFlat(document, documentSchema);
|
|
4609
4680
|
if (fromId && (toIds == null ? void 0 : toIds.length)) {
|
|
4610
|
-
const transMap =
|
|
4611
|
-
|
|
4681
|
+
const transMap = getFieldLanguageMap(documentSchema, docMembers, fromId, toIds, (_b2 = config == null ? void 0 : config.translationOutputs) != null ? _b2 : defaultLanguageOutputs);
|
|
4682
|
+
setFieldLanguageMaps(transMap);
|
|
4612
4683
|
} else {
|
|
4613
|
-
|
|
4684
|
+
setFieldLanguageMaps(void 0);
|
|
4614
4685
|
}
|
|
4615
4686
|
}, [config]);
|
|
4616
4687
|
const toggleToLanguage = react.useCallback((toggledLang, toLanguages2, languages2) => {
|
|
4617
|
-
if (!languages2) {
|
|
4688
|
+
if (!languages2 || !fromLanguage) {
|
|
4618
4689
|
return;
|
|
4619
4690
|
}
|
|
4620
4691
|
const wasSelected = !!(toLanguages2 == null ? void 0 : toLanguages2.find(l => l.id === toggledLang.id));
|
|
4621
4692
|
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
4693
|
setToLanguages(newToLangs);
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
document: document2,
|
|
4627
|
-
documentSchema: documentSchema2
|
|
4628
|
-
} = _ref11;
|
|
4694
|
+
setPreferredToFieldLanguages(fromLanguage.id, newToLangs.map(l => l.id));
|
|
4695
|
+
}, [fromLanguage]);
|
|
4696
|
+
const openFieldTranslation = react.useCallback(async params => {
|
|
4629
4697
|
setDialogOpen(true);
|
|
4630
|
-
const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams,
|
|
4698
|
+
const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams, params.document);
|
|
4631
4699
|
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
4700
|
setLanguages(languages2);
|
|
4633
|
-
|
|
4634
|
-
setDocumentSchema(documentSchema2);
|
|
4701
|
+
setFieldTranslationParams(params);
|
|
4635
4702
|
const fromLanguage2 = languages2 == null ? void 0 : languages2[0];
|
|
4636
4703
|
if (fromLanguage2) {
|
|
4637
|
-
selectFromLanguage(fromLanguage2, languages2,
|
|
4704
|
+
selectFromLanguage(fromLanguage2, languages2, params);
|
|
4638
4705
|
} else {
|
|
4639
4706
|
console.error("No languages available for selected language params", languageParams);
|
|
4640
4707
|
}
|
|
@@ -4645,12 +4712,14 @@ function FieldTranslationProvider(props) {
|
|
|
4645
4712
|
translationLoading: false
|
|
4646
4713
|
};
|
|
4647
4714
|
}, [openFieldTranslation]);
|
|
4648
|
-
const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(
|
|
4715
|
+
const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(fieldLanguageMaps == null ? void 0 : fieldLanguageMaps.length) || !documentId;
|
|
4649
4716
|
const onRunTranslation = react.useCallback(() => {
|
|
4650
|
-
|
|
4717
|
+
const translatePath = fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath;
|
|
4718
|
+
if (fieldLanguageMaps && documentId && translatePath) {
|
|
4651
4719
|
runTranslate({
|
|
4652
4720
|
documentId,
|
|
4653
|
-
|
|
4721
|
+
translatePath: fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath,
|
|
4722
|
+
fieldLanguageMap: fieldLanguageMaps.map(map => ({
|
|
4654
4723
|
...map,
|
|
4655
4724
|
// eslint-disable-next-line max-nested-callbacks
|
|
4656
4725
|
outputs: map.outputs.filter(out => !!(toLanguages == null ? void 0 : toLanguages.find(l => l.id === out.id)))
|
|
@@ -4658,7 +4727,7 @@ function FieldTranslationProvider(props) {
|
|
|
4658
4727
|
});
|
|
4659
4728
|
}
|
|
4660
4729
|
close();
|
|
4661
|
-
}, [
|
|
4730
|
+
}, [fieldLanguageMaps, documentId, runTranslate, close, toLanguages, fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath]);
|
|
4662
4731
|
const runButton = /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
4663
4732
|
text: "Translate",
|
|
4664
4733
|
tone: "primary",
|
|
@@ -4717,7 +4786,7 @@ function FieldTranslationProvider(props) {
|
|
|
4717
4786
|
name: "fromLang",
|
|
4718
4787
|
value: l.id,
|
|
4719
4788
|
checked: l.id === (fromLanguage == null ? void 0 : fromLanguage.id),
|
|
4720
|
-
onClick: () => selectFromLanguage(l, languages,
|
|
4789
|
+
onClick: () => selectFromLanguage(l, languages, fieldTranslationParams)
|
|
4721
4790
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
4722
4791
|
children: (_a2 = l.title) != null ? _a2 : l.id
|
|
4723
4792
|
})]
|
|
@@ -4740,8 +4809,7 @@ function FieldTranslationProvider(props) {
|
|
|
4740
4809
|
name: "toLang",
|
|
4741
4810
|
value: l.id,
|
|
4742
4811
|
checked: !!(toLanguages == null ? void 0 : toLanguages.find(tl => tl.id === l.id)),
|
|
4743
|
-
onClick: () => toggleToLanguage(l, toLanguages, languages)
|
|
4744
|
-
disabled: !(translationMap == null ? void 0 : translationMap.find(tm => tm.outputs.find(o => o.id === l.id)))
|
|
4812
|
+
onClick: () => toggleToLanguage(l, toLanguages, languages)
|
|
4745
4813
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
4746
4814
|
children: (_a2 = l.title) != null ? _a2 : l.id
|
|
4747
4815
|
})]
|
|
@@ -4806,7 +4874,10 @@ function ErrorWrapper(props) {
|
|
|
4806
4874
|
const catchError = react.useCallback(params => {
|
|
4807
4875
|
setError(params.error);
|
|
4808
4876
|
}, [setError]);
|
|
4809
|
-
const unsetValue = react.useCallback(() =>
|
|
4877
|
+
const unsetValue = react.useCallback(() => {
|
|
4878
|
+
onChange(sanity.PatchEvent.from(sanity.unset()));
|
|
4879
|
+
setError(void 0);
|
|
4880
|
+
}, [onChange]);
|
|
4810
4881
|
const dismiss = react.useCallback(() => setError(void 0), []);
|
|
4811
4882
|
const catcher = /* @__PURE__ */jsxRuntime.jsx(ui.ErrorBoundary, {
|
|
4812
4883
|
onCatch: catchError,
|
|
@@ -6114,7 +6185,7 @@ function PrivateIcon() {
|
|
|
6114
6185
|
children: /* @__PURE__ */jsxRuntime.jsx(icons.LockIcon, {})
|
|
6115
6186
|
});
|
|
6116
6187
|
}
|
|
6117
|
-
const ImageContext = react.createContext(
|
|
6188
|
+
const ImageContext = react.createContext({});
|
|
6118
6189
|
function ImageContextProvider(props) {
|
|
6119
6190
|
var _a;
|
|
6120
6191
|
const {
|
|
@@ -6150,17 +6221,19 @@ function ImageContextProvider(props) {
|
|
|
6150
6221
|
}, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing]);
|
|
6151
6222
|
const context = react.useMemo(() => {
|
|
6152
6223
|
const captionField = getCaptionFieldOption(schemaType);
|
|
6153
|
-
|
|
6154
|
-
|
|
6224
|
+
const imagePromptField = getImagePromptFieldOption(schemaType);
|
|
6225
|
+
return {
|
|
6226
|
+
captionPath: captionField ? sanity.pathToString([...path, captionField]) : void 0,
|
|
6227
|
+
imagePromptPath: imagePromptField ? sanity.pathToString([...path, imagePromptField]) : void 0,
|
|
6155
6228
|
assetRef
|
|
6156
|
-
}
|
|
6229
|
+
};
|
|
6157
6230
|
}, [schemaType, path, assetRef]);
|
|
6158
6231
|
return /* @__PURE__ */jsxRuntime.jsx(ImageContext.Provider, {
|
|
6159
6232
|
value: context,
|
|
6160
6233
|
children: props.renderDefault(props)
|
|
6161
6234
|
});
|
|
6162
6235
|
}
|
|
6163
|
-
function node$
|
|
6236
|
+
function node$3(node2) {
|
|
6164
6237
|
return node2;
|
|
6165
6238
|
}
|
|
6166
6239
|
const generateCaptionsActions = {
|
|
@@ -6181,7 +6254,7 @@ const generateCaptionsActions = {
|
|
|
6181
6254
|
documentId
|
|
6182
6255
|
} = useAssistDocumentContext();
|
|
6183
6256
|
return react.useMemo(() => {
|
|
6184
|
-
return node$
|
|
6257
|
+
return node$3({
|
|
6185
6258
|
type: "action",
|
|
6186
6259
|
icon: loading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
6187
6260
|
style: {
|
|
@@ -6212,27 +6285,31 @@ const generateCaptionsActions = {
|
|
|
6212
6285
|
return void 0;
|
|
6213
6286
|
}
|
|
6214
6287
|
};
|
|
6215
|
-
function node$
|
|
6288
|
+
function node$2(node2) {
|
|
6216
6289
|
return node2;
|
|
6217
6290
|
}
|
|
6218
6291
|
const translateActions = {
|
|
6219
6292
|
name: "sanity-assist-translate",
|
|
6220
6293
|
useAction(props) {
|
|
6221
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
6294
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6222
6295
|
const {
|
|
6223
6296
|
config
|
|
6224
6297
|
} = useAiAssistanceConfig();
|
|
6225
6298
|
const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
|
|
6226
|
-
const isDocumentLevel = props.path.length === 0;
|
|
6227
6299
|
const {
|
|
6228
|
-
schemaType,
|
|
6300
|
+
schemaType: fieldSchemaType,
|
|
6301
|
+
path,
|
|
6229
6302
|
documentId,
|
|
6303
|
+
documentSchemaType,
|
|
6230
6304
|
documentIsAssistable
|
|
6231
6305
|
} = props;
|
|
6232
|
-
const
|
|
6233
|
-
const docTransTypes = (
|
|
6234
|
-
const
|
|
6235
|
-
|
|
6306
|
+
const isDocumentLevel = path.length === 0;
|
|
6307
|
+
const docTransTypes = (_b = (_a = config.translate) == null ? void 0 : _a.document) == null ? void 0 : _b.documentTypes;
|
|
6308
|
+
const options = fieldSchemaType == null ? void 0 : fieldSchemaType.options;
|
|
6309
|
+
const addFieldAction = isDocumentLevel || ((_c = options == null ? void 0 : options.aiWritingAssistance) == null ? void 0 : _c.translateAction);
|
|
6310
|
+
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));
|
|
6311
|
+
const documentTranslationEnabled = addFieldAction && documentSchemaType && (!docTransTypes && isAssistSupported(fieldSchemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(documentSchemaType.name)));
|
|
6312
|
+
if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
|
|
6236
6313
|
const {
|
|
6237
6314
|
value: documentValue,
|
|
6238
6315
|
onChange: documentOnChange
|
|
@@ -6245,39 +6322,52 @@ const translateActions = {
|
|
|
6245
6322
|
task: translationApi.translate
|
|
6246
6323
|
});
|
|
6247
6324
|
docRef.current = documentValue;
|
|
6248
|
-
const languagePath = (
|
|
6249
|
-
const translateDocumentAction = react.useMemo(() =>
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6325
|
+
const languagePath = (_h = (_g = config.translate) == null ? void 0 : _g.document) == null ? void 0 : _h.languageField;
|
|
6326
|
+
const translateDocumentAction = react.useMemo(() => {
|
|
6327
|
+
var _a2;
|
|
6328
|
+
if (!languagePath || !documentTranslationEnabled) {
|
|
6329
|
+
return void 0;
|
|
6330
|
+
}
|
|
6331
|
+
const {
|
|
6332
|
+
value: languageId
|
|
6333
|
+
} = (_a2 = mutator.extractWithPath(languagePath, documentValue)[0]) != null ? _a2 : {};
|
|
6334
|
+
const title = path.length ? "Translate" : "Translate document";
|
|
6335
|
+
return node$2({
|
|
6336
|
+
type: "action",
|
|
6337
|
+
icon: translationApi.loading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
6256
6338
|
style: {
|
|
6257
|
-
|
|
6339
|
+
height: 17
|
|
6340
|
+
},
|
|
6341
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
|
|
6342
|
+
style: {
|
|
6343
|
+
transform: "translateY(6px)"
|
|
6344
|
+
}
|
|
6345
|
+
})
|
|
6346
|
+
}) : icons.TranslateIcon,
|
|
6347
|
+
title,
|
|
6348
|
+
onAction: () => {
|
|
6349
|
+
if (translationApi.loading || !languagePath || !documentId) {
|
|
6350
|
+
return;
|
|
6258
6351
|
}
|
|
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]);
|
|
6352
|
+
translate({
|
|
6353
|
+
languagePath,
|
|
6354
|
+
translatePath: path,
|
|
6355
|
+
documentId: documentId != null ? documentId : ""
|
|
6356
|
+
});
|
|
6357
|
+
},
|
|
6358
|
+
renderAsButton: true,
|
|
6359
|
+
disabled: translationApi.loading || !languageId ? {
|
|
6360
|
+
reason: "Language is not set for this document"
|
|
6361
|
+
} : void 0
|
|
6362
|
+
});
|
|
6363
|
+
}, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled, path]);
|
|
6274
6364
|
const fieldTranslate = useFieldTranslation();
|
|
6275
6365
|
const openFieldTranslation = useDraftDelayedTask({
|
|
6276
6366
|
documentOnChange,
|
|
6277
6367
|
isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false,
|
|
6278
6368
|
task: fieldTranslate.openFieldTranslation
|
|
6279
6369
|
});
|
|
6280
|
-
const translateFieldsAction = react.useMemo(() => fieldTransEnabled ? node$
|
|
6370
|
+
const translateFieldsAction = react.useMemo(() => fieldTransEnabled ? node$2({
|
|
6281
6371
|
type: "action",
|
|
6282
6372
|
icon: fieldTranslate.translationLoading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
6283
6373
|
style: {
|
|
@@ -6289,24 +6379,25 @@ const translateActions = {
|
|
|
6289
6379
|
}
|
|
6290
6380
|
})
|
|
6291
6381
|
}) : icons.TranslateIcon,
|
|
6292
|
-
title: "Translate fields",
|
|
6382
|
+
title: "Translate fields...",
|
|
6293
6383
|
onAction: () => {
|
|
6294
6384
|
if (fieldTranslate.translationLoading || !documentId) {
|
|
6295
6385
|
return;
|
|
6296
6386
|
}
|
|
6297
6387
|
openFieldTranslation({
|
|
6298
6388
|
document: docRef.current,
|
|
6299
|
-
documentSchema:
|
|
6389
|
+
documentSchema: documentSchemaType,
|
|
6390
|
+
translatePath: path
|
|
6300
6391
|
});
|
|
6301
6392
|
},
|
|
6302
6393
|
renderAsButton: true,
|
|
6303
6394
|
disabled: fieldTranslate.translationLoading
|
|
6304
|
-
}) : void 0, [openFieldTranslation,
|
|
6395
|
+
}) : void 0, [openFieldTranslation, documentSchemaType, documentId, fieldTranslate.translationLoading, fieldTransEnabled, path]);
|
|
6305
6396
|
return react.useMemo(() => {
|
|
6306
|
-
return node$
|
|
6397
|
+
return node$2({
|
|
6307
6398
|
type: "group",
|
|
6308
6399
|
icon: () => null,
|
|
6309
|
-
title: "
|
|
6400
|
+
title: "Translation",
|
|
6310
6401
|
children: [translateDocumentAction, translateFieldsAction].filter(c => !!c),
|
|
6311
6402
|
expanded: true
|
|
6312
6403
|
});
|
|
@@ -6315,6 +6406,58 @@ const translateActions = {
|
|
|
6315
6406
|
return void 0;
|
|
6316
6407
|
}
|
|
6317
6408
|
};
|
|
6409
|
+
function node$1(node2) {
|
|
6410
|
+
return node2;
|
|
6411
|
+
}
|
|
6412
|
+
const generateImagActions = {
|
|
6413
|
+
name: "sanity-assist-generate-image",
|
|
6414
|
+
useAction(props) {
|
|
6415
|
+
const pathKey = usePathKey(props.path);
|
|
6416
|
+
const {
|
|
6417
|
+
config
|
|
6418
|
+
} = useAiAssistanceConfig();
|
|
6419
|
+
const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
|
|
6420
|
+
const {
|
|
6421
|
+
generateImage,
|
|
6422
|
+
loading
|
|
6423
|
+
} = useGenerateImage(apiClient);
|
|
6424
|
+
const imageContext = react.useContext(ImageContext);
|
|
6425
|
+
if (imageContext && pathKey === (imageContext == null ? void 0 : imageContext.imagePromptPath)) {
|
|
6426
|
+
const {
|
|
6427
|
+
documentId
|
|
6428
|
+
} = useAssistDocumentContext();
|
|
6429
|
+
return react.useMemo(() => {
|
|
6430
|
+
return node$1({
|
|
6431
|
+
type: "action",
|
|
6432
|
+
icon: loading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
6433
|
+
style: {
|
|
6434
|
+
height: 17
|
|
6435
|
+
},
|
|
6436
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
|
|
6437
|
+
style: {
|
|
6438
|
+
transform: "translateY(6px)"
|
|
6439
|
+
}
|
|
6440
|
+
})
|
|
6441
|
+
}) : icons.ImageIcon,
|
|
6442
|
+
title: "Generate image from prompt",
|
|
6443
|
+
onAction: () => {
|
|
6444
|
+
if (loading) {
|
|
6445
|
+
return;
|
|
6446
|
+
}
|
|
6447
|
+
generateImage({
|
|
6448
|
+
path: pathKey,
|
|
6449
|
+
documentId: documentId != null ? documentId : ""
|
|
6450
|
+
});
|
|
6451
|
+
},
|
|
6452
|
+
renderAsButton: true,
|
|
6453
|
+
disabled: loading,
|
|
6454
|
+
hidden: !imageContext.assetRef
|
|
6455
|
+
});
|
|
6456
|
+
}, [generateImage, pathKey, documentId, loading, imageContext]);
|
|
6457
|
+
}
|
|
6458
|
+
return void 0;
|
|
6459
|
+
}
|
|
6460
|
+
};
|
|
6318
6461
|
function node(node2) {
|
|
6319
6462
|
return node2;
|
|
6320
6463
|
}
|
|
@@ -6371,10 +6514,12 @@ const assistFieldActions = {
|
|
|
6371
6514
|
const isPathSelected = pathKey === selectedPath;
|
|
6372
6515
|
const isSelected = isInspectorOpen && isPathSelected;
|
|
6373
6516
|
const imageCaptionAction = generateCaptionsActions.useAction(props);
|
|
6517
|
+
const imageGenAction = generateImagActions.useAction(props);
|
|
6374
6518
|
const translateAction = translateActions.useAction(sanity.typed({
|
|
6375
6519
|
...props,
|
|
6376
6520
|
documentId: assistableDocumentId,
|
|
6377
|
-
documentIsAssistable
|
|
6521
|
+
documentIsAssistable,
|
|
6522
|
+
documentSchemaType
|
|
6378
6523
|
}));
|
|
6379
6524
|
const manageInstructions = react.useCallback(() => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
|
|
6380
6525
|
[fieldPathParam]: pathKey,
|
|
@@ -6402,7 +6547,7 @@ const assistFieldActions = {
|
|
|
6402
6547
|
}, [fieldAssist == null ? void 0 : fieldAssist.instructions]);
|
|
6403
6548
|
const instructions = react.useMemo(() => [...privateInstructions, ...sharedInstructions], [privateInstructions, sharedInstructions]);
|
|
6404
6549
|
const runInstructionsGroup = react.useMemo(() => {
|
|
6405
|
-
return (instructions == null ? void 0 : instructions.length) || imageCaptionAction || translateAction ? node({
|
|
6550
|
+
return (instructions == null ? void 0 : instructions.length) || imageCaptionAction || translateAction || imageGenAction ? node({
|
|
6406
6551
|
type: "group",
|
|
6407
6552
|
icon: () => null,
|
|
6408
6553
|
title: "Run instructions",
|
|
@@ -6413,10 +6558,10 @@ const assistFieldActions = {
|
|
|
6413
6558
|
hidden: isHidden,
|
|
6414
6559
|
documentIsNew: !!documentIsNew,
|
|
6415
6560
|
assistSupported
|
|
6416
|
-
}))), imageCaptionAction].filter(a => !!a),
|
|
6561
|
+
}))), imageCaptionAction, imageGenAction].filter(a => !!a),
|
|
6417
6562
|
expanded: true
|
|
6418
6563
|
}) : void 0;
|
|
6419
|
-
}, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction, translateAction]);
|
|
6564
|
+
}, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction, translateAction, imageGenAction]);
|
|
6420
6565
|
const instructionsLength = (instructions == null ? void 0 : instructions.length) || 0;
|
|
6421
6566
|
const manageInstructionsItem = react.useMemo(() => node({
|
|
6422
6567
|
type: "action",
|
|
@@ -6429,13 +6574,13 @@ const assistFieldActions = {
|
|
|
6429
6574
|
type: "group",
|
|
6430
6575
|
icon: icons.SparklesIcon,
|
|
6431
6576
|
title: pluginTitleShort,
|
|
6432
|
-
children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c),
|
|
6577
|
+
children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c).filter(c => c.type === "group" ? c.children.length : true),
|
|
6433
6578
|
expanded: false,
|
|
6434
6579
|
renderAsButton: true,
|
|
6435
|
-
hidden: !assistSupported && !imageCaptionAction && !translateAction
|
|
6580
|
+
hidden: !assistSupported && !imageCaptionAction && !translateAction && !imageGenAction
|
|
6436
6581
|
}), [
|
|
6437
6582
|
//documentIsNew,
|
|
6438
|
-
runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction, translateAction]);
|
|
6583
|
+
runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction, translateAction, imageGenAction]);
|
|
6439
6584
|
const emptyAction = react.useMemo(() => node({
|
|
6440
6585
|
type: "action",
|
|
6441
6586
|
hidden: !assistSupported,
|
|
@@ -6445,7 +6590,7 @@ const assistFieldActions = {
|
|
|
6445
6590
|
title: pluginTitleShort,
|
|
6446
6591
|
selected: isSelected
|
|
6447
6592
|
}), [assistSupported, manageInstructions, isSelected]);
|
|
6448
|
-
if (instructionsLength === 0 && !imageCaptionAction && !translateAction) {
|
|
6593
|
+
if (instructionsLength === 0 && !imageCaptionAction && !translateAction && !imageGenAction) {
|
|
6449
6594
|
return emptyAction;
|
|
6450
6595
|
}
|
|
6451
6596
|
return group;
|
|
@@ -6564,12 +6709,28 @@ function AssistDocumentInput(_ref23) {
|
|
|
6564
6709
|
...props
|
|
6565
6710
|
} = _ref23;
|
|
6566
6711
|
useInstructionToaster(documentId, props.schemaType);
|
|
6712
|
+
const schemaType = react.useMemo(() => {
|
|
6713
|
+
if (props.schemaType.name !== assistDocumentTypeName) {
|
|
6714
|
+
return props.schemaType;
|
|
6715
|
+
}
|
|
6716
|
+
return {
|
|
6717
|
+
...props.schemaType,
|
|
6718
|
+
type: {
|
|
6719
|
+
...props.schemaType.type,
|
|
6720
|
+
// compatability with i18nArrays plugin that requires this to be document
|
|
6721
|
+
name: "document"
|
|
6722
|
+
}
|
|
6723
|
+
};
|
|
6724
|
+
}, [props.schemaType]);
|
|
6567
6725
|
return /* @__PURE__ */jsxRuntime.jsx(FirstAssistedPathProvider, {
|
|
6568
6726
|
members: props.members,
|
|
6569
6727
|
children: /* @__PURE__ */jsxRuntime.jsx(AssistDocumentContextProvider, {
|
|
6570
|
-
schemaType
|
|
6728
|
+
schemaType,
|
|
6571
6729
|
documentId,
|
|
6572
|
-
children: props.renderDefault(
|
|
6730
|
+
children: props.renderDefault({
|
|
6731
|
+
...props,
|
|
6732
|
+
schemaType
|
|
6733
|
+
})
|
|
6573
6734
|
})
|
|
6574
6735
|
});
|
|
6575
6736
|
}
|
|
@@ -6645,7 +6806,8 @@ const assist = sanity.definePlugin(config => {
|
|
|
6645
6806
|
},
|
|
6646
6807
|
document: {
|
|
6647
6808
|
inspectors: (prev, context) => {
|
|
6648
|
-
const
|
|
6809
|
+
const documentType = context.documentType;
|
|
6810
|
+
const docSchema = context.schema.get(documentType);
|
|
6649
6811
|
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
6650
6812
|
return [...prev, assistInspector];
|
|
6651
6813
|
}
|
|
@@ -6656,6 +6818,9 @@ const assist = sanity.definePlugin(config => {
|
|
|
6656
6818
|
documentType,
|
|
6657
6819
|
schema
|
|
6658
6820
|
} = _ref24;
|
|
6821
|
+
if (documentType === assistDocumentTypeName) {
|
|
6822
|
+
return [];
|
|
6823
|
+
}
|
|
6659
6824
|
const docSchema = schema.get(documentType);
|
|
6660
6825
|
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
6661
6826
|
return [...prev, assistFieldActions];
|
|
@@ -6668,6 +6833,9 @@ const assist = sanity.definePlugin(config => {
|
|
|
6668
6833
|
schema,
|
|
6669
6834
|
schemaType
|
|
6670
6835
|
} = _ref25;
|
|
6836
|
+
if (schemaType === assistDocumentTypeName) {
|
|
6837
|
+
return [];
|
|
6838
|
+
}
|
|
6671
6839
|
const docSchema = schema.get(schemaType);
|
|
6672
6840
|
if (docSchema && sanity.isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
|
|
6673
6841
|
return [...prev, createAssistDocumentPresence(documentId, docSchema)];
|