@sanity/assist 4.4.2 → 4.4.4
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 +0 -2
- package/dist/index.esm.js +24 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assistDocument/components/AssistDocumentForm.tsx +15 -1
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +11 -3
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {Card, Stack, Text} from '@sanity/ui'
|
|
2
2
|
import {useContext, useEffect, useMemo, useRef} from 'react'
|
|
3
3
|
import {
|
|
4
|
+
FieldError,
|
|
4
5
|
FormCallbacksProvider,
|
|
5
6
|
FormCallbacksValue,
|
|
6
7
|
FormInput,
|
|
7
8
|
insert,
|
|
8
9
|
KeyedSegment,
|
|
10
|
+
MemberFieldError,
|
|
9
11
|
ObjectInputProps,
|
|
10
12
|
ObjectSchemaType,
|
|
11
13
|
PatchEvent,
|
|
@@ -127,6 +129,16 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
|
|
|
127
129
|
}
|
|
128
130
|
}, [activePath, instruction, onPathOpen])
|
|
129
131
|
|
|
132
|
+
const fieldError = useMemo(() => {
|
|
133
|
+
const fieldError = props.members.find(
|
|
134
|
+
(m): m is FieldError => m.kind === 'error' && m.fieldName === 'fields',
|
|
135
|
+
)
|
|
136
|
+
if (fieldError) {
|
|
137
|
+
return <MemberFieldError member={fieldError} />
|
|
138
|
+
}
|
|
139
|
+
return undefined
|
|
140
|
+
}, [props.members])
|
|
141
|
+
|
|
130
142
|
return (
|
|
131
143
|
<SelectedFieldContextProvider value={context}>
|
|
132
144
|
<Stack space={5}>
|
|
@@ -140,7 +152,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
|
|
|
140
152
|
/>
|
|
141
153
|
{instruction && <BackToInstructionListLink />}
|
|
142
154
|
|
|
143
|
-
{activePath && (
|
|
155
|
+
{activePath && !fieldError && (
|
|
144
156
|
<FormCallbacksProvider {...newCallbacks}>
|
|
145
157
|
<div style={{lineHeight: '1.25em'}}>
|
|
146
158
|
<FormInput {...props} absolutePath={activePath} />
|
|
@@ -148,6 +160,8 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
|
|
|
148
160
|
</FormCallbacksProvider>
|
|
149
161
|
)}
|
|
150
162
|
|
|
163
|
+
{fieldError}
|
|
164
|
+
|
|
151
165
|
{!activePath && props.renderDefault(props)}
|
|
152
166
|
</Stack>
|
|
153
167
|
</SelectedFieldContextProvider>
|
|
@@ -19,6 +19,15 @@ export function useAssistDocumentContextValue(documentId: string, documentType:
|
|
|
19
19
|
return schemaType
|
|
20
20
|
}, [documentType, schema])
|
|
21
21
|
|
|
22
|
+
const {fieldRefs, fieldRefsByTypePath} = useMemo(() => {
|
|
23
|
+
const fieldRefs = getFieldRefs(documentSchemaType)
|
|
24
|
+
const fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs)
|
|
25
|
+
return {
|
|
26
|
+
fieldRefs,
|
|
27
|
+
fieldRefsByTypePath,
|
|
28
|
+
}
|
|
29
|
+
}, [documentSchemaType])
|
|
30
|
+
|
|
22
31
|
const {
|
|
23
32
|
openInspector,
|
|
24
33
|
closeInspector,
|
|
@@ -54,9 +63,6 @@ export function useAssistDocumentContextValue(documentId: string, documentType:
|
|
|
54
63
|
const {syntheticTasks, addSyntheticTask, removeSyntheticTask} =
|
|
55
64
|
useSyntheticTasks(assistableDocumentId)
|
|
56
65
|
|
|
57
|
-
const fieldRefs = getFieldRefs(documentSchemaType)
|
|
58
|
-
const fieldRefsByTypePath = asFieldRefsByTypePath(fieldRefs)
|
|
59
|
-
|
|
60
66
|
const value: AssistDocumentContextValue = useMemo(() => {
|
|
61
67
|
const base = {
|
|
62
68
|
assistableDocumentId,
|
|
@@ -96,6 +102,8 @@ export function useAssistDocumentContextValue(documentId: string, documentType:
|
|
|
96
102
|
syntheticTasks,
|
|
97
103
|
addSyntheticTask,
|
|
98
104
|
removeSyntheticTask,
|
|
105
|
+
fieldRefs,
|
|
106
|
+
fieldRefsByTypePath,
|
|
99
107
|
])
|
|
100
108
|
|
|
101
109
|
return value
|