@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/src/useApiClient.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {useClient, useCurrentUser, useSchema} from 'sanity'
|
|
1
|
+
import {Path, pathToString, useClient, useCurrentUser, useSchema} from 'sanity'
|
|
2
2
|
import {useCallback, useMemo, useState} from 'react'
|
|
3
3
|
import {serializeSchema} from './schemas/serialize/serializeSchema'
|
|
4
4
|
import {useToast} from '@sanity/ui'
|
|
5
5
|
import {SanityClient} from '@sanity/client'
|
|
6
|
-
import {
|
|
6
|
+
import {FieldLanguageMap} from './translate/paths'
|
|
7
|
+
import {documentRootKey} from './types'
|
|
7
8
|
|
|
8
9
|
export interface UserTextInstance {
|
|
9
10
|
blockKey: string
|
|
@@ -26,6 +27,13 @@ export interface InstructStatus {
|
|
|
26
27
|
validToken: boolean
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
export interface TranslateRequest {
|
|
31
|
+
documentId: string
|
|
32
|
+
translatePath: Path
|
|
33
|
+
languagePath?: string
|
|
34
|
+
fieldLanguageMap?: FieldLanguageMap[]
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
const basePath = '/assist/tasks/instruction'
|
|
30
38
|
|
|
31
39
|
export function useApiClient(customApiClient?: (defaultClient: SanityClient) => SanityClient) {
|
|
@@ -44,15 +52,7 @@ export function useTranslate(apiClient: SanityClient) {
|
|
|
44
52
|
const toast = useToast()
|
|
45
53
|
|
|
46
54
|
const translate = useCallback(
|
|
47
|
-
({
|
|
48
|
-
documentId,
|
|
49
|
-
languagePath,
|
|
50
|
-
fieldLanguageMap,
|
|
51
|
-
}: {
|
|
52
|
-
documentId: string
|
|
53
|
-
languagePath?: string
|
|
54
|
-
fieldLanguageMap?: TranslationMap[]
|
|
55
|
-
}) => {
|
|
55
|
+
({documentId, languagePath, translatePath, fieldLanguageMap}: TranslateRequest) => {
|
|
56
56
|
setLoading(true)
|
|
57
57
|
|
|
58
58
|
return apiClient
|
|
@@ -66,6 +66,8 @@ export function useTranslate(apiClient: SanityClient) {
|
|
|
66
66
|
types,
|
|
67
67
|
languagePath,
|
|
68
68
|
fieldLanguageMap,
|
|
69
|
+
translatePath:
|
|
70
|
+
translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
|
|
69
71
|
userId: user?.id,
|
|
70
72
|
},
|
|
71
73
|
})
|