@sanity/assist 1.2.15-lang.4 → 1.2.15-lang.6
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 +2 -0
- package/dist/index.esm.js +32 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +31 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/fieldActions/generateImageActions.tsx +1 -2
- package/src/node_modules/.vitest/results.json +1 -1
- package/src/schemas/serialize/serializeSchema.test.ts +171 -0
- package/src/schemas/serialize/serializeSchema.ts +44 -1
- package/src/translate/FieldTranslationProvider.tsx +8 -7
- package/src/translate/translateActions.tsx +1 -6
- package/src/types.ts +8 -10
package/README.md
CHANGED
|
@@ -380,6 +380,8 @@ The rules can be extracted into an AI Context document and reused in other instr
|
|
|
380
380
|
|
|
381
381
|
AI assist offers full document translations, which is ideal for pairing with [@sanity/document-internationalization](https://github.com/sanity-io/document-internationalization).
|
|
382
382
|
|
|
383
|
+
Translations are done deeply; visiting nested objects, arrays and even Portable text annotations.
|
|
384
|
+
|
|
383
385
|
### What AI Assist full document translations solves
|
|
384
386
|
|
|
385
387
|
Given a document written in one language, AI assist can translate the document in place to a language specified by a language field in the document.
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { useClient, typed, useSchema, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, pathToString, isObjectSchemaType, stringToPath as stringToPath$2, isKeySegment, useEditState, useCurrentUser, StatusButton, FormFieldHeaderText, PatchEvent, unset, set, useFormCallbacks, FormCallbacksProvider, FormInput, setIfMissing, insert, PresenceOverlay, VirtualizerScrollInstanceProvider, useColorSchemeValue,
|
|
2
|
+
import { useClient, isArraySchemaType, typed, useSchema, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, pathToString, isObjectSchemaType, stringToPath as stringToPath$2, isKeySegment, useEditState, useCurrentUser, StatusButton, FormFieldHeaderText, PatchEvent, unset, set, useFormCallbacks, FormCallbacksProvider, FormInput, setIfMissing, insert, PresenceOverlay, VirtualizerScrollInstanceProvider, useColorSchemeValue, isDocumentSchemaType, ObjectInputMember, defineType, defineField, defineArrayMember, isArrayOfObjectsSchemaType, getPublishedId, useSyncState, definePlugin } from 'sanity';
|
|
3
3
|
import { Card, Stack, Box, Button, Spinner, Flex, Label, focusFirstDescendant, Text, useClickOutside, Popover, useLayer, useGlobalKeyDown, useToast, Dialog, Tooltip, TextArea, Container, Autocomplete, Breadcrumbs, Badge, useTheme, rgba, Radio, Checkbox, ThemeProvider, ErrorBoundary, Switch, MenuButton, Menu, MenuItem } from '@sanity/ui';
|
|
4
4
|
import { useState, useRef, useEffect, useMemo, useCallback, createContext, useReducer, forwardRef, createElement, useContext, useId } from 'react';
|
|
5
5
|
import { SyncIcon, DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, ErrorOutlineIcon, CheckmarkCircleIcon, CloseCircleIcon, ClockIcon, PlayIcon, SparklesIcon, ArrowLeftIcon, SearchIcon, RetryIcon, ArrowRightIcon, CloseIcon, CheckmarkIcon, icons, TokenIcon, DocumentTextIcon, ThListIcon, CodeIcon, ComposeIcon, LockIcon, TranslateIcon, ControlsIcon } from '@sanity/icons';
|
|
@@ -231,7 +231,9 @@ function getBaseFields(schema, type, typeName, options) {
|
|
|
231
231
|
}) : void 0,
|
|
232
232
|
of: "of" in type && typeName === "array" ? arrayOf(type, schema, options) : void 0,
|
|
233
233
|
to: "to" in type && typeName === "reference" ? refToTypeNames(type) : void 0,
|
|
234
|
-
fields: "fields" in type && inlineTypes.includes(typeName) ? serializeFields(schema, type, options) : void 0
|
|
234
|
+
fields: "fields" in type && inlineTypes.includes(typeName) ? serializeFields(schema, type, options) : void 0,
|
|
235
|
+
annotations: typeName === "block" && "fields" in type ? serializeAnnotations(type, schema, options) : void 0,
|
|
236
|
+
inlineOf: typeName === "block" && "fields" in type ? serializeInlineOf(type, schema, options) : void 0
|
|
235
237
|
});
|
|
236
238
|
}
|
|
237
239
|
function serializeFields(schema, schemaType, options) {
|
|
@@ -254,6 +256,25 @@ function serializeMember(schema, type, name, options) {
|
|
|
254
256
|
...getBaseFields(schema, type, typeName, options)
|
|
255
257
|
});
|
|
256
258
|
}
|
|
259
|
+
function serializeInlineOf(blockSchemaType, schema, options) {
|
|
260
|
+
const childrenField = blockSchemaType.fields.find(f => f.name === "children");
|
|
261
|
+
const childrenType = childrenField == null ? void 0 : childrenField.type;
|
|
262
|
+
if (!childrenType || !isArraySchemaType(childrenType)) {
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
return arrayOf({
|
|
266
|
+
...childrenType,
|
|
267
|
+
of: childrenType.of.filter(t => !isType(t, "span"))
|
|
268
|
+
}, schema, options);
|
|
269
|
+
}
|
|
270
|
+
function serializeAnnotations(blockSchemaType, schema, options) {
|
|
271
|
+
const markDefs = blockSchemaType.fields.find(f => f.name === "markDefs");
|
|
272
|
+
const marksType = markDefs == null ? void 0 : markDefs.type;
|
|
273
|
+
if (!marksType || !isArraySchemaType(marksType)) {
|
|
274
|
+
return void 0;
|
|
275
|
+
}
|
|
276
|
+
return arrayOf(marksType, schema, options);
|
|
277
|
+
}
|
|
257
278
|
function arrayOf(arrayType, schema, options) {
|
|
258
279
|
return arrayType.of.filter(type => isAssistSupported(type)).map(t => {
|
|
259
280
|
return serializeMember(schema, t, t.name, options);
|
|
@@ -4659,13 +4680,14 @@ function FieldTranslationProvider(props) {
|
|
|
4659
4680
|
return;
|
|
4660
4681
|
}
|
|
4661
4682
|
const preferred = getPreferredToFieldLanguages(from.id);
|
|
4662
|
-
const
|
|
4663
|
-
|
|
4683
|
+
const allToLanguages = languages2.filter(l => l.id !== (from == null ? void 0 : from.id));
|
|
4684
|
+
const filteredToLanguages = allToLanguages.filter(l => !preferred.length || preferred.includes(l.id));
|
|
4685
|
+
setToLanguages(filteredToLanguages);
|
|
4664
4686
|
const fromId = from == null ? void 0 : from.id;
|
|
4665
|
-
const
|
|
4687
|
+
const allToIds = (_a2 = allToLanguages == null ? void 0 : allToLanguages.map(l => l.id)) != null ? _a2 : [];
|
|
4666
4688
|
const docMembers = getDocumentMembersFlat(document, documentSchema);
|
|
4667
|
-
if (fromId && (
|
|
4668
|
-
const transMap = getFieldLanguageMap(documentSchema, docMembers, fromId,
|
|
4689
|
+
if (fromId && (allToIds == null ? void 0 : allToIds.length)) {
|
|
4690
|
+
const transMap = getFieldLanguageMap(documentSchema, docMembers, fromId, allToIds, (_b2 = config == null ? void 0 : config.translationOutputs) != null ? _b2 : defaultLanguageOutputs);
|
|
4669
4691
|
setFieldLanguageMaps(transMap);
|
|
4670
4692
|
} else {
|
|
4671
4693
|
setFieldLanguageMaps(void 0);
|
|
@@ -6311,13 +6333,9 @@ const translateActions = {
|
|
|
6311
6333
|
docRef.current = documentValue;
|
|
6312
6334
|
const languagePath = (_h = (_g = config.translate) == null ? void 0 : _g.document) == null ? void 0 : _h.languageField;
|
|
6313
6335
|
const translateDocumentAction = useMemo(() => {
|
|
6314
|
-
var _a2;
|
|
6315
6336
|
if (!languagePath || !documentTranslationEnabled) {
|
|
6316
6337
|
return void 0;
|
|
6317
6338
|
}
|
|
6318
|
-
const {
|
|
6319
|
-
value: languageId
|
|
6320
|
-
} = (_a2 = extractWithPath(languagePath, documentValue)[0]) != null ? _a2 : {};
|
|
6321
6339
|
const title = path.length ? "Translate" : "Translate document";
|
|
6322
6340
|
return node$2({
|
|
6323
6341
|
type: "action",
|
|
@@ -6343,9 +6361,7 @@ const translateActions = {
|
|
|
6343
6361
|
});
|
|
6344
6362
|
},
|
|
6345
6363
|
renderAsButton: true,
|
|
6346
|
-
disabled: translationApi.loading
|
|
6347
|
-
reason: "Language is not set for this document"
|
|
6348
|
-
} : void 0
|
|
6364
|
+
disabled: translationApi.loading
|
|
6349
6365
|
});
|
|
6350
6366
|
}, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled, path]);
|
|
6351
6367
|
const fieldTranslate = useFieldTranslation();
|
|
@@ -6437,10 +6453,9 @@ const generateImagActions = {
|
|
|
6437
6453
|
});
|
|
6438
6454
|
},
|
|
6439
6455
|
renderAsButton: true,
|
|
6440
|
-
disabled: loading
|
|
6441
|
-
hidden: !imageContext.assetRef
|
|
6456
|
+
disabled: loading
|
|
6442
6457
|
});
|
|
6443
|
-
}, [generateImage, pathKey, documentId, loading
|
|
6458
|
+
}, [generateImage, pathKey, documentId, loading]);
|
|
6444
6459
|
}
|
|
6445
6460
|
return void 0;
|
|
6446
6461
|
}
|