@sanity/assist 1.2.15-lang.5 → 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 +24 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +23 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- 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/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);
|
|
@@ -6312,13 +6333,9 @@ const translateActions = {
|
|
|
6312
6333
|
docRef.current = documentValue;
|
|
6313
6334
|
const languagePath = (_h = (_g = config.translate) == null ? void 0 : _g.document) == null ? void 0 : _h.languageField;
|
|
6314
6335
|
const translateDocumentAction = useMemo(() => {
|
|
6315
|
-
var _a2;
|
|
6316
6336
|
if (!languagePath || !documentTranslationEnabled) {
|
|
6317
6337
|
return void 0;
|
|
6318
6338
|
}
|
|
6319
|
-
const {
|
|
6320
|
-
value: languageId
|
|
6321
|
-
} = (_a2 = extractWithPath(languagePath, documentValue)[0]) != null ? _a2 : {};
|
|
6322
6339
|
const title = path.length ? "Translate" : "Translate document";
|
|
6323
6340
|
return node$2({
|
|
6324
6341
|
type: "action",
|
|
@@ -6344,9 +6361,7 @@ const translateActions = {
|
|
|
6344
6361
|
});
|
|
6345
6362
|
},
|
|
6346
6363
|
renderAsButton: true,
|
|
6347
|
-
disabled: translationApi.loading
|
|
6348
|
-
reason: "Language is not set for this document"
|
|
6349
|
-
} : void 0
|
|
6364
|
+
disabled: translationApi.loading
|
|
6350
6365
|
});
|
|
6351
6366
|
}, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled, path]);
|
|
6352
6367
|
const fieldTranslate = useFieldTranslation();
|