@sanity/assist 2.0.4-canary.0 → 2.0.5
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 +233 -214
- package/dist/index.esm.js +1769 -1769
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1767 -1767
- package/dist/index.js.map +1 -1
- package/package.json +17 -18
- package/src/_lib/connector/ConnectFromRegion.tsx +4 -3
- package/src/_lib/connector/ConnectToRegion.tsx +1 -0
- package/src/_lib/connector/ConnectorRegion.tsx +2 -1
- package/src/_lib/connector/ConnectorsProvider.tsx +2 -1
- package/src/_lib/connector/ConnectorsStoreContext.ts +1 -0
- package/src/_lib/connector/index.ts +1 -1
- package/src/_lib/connector/mapConnectorToLine.ts +2 -2
- package/src/_lib/connector/useConnectorsStore.ts +2 -1
- package/src/_lib/connector/useRegionRects.ts +4 -3
- package/src/_lib/fixedListenQuery.ts +11 -11
- package/src/_lib/form/DocumentForm.tsx +4 -3
- package/src/_lib/form/helpers.ts +2 -1
- package/src/_lib/useListeningQuery.ts +4 -3
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +1 -0
- package/src/assistConnectors/ConnectorPath.tsx +3 -2
- package/src/assistConnectors/draw/connectorPath.ts +13 -13
- package/src/assistDocument/AssistDocumentContext.tsx +3 -2
- package/src/assistDocument/AssistDocumentContextProvider.tsx +2 -1
- package/src/assistDocument/AssistDocumentInput.tsx +9 -8
- package/src/assistDocument/RequestRunInstructionProvider.tsx +4 -3
- package/src/assistDocument/components/AssistDocumentForm.tsx +25 -24
- package/src/assistDocument/components/FieldRefPreview.tsx +4 -3
- package/src/assistDocument/components/InstructionsArrayInput.tsx +4 -3
- package/src/assistDocument/components/SelectedFieldContext.tsx +1 -1
- package/src/assistDocument/components/helpers.ts +4 -4
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +3 -2
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +5 -4
- package/src/assistDocument/components/instruction/InstructionInput.tsx +3 -2
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +2 -1
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +14 -13
- package/src/assistDocument/components/instruction/PromptInput.tsx +4 -3
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +2 -2
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +1 -1
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +7 -6
- package/src/assistDocument/hooks/useInstructionToaster.tsx +6 -5
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +14 -13
- package/src/assistFormComponents/AssistField.tsx +9 -8
- package/src/assistFormComponents/AssistFormBlock.tsx +5 -4
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +1 -1
- package/src/assistFormComponents/AssistItem.tsx +3 -2
- package/src/assistFormComponents/validation/listItem.tsx +2 -2
- package/src/assistFormComponents/validation/validationList.tsx +3 -2
- package/src/assistInspector/AssistInspector.tsx +16 -15
- package/src/assistInspector/FieldAutocomplete.tsx +4 -3
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +19 -18
- package/src/assistInspector/helpers.ts +10 -9
- package/src/assistInspector/index.ts +4 -3
- package/src/assistLayout/AiAssistanceConfigContext.tsx +1 -0
- package/src/assistLayout/AssistLayout.tsx +5 -4
- package/src/assistLayout/RunInstructionProvider.tsx +18 -15
- package/src/components/FadeInContent.tsx +1 -1
- package/src/components/HideReferenceChangedBannerInput.tsx +1 -1
- package/src/components/ImageContext.tsx +4 -3
- package/src/components/SafeValueInput.tsx +7 -6
- package/src/components/TimeAgo.tsx +1 -1
- package/src/fieldActions/assistFieldActions.tsx +31 -30
- package/src/fieldActions/generateCaptionActions.tsx +8 -7
- package/src/fieldActions/generateImageActions.tsx +6 -5
- package/src/helpers/assistSupported.ts +1 -0
- package/src/helpers/conditionalMembers.test.ts +2 -1
- package/src/helpers/conditionalMembers.ts +17 -14
- package/src/helpers/misc.ts +3 -2
- package/src/helpers/typeUtils.ts +1 -1
- package/src/helpers/useAssistSupported.ts +2 -1
- package/src/onboarding/FieldActionsOnboarding.tsx +2 -1
- package/src/onboarding/FirstAssistedPathProvider.tsx +4 -3
- package/src/onboarding/InspectorOnboarding.tsx +3 -2
- package/src/onboarding/onboardingStore.ts +1 -1
- package/src/presence/AiFieldPresence.tsx +3 -1
- package/src/presence/AssistDocumentPresence.tsx +7 -6
- package/src/presence/useAssistPresence.ts +6 -3
- package/src/schemas/assistDocumentSchema.tsx +21 -20
- package/src/schemas/contextDocumentSchema.tsx +3 -2
- package/src/schemas/index.ts +2 -1
- package/src/schemas/serialize/SchemTypeTool.tsx +4 -3
- package/src/schemas/serialize/serializeSchema.test.ts +3 -2
- package/src/schemas/serialize/serializeSchema.ts +15 -14
- package/src/schemas/serializedSchemaTypeSchema.ts +2 -1
- package/src/translate/FieldTranslationProvider.tsx +33 -25
- package/src/translate/getLanguageParams.ts +3 -3
- package/src/translate/paths.test.ts +11 -4
- package/src/translate/paths.ts +12 -11
- package/src/translate/translateActions.tsx +12 -11
- package/src/translate/types.ts +2 -2
- package/src/useApiClient.ts +9 -9
package/src/translate/paths.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import {extractWithPath} from '@sanity/mutator'
|
|
1
2
|
import {
|
|
2
3
|
isDocumentSchemaType,
|
|
3
4
|
isKeySegment,
|
|
4
|
-
ObjectSchemaType,
|
|
5
|
-
Path,
|
|
5
|
+
type ObjectSchemaType,
|
|
6
|
+
type Path,
|
|
6
7
|
pathToString,
|
|
7
|
-
SanityDocumentLike,
|
|
8
|
+
type SanityDocumentLike,
|
|
8
9
|
} from 'sanity'
|
|
9
|
-
|
|
10
|
-
import {DocumentMember, TranslationOutput, TranslationOutputsFunction} from './types'
|
|
10
|
+
|
|
11
|
+
import type {DocumentMember, TranslationOutput, TranslationOutputsFunction} from './types'
|
|
11
12
|
|
|
12
13
|
export interface FieldLanguageMap {
|
|
13
14
|
inputLanguageId: string
|
|
@@ -30,7 +31,7 @@ function extractPaths(
|
|
|
30
31
|
doc: SanityDocumentLike,
|
|
31
32
|
schemaType: ObjectSchemaType,
|
|
32
33
|
path: Path,
|
|
33
|
-
maxDepth: number
|
|
34
|
+
maxDepth: number,
|
|
34
35
|
): DocumentMember[] {
|
|
35
36
|
if (path.length >= maxDepth) {
|
|
36
37
|
return []
|
|
@@ -75,7 +76,7 @@ function extractPaths(
|
|
|
75
76
|
itemPath,
|
|
76
77
|
item,
|
|
77
78
|
itemSchema,
|
|
78
|
-
}
|
|
79
|
+
},
|
|
79
80
|
)
|
|
80
81
|
}
|
|
81
82
|
if (item._key && itemSchema) {
|
|
@@ -83,7 +84,7 @@ function extractPaths(
|
|
|
83
84
|
doc,
|
|
84
85
|
itemSchema as ObjectSchemaType,
|
|
85
86
|
itemPath,
|
|
86
|
-
maxDepth
|
|
87
|
+
maxDepth,
|
|
87
88
|
)
|
|
88
89
|
const arrayMember = {
|
|
89
90
|
path: itemPath,
|
|
@@ -112,7 +113,7 @@ export const defaultLanguageOutputs: TranslationOutputsFunction = function (
|
|
|
112
113
|
member,
|
|
113
114
|
enclosingType,
|
|
114
115
|
translateFromLanguageId,
|
|
115
|
-
translateToLanguageIds
|
|
116
|
+
translateToLanguageIds,
|
|
116
117
|
) {
|
|
117
118
|
if (
|
|
118
119
|
member.schemaType.jsonType === 'object' &&
|
|
@@ -146,7 +147,7 @@ export function getFieldLanguageMap(
|
|
|
146
147
|
documentMembers: DocumentMember[],
|
|
147
148
|
translateFromLanguageId: string,
|
|
148
149
|
outputLanguageIds: string[],
|
|
149
|
-
langFn: TranslationOutputsFunction
|
|
150
|
+
langFn: TranslationOutputsFunction,
|
|
150
151
|
): FieldLanguageMap[] {
|
|
151
152
|
const translationMaps: FieldLanguageMap[] = []
|
|
152
153
|
for (const member of documentMembers) {
|
|
@@ -159,7 +160,7 @@ export function getFieldLanguageMap(
|
|
|
159
160
|
member,
|
|
160
161
|
enclosingType,
|
|
161
162
|
translateFromLanguageId,
|
|
162
|
-
outputLanguageIds
|
|
163
|
+
outputLanguageIds,
|
|
163
164
|
)?.filter((translation) => translation.id !== translateFromLanguageId)
|
|
164
165
|
|
|
165
166
|
if (translations) {
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
import {
|
|
2
|
+
import {TranslateIcon} from '@sanity/icons'
|
|
3
|
+
import {Box, Spinner} from '@sanity/ui'
|
|
4
|
+
import {useMemo, useRef} from 'react'
|
|
5
|
+
import type {
|
|
3
6
|
DocumentFieldAction,
|
|
4
7
|
DocumentFieldActionGroup,
|
|
5
8
|
DocumentFieldActionItem,
|
|
6
9
|
DocumentFieldActionProps,
|
|
7
10
|
ObjectSchemaType,
|
|
8
11
|
} from 'sanity'
|
|
9
|
-
import {TranslateIcon} from '@sanity/icons'
|
|
10
|
-
import {useMemo, useRef} from 'react'
|
|
11
|
-
import {useApiClient, useTranslate} from '../useApiClient'
|
|
12
|
-
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
13
|
-
import {Box, Spinner} from '@sanity/ui'
|
|
14
|
-
import {isAssistSupported} from '../helpers/assistSupported'
|
|
15
12
|
import {useDocumentPane} from 'sanity/desk'
|
|
16
|
-
|
|
13
|
+
|
|
17
14
|
import {useDraftDelayedTask} from '../assistDocument/RequestRunInstructionProvider'
|
|
18
|
-
import {
|
|
15
|
+
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
16
|
+
import {isAssistSupported} from '../helpers/assistSupported'
|
|
19
17
|
import {getConditionalMembers} from '../helpers/conditionalMembers'
|
|
18
|
+
import type {AssistOptions} from '../schemas/typeDefExtensions'
|
|
19
|
+
import {useApiClient, useTranslate} from '../useApiClient'
|
|
20
|
+
import {useFieldTranslation} from './FieldTranslationProvider'
|
|
20
21
|
|
|
21
22
|
function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
|
|
22
23
|
return node
|
|
@@ -163,7 +164,7 @@ export const translateActions: DocumentFieldAction = {
|
|
|
163
164
|
fieldTransEnabled,
|
|
164
165
|
path,
|
|
165
166
|
readOnly,
|
|
166
|
-
]
|
|
167
|
+
],
|
|
167
168
|
)
|
|
168
169
|
|
|
169
170
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
@@ -176,7 +177,7 @@ export const translateActions: DocumentFieldAction = {
|
|
|
176
177
|
icon: () => null,
|
|
177
178
|
title: 'Translation',
|
|
178
179
|
children: [translateDocumentAction, translateFieldsAction].filter(
|
|
179
|
-
(c): c is DocumentFieldActionItem => !!c
|
|
180
|
+
(c): c is DocumentFieldActionItem => !!c,
|
|
180
181
|
),
|
|
181
182
|
expanded: true,
|
|
182
183
|
})
|
package/src/translate/types.ts
CHANGED
|
@@ -22,12 +22,12 @@ export type TranslationOutputsFunction = (
|
|
|
22
22
|
documentMember: DocumentMember,
|
|
23
23
|
enclosingType: SchemaType,
|
|
24
24
|
translateFromLanguageId: string,
|
|
25
|
-
translateToLanguageIds: string[]
|
|
25
|
+
translateToLanguageIds: string[],
|
|
26
26
|
) => TranslationOutput[] | undefined
|
|
27
27
|
|
|
28
28
|
export type LanguageCallback = (
|
|
29
29
|
client: SanityClient,
|
|
30
|
-
selectedLanguageParams: Record<string, unknown
|
|
30
|
+
selectedLanguageParams: Record<string, unknown>,
|
|
31
31
|
) => Promise<Language[]>
|
|
32
32
|
|
|
33
33
|
export interface FieldTranslationConfig {
|
package/src/useApiClient.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function useApiClient(customApiClient?: (defaultClient: SanityClient) =>
|
|
|
47
47
|
const client = useClient({apiVersion: '2023-06-05'})
|
|
48
48
|
return useMemo(
|
|
49
49
|
() => (customApiClient ? customApiClient(client) : client),
|
|
50
|
-
[client, customApiClient]
|
|
50
|
+
[client, customApiClient],
|
|
51
51
|
)
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -102,7 +102,7 @@ export function useTranslate(apiClient: SanityClient) {
|
|
|
102
102
|
}, 2000)
|
|
103
103
|
})
|
|
104
104
|
},
|
|
105
|
-
[setLoading, apiClient, toast, user, types]
|
|
105
|
+
[setLoading, apiClient, toast, user, types],
|
|
106
106
|
)
|
|
107
107
|
|
|
108
108
|
return useMemo(
|
|
@@ -110,7 +110,7 @@ export function useTranslate(apiClient: SanityClient) {
|
|
|
110
110
|
translate,
|
|
111
111
|
loading,
|
|
112
112
|
}),
|
|
113
|
-
[translate, loading]
|
|
113
|
+
[translate, loading],
|
|
114
114
|
)
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -155,7 +155,7 @@ export function useGenerateCaption(apiClient: SanityClient) {
|
|
|
155
155
|
}, 2000)
|
|
156
156
|
})
|
|
157
157
|
},
|
|
158
|
-
[setLoading, apiClient, toast, user, types]
|
|
158
|
+
[setLoading, apiClient, toast, user, types],
|
|
159
159
|
)
|
|
160
160
|
|
|
161
161
|
return useMemo(
|
|
@@ -163,7 +163,7 @@ export function useGenerateCaption(apiClient: SanityClient) {
|
|
|
163
163
|
generateCaption,
|
|
164
164
|
loading,
|
|
165
165
|
}),
|
|
166
|
-
[generateCaption, loading]
|
|
166
|
+
[generateCaption, loading],
|
|
167
167
|
)
|
|
168
168
|
}
|
|
169
169
|
|
|
@@ -208,7 +208,7 @@ export function useGenerateImage(apiClient: SanityClient) {
|
|
|
208
208
|
}, 2000)
|
|
209
209
|
})
|
|
210
210
|
},
|
|
211
|
-
[setLoading, apiClient, toast, user, types]
|
|
211
|
+
[setLoading, apiClient, toast, user, types],
|
|
212
212
|
)
|
|
213
213
|
|
|
214
214
|
return useMemo(
|
|
@@ -216,7 +216,7 @@ export function useGenerateImage(apiClient: SanityClient) {
|
|
|
216
216
|
generateImage,
|
|
217
217
|
loading,
|
|
218
218
|
}),
|
|
219
|
-
[generateImage, loading]
|
|
219
|
+
[generateImage, loading],
|
|
220
220
|
)
|
|
221
221
|
}
|
|
222
222
|
|
|
@@ -301,7 +301,7 @@ export function useRunInstructionApi(apiClient: SanityClient) {
|
|
|
301
301
|
setLoading(false)
|
|
302
302
|
})
|
|
303
303
|
},
|
|
304
|
-
[apiClient, types, user, toast]
|
|
304
|
+
[apiClient, types, user, toast],
|
|
305
305
|
)
|
|
306
306
|
|
|
307
307
|
return useMemo(
|
|
@@ -309,6 +309,6 @@ export function useRunInstructionApi(apiClient: SanityClient) {
|
|
|
309
309
|
runInstruction,
|
|
310
310
|
loading,
|
|
311
311
|
}),
|
|
312
|
-
[runInstruction, loading]
|
|
312
|
+
[runInstruction, loading],
|
|
313
313
|
)
|
|
314
314
|
}
|