@sanity/assist 4.4.3 → 4.4.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/dist/index.esm.js +144 -131
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +143 -130
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -131
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assistDocument/AssistDocumentContext.tsx +3 -1
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +21 -4
- package/src/useApiClient.ts +6 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {createContext, useContext} from 'react'
|
|
2
2
|
import {DocumentInspector, ObjectSchemaType, PatchEvent} from 'sanity'
|
|
3
3
|
|
|
4
|
-
import {InstructionTask, StudioAssistDocument} from '../types'
|
|
4
|
+
import {InstructionTask, SerializedSchemaType, StudioAssistDocument} from '../types'
|
|
5
5
|
import {FieldRef} from '../assistInspector/helpers'
|
|
6
6
|
|
|
7
7
|
export type AssistDocumentContextValue = (
|
|
@@ -36,6 +36,8 @@ export type AssistDocumentContextValue = (
|
|
|
36
36
|
|
|
37
37
|
fieldRefs: FieldRef[]
|
|
38
38
|
fieldRefsByTypePath: Record<string, FieldRef | undefined>
|
|
39
|
+
|
|
40
|
+
serializedTypes: SerializedSchemaType[]
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export const AssistDocumentContext = createContext<AssistDocumentContextValue | undefined>(
|
|
@@ -4,9 +4,14 @@ import {useDocumentPane} from 'sanity/structure'
|
|
|
4
4
|
|
|
5
5
|
import {asFieldRefsByTypePath, getFieldRefs, useAiPaneRouter} from '../../assistInspector/helpers'
|
|
6
6
|
import {fieldPathParam, InstructionTask} from '../../types'
|
|
7
|
-
import
|
|
7
|
+
import {AssistDocumentContextValue, useAssistDocumentContext} from '../AssistDocumentContext'
|
|
8
8
|
import {isDocAssistable} from '../RequestRunInstructionProvider'
|
|
9
9
|
import {useStudioAssistDocument} from './useStudioAssistDocument'
|
|
10
|
+
import {serializeSchema} from '../../schemas/serialize/serializeSchema'
|
|
11
|
+
|
|
12
|
+
export function useSerializedTypes() {
|
|
13
|
+
return useAssistDocumentContext().serializedTypes
|
|
14
|
+
}
|
|
10
15
|
|
|
11
16
|
export function useAssistDocumentContextValue(documentId: string, documentType: string) {
|
|
12
17
|
const schema = useSchema()
|
|
@@ -19,6 +24,17 @@ export function useAssistDocumentContextValue(documentId: string, documentType:
|
|
|
19
24
|
return schemaType
|
|
20
25
|
}, [documentType, schema])
|
|
21
26
|
|
|
27
|
+
const serializedTypes = useMemo(() => serializeSchema(schema, {leanFormat: true}), [schema])
|
|
28
|
+
|
|
29
|
+
const {fieldRefs, fieldRefsByTypePath} = useMemo(() => {
|
|
30
|
+
const fieldRefs = getFieldRefs(documentSchemaType)
|
|
31
|
+
const fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs)
|
|
32
|
+
return {
|
|
33
|
+
fieldRefs,
|
|
34
|
+
fieldRefsByTypePath,
|
|
35
|
+
}
|
|
36
|
+
}, [documentSchemaType])
|
|
37
|
+
|
|
22
38
|
const {
|
|
23
39
|
openInspector,
|
|
24
40
|
closeInspector,
|
|
@@ -54,9 +70,6 @@ export function useAssistDocumentContextValue(documentId: string, documentType:
|
|
|
54
70
|
const {syntheticTasks, addSyntheticTask, removeSyntheticTask} =
|
|
55
71
|
useSyntheticTasks(assistableDocumentId)
|
|
56
72
|
|
|
57
|
-
const fieldRefs = getFieldRefs(documentSchemaType)
|
|
58
|
-
const fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs)
|
|
59
|
-
|
|
60
73
|
const value: AssistDocumentContextValue = useMemo(() => {
|
|
61
74
|
const base = {
|
|
62
75
|
assistableDocumentId,
|
|
@@ -73,6 +86,7 @@ export function useAssistDocumentContextValue(documentId: string, documentType:
|
|
|
73
86
|
removeSyntheticTask,
|
|
74
87
|
fieldRefs,
|
|
75
88
|
fieldRefsByTypePath,
|
|
89
|
+
serializedTypes,
|
|
76
90
|
}
|
|
77
91
|
if (!assistDocument) {
|
|
78
92
|
return {...base, loading: true, assistDocument: undefined}
|
|
@@ -96,6 +110,9 @@ export function useAssistDocumentContextValue(documentId: string, documentType:
|
|
|
96
110
|
syntheticTasks,
|
|
97
111
|
addSyntheticTask,
|
|
98
112
|
removeSyntheticTask,
|
|
113
|
+
fieldRefs,
|
|
114
|
+
fieldRefsByTypePath,
|
|
115
|
+
serializedTypes,
|
|
99
116
|
])
|
|
100
117
|
|
|
101
118
|
return value
|
package/src/useApiClient.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type {SanityClient} from '@sanity/client'
|
|
2
2
|
import {useToast} from '@sanity/ui'
|
|
3
3
|
import {useCallback, useMemo, useState} from 'react'
|
|
4
|
-
import {Path, pathToString, useClient, useCurrentUser
|
|
4
|
+
import {Path, pathToString, useClient, useCurrentUser} from 'sanity'
|
|
5
5
|
|
|
6
6
|
import {useAiAssistanceConfig} from './assistLayout/AiAssistanceConfigContext'
|
|
7
7
|
import {ConditionalMemberState} from './helpers/conditionalMembers'
|
|
8
|
-
import {serializeSchema} from './schemas/serialize/serializeSchema'
|
|
9
8
|
import {FieldLanguageMap} from './translate/paths'
|
|
10
9
|
import {documentRootKey} from './types'
|
|
10
|
+
import {useSerializedTypes} from './assistDocument/hooks/useAssistDocumentContextValue'
|
|
11
11
|
|
|
12
12
|
export interface UserTextInstance {
|
|
13
13
|
blockKey: string
|
|
@@ -58,8 +58,7 @@ export function useApiClient(customApiClient?: (defaultClient: SanityClient) =>
|
|
|
58
58
|
export function useTranslate(apiClient: SanityClient) {
|
|
59
59
|
const [loading, setLoading] = useState(false)
|
|
60
60
|
const user = useCurrentUser()
|
|
61
|
-
const
|
|
62
|
-
const types = useMemo(() => serializeSchema(schema, {leanFormat: true}), [schema])
|
|
61
|
+
const types = useSerializedTypes()
|
|
63
62
|
const toast = useToast()
|
|
64
63
|
|
|
65
64
|
const translate = useCallback(
|
|
@@ -126,8 +125,7 @@ export function useTranslate(apiClient: SanityClient) {
|
|
|
126
125
|
export function useGenerateCaption(apiClient: SanityClient) {
|
|
127
126
|
const [loading, setLoading] = useState(false)
|
|
128
127
|
const user = useCurrentUser()
|
|
129
|
-
const
|
|
130
|
-
const types = useMemo(() => serializeSchema(schema, {leanFormat: true}), [schema])
|
|
128
|
+
const types = useSerializedTypes()
|
|
131
129
|
const toast = useToast()
|
|
132
130
|
|
|
133
131
|
const generateCaption = useCallback(
|
|
@@ -179,8 +177,7 @@ export function useGenerateCaption(apiClient: SanityClient) {
|
|
|
179
177
|
export function useGenerateImage(apiClient: SanityClient) {
|
|
180
178
|
const [loading, setLoading] = useState(false)
|
|
181
179
|
const user = useCurrentUser()
|
|
182
|
-
const
|
|
183
|
-
const types = useMemo(() => serializeSchema(schema, {leanFormat: true}), [schema])
|
|
180
|
+
const types = useSerializedTypes()
|
|
184
181
|
const toast = useToast()
|
|
185
182
|
|
|
186
183
|
const generateImage = useCallback(
|
|
@@ -280,8 +277,7 @@ export function useRunInstructionApi(apiClient: SanityClient) {
|
|
|
280
277
|
const toast = useToast()
|
|
281
278
|
const [loading, setLoading] = useState(false)
|
|
282
279
|
const user = useCurrentUser()
|
|
283
|
-
const
|
|
284
|
-
const types = useMemo(() => serializeSchema(schema, {leanFormat: true}), [schema])
|
|
280
|
+
const types = useSerializedTypes()
|
|
285
281
|
|
|
286
282
|
const {
|
|
287
283
|
config: {assist: assistConfig},
|