@sanity/assist 2.0.4 → 3.0.0
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 -2
- package/dist/index.d.mts +377 -0
- package/dist/index.esm.js +3132 -5883
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3109 -5886
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4159 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -37
- 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 +11 -9
- 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 +10 -9
- 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 +4 -3
- 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 +10 -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 +8 -7
- 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 +3 -3
- package/src/assistFormComponents/validation/validationList.tsx +3 -2
- package/src/assistInspector/AssistInspector.tsx +25 -18
- package/src/assistInspector/FieldAutocomplete.tsx +4 -3
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +20 -19
- package/src/assistInspector/helpers.ts +16 -15
- 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 +3 -3
- package/src/components/HideReferenceChangedBannerInput.tsx +1 -1
- package/src/components/ImageContext.tsx +5 -4
- package/src/components/SafeValueInput.tsx +9 -11
- 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/AssistAvatar.tsx +2 -2
- 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 +4 -4
- 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/dist/index.cjs.mjs +0 -7
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssistDocument,
|
|
3
|
-
AssistField,
|
|
4
|
-
assistFieldTypeName,
|
|
5
|
-
AssistInspectorRouteParams,
|
|
6
|
-
documentRootKey,
|
|
7
|
-
fieldPathParam,
|
|
8
|
-
instructionParam,
|
|
9
|
-
StudioInstruction,
|
|
10
|
-
} from '../../types'
|
|
1
|
+
import {Card, Stack, Text} from '@sanity/ui'
|
|
11
2
|
import {createContext, useContext, useEffect, useMemo, useRef} from 'react'
|
|
12
3
|
import {
|
|
13
4
|
FormCallbacksProvider,
|
|
@@ -27,12 +18,22 @@ import {
|
|
|
27
18
|
useFormCallbacks,
|
|
28
19
|
useSchema,
|
|
29
20
|
} from 'sanity'
|
|
30
|
-
|
|
21
|
+
|
|
31
22
|
import {useAiPaneRouter} from '../../assistInspector/helpers'
|
|
32
|
-
import {SelectedFieldContextProvider, SelectedFieldContextValue} from './SelectedFieldContext'
|
|
33
|
-
import {Card, Stack, Text} from '@sanity/ui'
|
|
34
|
-
import {documentTypeFromAiDocumentId} from '../../helpers/ids'
|
|
35
23
|
import {useAiAssistanceConfig} from '../../assistLayout/AiAssistanceConfigContext'
|
|
24
|
+
import {documentTypeFromAiDocumentId} from '../../helpers/ids'
|
|
25
|
+
import {
|
|
26
|
+
AssistDocument,
|
|
27
|
+
AssistField,
|
|
28
|
+
assistFieldTypeName,
|
|
29
|
+
AssistInspectorRouteParams,
|
|
30
|
+
documentRootKey,
|
|
31
|
+
fieldPathParam,
|
|
32
|
+
instructionParam,
|
|
33
|
+
StudioInstruction,
|
|
34
|
+
} from '../../types'
|
|
35
|
+
import {BackToInstructionListLink} from './instruction/BackToInstructionsLink'
|
|
36
|
+
import {SelectedFieldContextProvider, SelectedFieldContextValue} from './SelectedFieldContext'
|
|
36
37
|
|
|
37
38
|
const EMPTY_FIELDS: AssistField[] = []
|
|
38
39
|
|
|
@@ -96,7 +97,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
|
|
|
96
97
|
documentSchema,
|
|
97
98
|
fieldSchema: fieldSchema ?? documentSchema,
|
|
98
99
|
}),
|
|
99
|
-
[fieldSchema, documentSchema]
|
|
100
|
+
[fieldSchema, documentSchema],
|
|
100
101
|
)
|
|
101
102
|
|
|
102
103
|
const title = value?.title
|
|
@@ -118,7 +119,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
|
|
|
118
119
|
typed<AssistInspectorRouteParams>({
|
|
119
120
|
...params,
|
|
120
121
|
[instructionParam]: (path[3] as KeyedSegment)?._key,
|
|
121
|
-
}) as Record<keyof AssistInspectorRouteParams, string | undefined
|
|
122
|
+
}) as Record<keyof AssistInspectorRouteParams, string | undefined>,
|
|
122
123
|
)
|
|
123
124
|
onPathOpen([])
|
|
124
125
|
} else {
|
|
@@ -126,7 +127,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
|
|
|
126
127
|
}
|
|
127
128
|
},
|
|
128
129
|
}),
|
|
129
|
-
[formCallbacks, onPathOpen, params, setParams, instruction]
|
|
130
|
+
[formCallbacks, onPathOpen, params, setParams, instruction],
|
|
130
131
|
)
|
|
131
132
|
|
|
132
133
|
useEffect(() => {
|
|
@@ -164,7 +165,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
|
|
|
164
165
|
|
|
165
166
|
function useSelectedSchema(
|
|
166
167
|
fieldPath: string | undefined,
|
|
167
|
-
documentSchema: ObjectSchemaType | undefined
|
|
168
|
+
documentSchema: ObjectSchemaType | undefined,
|
|
168
169
|
): SchemaType | undefined {
|
|
169
170
|
return useMemo(() => {
|
|
170
171
|
if (!fieldPath) {
|
|
@@ -221,7 +222,7 @@ function FieldsInitializer({
|
|
|
221
222
|
const existingInstructions = existingField?.instructions
|
|
222
223
|
const presetField = documentPresets.fields?.find((f) => f.path === pathKey)
|
|
223
224
|
return presetField?.instructions?.filter(
|
|
224
|
-
(i) => !existingInstructions?.some((ei) => ei._key === i._key)
|
|
225
|
+
(i) => !existingInstructions?.some((ei) => ei._key === i._key),
|
|
225
226
|
)
|
|
226
227
|
}, [documentPresets, pathKey, existingField])
|
|
227
228
|
|
|
@@ -248,8 +249,8 @@ function FieldsInitializer({
|
|
|
248
249
|
}),
|
|
249
250
|
],
|
|
250
251
|
'after',
|
|
251
|
-
['fields', -1]
|
|
252
|
-
)
|
|
252
|
+
['fields', -1],
|
|
253
|
+
),
|
|
253
254
|
)
|
|
254
255
|
}
|
|
255
256
|
|
|
@@ -265,11 +266,11 @@ function FieldsInitializer({
|
|
|
265
266
|
...preset,
|
|
266
267
|
_type: 'sanity.assist.instruction',
|
|
267
268
|
prompt: preset.prompt?.map((p) => ({markDefs: [], ...p})),
|
|
268
|
-
})
|
|
269
|
+
}),
|
|
269
270
|
),
|
|
270
271
|
'after',
|
|
271
|
-
['fields', {_key: pathKey}, 'instructions', -1]
|
|
272
|
-
)
|
|
272
|
+
['fields', {_key: pathKey}, 'instructions', -1],
|
|
273
|
+
),
|
|
273
274
|
)
|
|
274
275
|
}
|
|
275
276
|
onChange(event)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {useContext} from 'react'
|
|
2
|
-
import {useSelectedField} from '../../assistInspector/helpers'
|
|
3
1
|
import {Box, Flex, Text} from '@sanity/ui'
|
|
2
|
+
import {useContext} from 'react'
|
|
4
3
|
import {PreviewProps} from 'sanity'
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
import {InlineBlockValueContext} from '../../assistFormComponents/AssistInlineFormBlock'
|
|
6
|
+
import {useSelectedField} from '../../assistInspector/helpers'
|
|
7
|
+
import {SelectedFieldContext} from './SelectedFieldContext'
|
|
7
8
|
|
|
8
9
|
export function FieldRefPreview(props: PreviewProps & {path?: string}) {
|
|
9
10
|
const documentSchema = useContext(SelectedFieldContext)?.documentSchema
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {ArrayOfObjectsInputProps, useCurrentUser} from 'sanity'
|
|
2
1
|
import {useMemo} from 'react'
|
|
2
|
+
import {ArrayOfObjectsInputProps, useCurrentUser} from 'sanity'
|
|
3
|
+
|
|
3
4
|
import {StudioInstruction} from '../../types'
|
|
4
5
|
|
|
5
6
|
export function InstructionsArrayInput(props: ArrayOfObjectsInputProps) {
|
|
@@ -9,7 +10,7 @@ export function InstructionsArrayInput(props: ArrayOfObjectsInputProps) {
|
|
|
9
10
|
const originalMembers = props.members
|
|
10
11
|
const value = useMemo(
|
|
11
12
|
() => (originalValue ?? []).filter((v) => !v.userId || v.userId === user?.id),
|
|
12
|
-
[originalValue, user]
|
|
13
|
+
[originalValue, user],
|
|
13
14
|
)
|
|
14
15
|
const members = useMemo(
|
|
15
16
|
() =>
|
|
@@ -20,7 +21,7 @@ export function InstructionsArrayInput(props: ArrayOfObjectsInputProps) {
|
|
|
20
21
|
const value = v?.item?.value as any
|
|
21
22
|
return !value.userId || value.userId === user?.id
|
|
22
23
|
}),
|
|
23
|
-
[originalMembers, user]
|
|
24
|
+
[originalMembers, user],
|
|
24
25
|
)
|
|
25
26
|
return props.renderDefault({...props, value, members})
|
|
26
27
|
}
|
|
@@ -2,20 +2,20 @@ import {FieldError, FieldMember, FieldSetMember, ObjectMember} from 'sanity'
|
|
|
2
2
|
|
|
3
3
|
export function findFieldMember(
|
|
4
4
|
members: ObjectMember[],
|
|
5
|
-
fieldName: string
|
|
5
|
+
fieldName: string,
|
|
6
6
|
): FieldMember | FieldError | undefined {
|
|
7
7
|
return members.find(
|
|
8
8
|
(m): m is FieldMember | FieldError =>
|
|
9
9
|
(m.kind === 'field' && m.name === fieldName) ||
|
|
10
|
-
(m.kind === 'error' && m.fieldName === fieldName)
|
|
10
|
+
(m.kind === 'error' && m.fieldName === fieldName),
|
|
11
11
|
)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function findFieldsetMember(
|
|
15
15
|
members: ObjectMember[],
|
|
16
|
-
fieldsetName: string
|
|
16
|
+
fieldsetName: string,
|
|
17
17
|
): FieldSetMember | undefined {
|
|
18
18
|
return members.find(
|
|
19
|
-
(m): m is FieldSetMember => m.kind === 'fieldSet' && m.fieldSet.name === fieldsetName
|
|
19
|
+
(m): m is FieldSetMember => m.kind === 'fieldSet' && m.fieldSet.name === fieldsetName,
|
|
20
20
|
)
|
|
21
21
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import {ArrowLeftIcon} from '@sanity/icons'
|
|
2
2
|
import {Button} from '@sanity/ui'
|
|
3
3
|
import {useCallback} from 'react'
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {useDocumentPane} from 'sanity/structure'
|
|
5
|
+
|
|
6
6
|
import {aiInspectorId} from '../../../assistInspector/constants'
|
|
7
|
+
import {instructionParam} from '../../../types'
|
|
7
8
|
|
|
8
9
|
export function BackToInstructionListLink() {
|
|
9
10
|
const {openInspector} = useDocumentPane()
|
|
10
11
|
|
|
11
12
|
const goBack = useCallback(
|
|
12
13
|
() => openInspector(aiInspectorId, {[instructionParam]: undefined as any}),
|
|
13
|
-
[openInspector]
|
|
14
|
+
[openInspector],
|
|
14
15
|
)
|
|
15
16
|
|
|
16
17
|
return (
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {set, StringInputProps} from 'sanity'
|
|
2
|
-
import {useCallback, useContext, useEffect, useId, useRef} from 'react'
|
|
3
1
|
import {Box} from '@sanity/ui'
|
|
4
|
-
import {
|
|
2
|
+
import {useCallback, useContext, useEffect, useId, useRef} from 'react'
|
|
3
|
+
import {set, StringInputProps} from 'sanity'
|
|
4
|
+
|
|
5
5
|
import {FieldAutocomplete} from '../../../assistInspector/FieldAutocomplete'
|
|
6
6
|
import {FieldRef} from '../../../assistInspector/helpers'
|
|
7
7
|
import {TypePathContext} from '../AssistDocumentForm'
|
|
8
|
+
import {SelectedFieldContext} from '../SelectedFieldContext'
|
|
8
9
|
|
|
9
10
|
export function FieldRefPathInput(props: StringInputProps) {
|
|
10
11
|
const documentSchema = useContext(SelectedFieldContext)?.documentSchema
|
|
@@ -33,7 +34,7 @@ export function FieldRefPathInput(props: StringInputProps) {
|
|
|
33
34
|
const mustStartWith = fieldSegments.slice(0, lastArrayItemIndex + 1).join('.')
|
|
34
35
|
return typePath.startsWith(mustStartWith)
|
|
35
36
|
},
|
|
36
|
-
[typePath]
|
|
37
|
+
[typePath],
|
|
37
38
|
)
|
|
38
39
|
if (!documentSchema) {
|
|
39
40
|
return props.renderDefault(props)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {FieldError, FieldMember, ObjectInputMember, ObjectInputProps} from 'sanity'
|
|
2
|
-
import {findFieldMember, findFieldsetMember} from '../helpers'
|
|
3
1
|
import {Box, Flex, Stack, Text} from '@sanity/ui'
|
|
4
2
|
import {useId, useMemo} from 'react'
|
|
3
|
+
import {FieldError, FieldMember, ObjectInputMember, ObjectInputProps} from 'sanity'
|
|
4
|
+
|
|
5
|
+
import {findFieldMember, findFieldsetMember} from '../helpers'
|
|
5
6
|
|
|
6
7
|
export function InstructionInput(props: ObjectInputProps) {
|
|
7
8
|
return (
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {useCallback, useContext, useState} from 'react'
|
|
1
2
|
import {
|
|
2
3
|
ArrayFieldProps,
|
|
3
4
|
ArraySchemaType,
|
|
@@ -5,7 +6,7 @@ import {
|
|
|
5
6
|
isObjectSchemaType,
|
|
6
7
|
ObjectSchemaType,
|
|
7
8
|
} from 'sanity'
|
|
8
|
-
|
|
9
|
+
|
|
9
10
|
import {SelectedFieldContext} from '../SelectedFieldContext'
|
|
10
11
|
|
|
11
12
|
export function InstructionOutputField(props: ArrayFieldProps) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {Card, Checkbox, Flex, Stack, Text} from '@sanity/ui'
|
|
2
|
+
import {useCallback, useContext, useEffect, useMemo} from 'react'
|
|
1
3
|
import {
|
|
2
4
|
ArrayOfObjectsInputProps,
|
|
3
5
|
ArraySchemaType,
|
|
@@ -11,12 +13,11 @@ import {
|
|
|
11
13
|
typed,
|
|
12
14
|
unset,
|
|
13
15
|
} from 'sanity'
|
|
14
|
-
|
|
15
|
-
import {SelectedFieldContext} from '../SelectedFieldContext'
|
|
16
|
-
import {Card, Checkbox, Flex, Stack, Text} from '@sanity/ui'
|
|
17
|
-
import {isType} from '../../../helpers/typeUtils'
|
|
16
|
+
|
|
18
17
|
import {isAssistSupported} from '../../../helpers/assistSupported'
|
|
18
|
+
import {isType} from '../../../helpers/typeUtils'
|
|
19
19
|
import {OutputFieldItem, outputFieldTypeName, OutputTypeItem} from '../../../types'
|
|
20
|
+
import {SelectedFieldContext} from '../SelectedFieldContext'
|
|
20
21
|
|
|
21
22
|
export function InstructionOutputInput(props: ArrayOfObjectsInputProps) {
|
|
22
23
|
const {fieldSchema} = useContext(SelectedFieldContext) ?? {}
|
|
@@ -38,13 +39,13 @@ export function InstructionOutputInput(props: ArrayOfObjectsInputProps) {
|
|
|
38
39
|
function useEmptySelectAllValue(
|
|
39
40
|
value: (OutputTypeItem | OutputFieldItem)[],
|
|
40
41
|
allowedValues: {name: string}[],
|
|
41
|
-
onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void
|
|
42
|
+
onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void,
|
|
42
43
|
) {
|
|
43
44
|
useEffect(() => {
|
|
44
45
|
const validValues = value?.filter((v) =>
|
|
45
46
|
allowedValues.find(
|
|
46
|
-
(f) => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type)
|
|
47
|
-
)
|
|
47
|
+
(f) => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type),
|
|
48
|
+
),
|
|
48
49
|
)
|
|
49
50
|
const valueLength = value?.length ?? 0
|
|
50
51
|
const validLength = validValues?.length ?? 0
|
|
@@ -65,7 +66,7 @@ function ObjectOutputInput({
|
|
|
65
66
|
|
|
66
67
|
const fields = useMemo(
|
|
67
68
|
() => fieldSchema.fields.filter((field) => isAssistSupported(field.type)),
|
|
68
|
-
[fieldSchema.fields]
|
|
69
|
+
[fieldSchema.fields],
|
|
69
70
|
)
|
|
70
71
|
|
|
71
72
|
useEmptySelectAllValue(value as OutputTypeItem[], fields, onChange)
|
|
@@ -84,7 +85,7 @@ function ObjectOutputInput({
|
|
|
84
85
|
_key: field.name,
|
|
85
86
|
_type: 'sanity.assist.output.field',
|
|
86
87
|
relativePath: field.name,
|
|
87
|
-
})
|
|
88
|
+
}),
|
|
88
89
|
)
|
|
89
90
|
onChange(PatchEvent.from([setIfMissing([]), insert(items, 'after', [-1])]))
|
|
90
91
|
}
|
|
@@ -97,7 +98,7 @@ function ObjectOutputInput({
|
|
|
97
98
|
onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], 'after', [-1])]))
|
|
98
99
|
}
|
|
99
100
|
},
|
|
100
|
-
[onChange, value, fields]
|
|
101
|
+
[onChange, value, fields],
|
|
101
102
|
)
|
|
102
103
|
|
|
103
104
|
return (
|
|
@@ -126,7 +127,7 @@ function ArrayOutputInput({
|
|
|
126
127
|
|
|
127
128
|
const ofItems = useMemo(
|
|
128
129
|
() => fieldSchema.of.filter((itemType) => isAssistSupported(itemType)),
|
|
129
|
-
[fieldSchema.of]
|
|
130
|
+
[fieldSchema.of],
|
|
130
131
|
)
|
|
131
132
|
|
|
132
133
|
useEmptySelectAllValue(value as OutputTypeItem[], ofItems, onChange)
|
|
@@ -145,7 +146,7 @@ function ArrayOutputInput({
|
|
|
145
146
|
_key: field.name,
|
|
146
147
|
_type: 'sanity.assist.output.type',
|
|
147
148
|
type: field.name,
|
|
148
|
-
})
|
|
149
|
+
}),
|
|
149
150
|
)
|
|
150
151
|
onChange(PatchEvent.from([setIfMissing([]), insert(items, 'after', [-1])]))
|
|
151
152
|
}
|
|
@@ -158,7 +159,7 @@ function ArrayOutputInput({
|
|
|
158
159
|
onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], 'after', [-1])]))
|
|
159
160
|
}
|
|
160
161
|
},
|
|
161
|
-
[onChange, value, ofItems]
|
|
162
|
+
[onChange, value, ofItems],
|
|
162
163
|
)
|
|
163
164
|
return (
|
|
164
165
|
<Stack space={2}>
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {ArrayOfObjectsInputProps, set, typed} from 'sanity'
|
|
2
1
|
import {Box} from '@sanity/ui'
|
|
3
|
-
import styled from 'styled-components'
|
|
4
2
|
import {useEffect} from 'react'
|
|
5
|
-
import {
|
|
3
|
+
import {type ArrayOfObjectsInputProps, set, typed} from 'sanity'
|
|
4
|
+
import {styled} from 'styled-components'
|
|
5
|
+
|
|
6
6
|
import {randomKey} from '../../../_lib/randomKey'
|
|
7
|
+
import type {
|
|
8
|
+
ContextBlock,
|
|
9
|
+
FieldRef,
|
|
10
|
+
PromptBlock,
|
|
11
|
+
PromptTextBlock,
|
|
12
|
+
UserInputBlock,
|
|
13
|
+
} from '../../../types'
|
|
7
14
|
|
|
8
15
|
const PteMods = styled(Box)`
|
|
9
16
|
& [data-testid='pt-editor__toolbar-card'] > div > div:last-child {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {icons} from '@sanity/icons'
|
|
2
|
-
import {set, StringInputProps} from 'sanity'
|
|
3
2
|
import {Button, Menu, MenuButton, MenuItem} from '@sanity/ui'
|
|
4
3
|
import {ElementType, ReactNode, useCallback, useId, useMemo} from 'react'
|
|
4
|
+
import {set, StringInputProps} from 'sanity'
|
|
5
5
|
|
|
6
6
|
export function IconInput(props: StringInputProps) {
|
|
7
7
|
const {value, onChange} = props
|
|
@@ -11,7 +11,7 @@ export function IconInput(props: StringInputProps) {
|
|
|
11
11
|
Object.entries(icons).map(([key, icon]) => (
|
|
12
12
|
<IconItem key={key} iconKey={key} icon={icon} onChange={onChange} />
|
|
13
13
|
)),
|
|
14
|
-
[onChange]
|
|
14
|
+
[onChange],
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
const selectedIcon = useMemo(() => getIcon(value), [value])
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {set, StringInputProps, unset, useCurrentUser} from 'sanity'
|
|
2
1
|
import {Card, Flex, Switch, Text} from '@sanity/ui'
|
|
3
2
|
import {useCallback, useId} from 'react'
|
|
3
|
+
import {set, StringInputProps, unset, useCurrentUser} from 'sanity'
|
|
4
4
|
|
|
5
5
|
export function InstructionVisibility(props: StringInputProps) {
|
|
6
6
|
const {value, onChange} = props
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {getPublishedId, ObjectSchemaType, useEditState} from 'sanity'
|
|
2
|
-
import {useStudioAssistDocument} from './useStudioAssistDocument'
|
|
3
|
-
import {AssistDocumentContextValue} from '../AssistDocumentContext'
|
|
4
1
|
import {useMemo} from 'react'
|
|
5
|
-
import {
|
|
6
|
-
import {useDocumentPane} from 'sanity/
|
|
2
|
+
import {getPublishedId, type ObjectSchemaType, useEditState} from 'sanity'
|
|
3
|
+
import {useDocumentPane} from 'sanity/structure'
|
|
4
|
+
|
|
7
5
|
import {useAiPaneRouter} from '../../assistInspector/helpers'
|
|
8
6
|
import {fieldPathParam} from '../../types'
|
|
7
|
+
import type {AssistDocumentContextValue} from '../AssistDocumentContext'
|
|
8
|
+
import {isDocAssistable} from '../RequestRunInstructionProvider'
|
|
9
|
+
import {useStudioAssistDocument} from './useStudioAssistDocument'
|
|
9
10
|
|
|
10
11
|
export function useAssistDocumentContextValue(
|
|
11
12
|
documentId: string,
|
|
12
|
-
documentSchemaType: ObjectSchemaType
|
|
13
|
+
documentSchemaType: ObjectSchemaType,
|
|
13
14
|
) {
|
|
14
15
|
const {published, draft} = useEditState(
|
|
15
16
|
getPublishedId(documentId),
|
|
16
17
|
documentSchemaType.name,
|
|
17
|
-
'low'
|
|
18
|
+
'low',
|
|
18
19
|
)
|
|
19
20
|
const assistableDocumentId = draft?._id || published?._id || documentId
|
|
20
21
|
const documentIsNew = Boolean(!draft?._id && !published?._id)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {InstructionTask} from '../../types'
|
|
1
|
+
import {useToast} from '@sanity/ui'
|
|
3
2
|
import {addSeconds, isAfter} from 'date-fns'
|
|
3
|
+
import {useEffect, useRef} from 'react'
|
|
4
|
+
import {ObjectSchemaType, useCurrentUser} from 'sanity'
|
|
5
|
+
|
|
4
6
|
import {getInstructionTitle} from '../../helpers/misc'
|
|
7
|
+
import {InstructionTask} from '../../types'
|
|
5
8
|
import {useStudioAssistDocument} from './useStudioAssistDocument'
|
|
6
|
-
import {ObjectSchemaType, useCurrentUser} from 'sanity'
|
|
7
|
-
import {useToast} from '@sanity/ui'
|
|
8
9
|
|
|
9
10
|
const NO_TASKS: InstructionTask[] = []
|
|
10
11
|
|
|
@@ -24,7 +25,7 @@ export function useInstructionToaster(documentId: string, documentSchemaType: Ob
|
|
|
24
25
|
|
|
25
26
|
if (previousTasks.current !== 'initial') {
|
|
26
27
|
const prevTaskByKey = Object.fromEntries(
|
|
27
|
-
(previousTasks.current ?? NO_TASKS).map((run) => [run._key, run])
|
|
28
|
+
(previousTasks.current ?? NO_TASKS).map((run) => [run._key, run]),
|
|
28
29
|
)
|
|
29
30
|
const endedTasks = tasks
|
|
30
31
|
?.filter((task) => task.startedByUserId === currentUser?.id)
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import {useEffect, useMemo} from 'react'
|
|
2
|
+
import {type ObjectSchemaType, typed, useClient, useCurrentUser} from 'sanity'
|
|
3
|
+
|
|
4
|
+
import {maxHistoryVisibilityMs} from '../../constants'
|
|
5
|
+
import {assistDocumentId, assistTasksStatusId} from '../../helpers/ids'
|
|
2
6
|
import {
|
|
3
7
|
assistDocumentTypeName,
|
|
4
|
-
AssistTasksStatus,
|
|
8
|
+
type AssistTasksStatus,
|
|
5
9
|
assistTasksStatusTypeName,
|
|
6
|
-
InstructionTask,
|
|
7
|
-
StudioAssistDocument,
|
|
8
|
-
StudioAssistField,
|
|
9
|
-
StudioInstruction,
|
|
10
|
+
type InstructionTask,
|
|
11
|
+
type StudioAssistDocument,
|
|
12
|
+
type StudioAssistField,
|
|
13
|
+
type StudioInstruction,
|
|
10
14
|
} from '../../types'
|
|
11
|
-
import {ObjectSchemaType, typed, useClient, useCurrentUser} from 'sanity'
|
|
12
15
|
import {useDocumentState} from './useDocumentState'
|
|
13
|
-
import {assistDocumentId, assistTasksStatusId} from '../../helpers/ids'
|
|
14
|
-
import {maxHistoryVisibilityMs} from '../../constants'
|
|
15
16
|
|
|
16
17
|
interface UseAssistDocumentProps {
|
|
17
18
|
documentId: string
|
|
@@ -29,11 +30,11 @@ export function useStudioAssistDocument({
|
|
|
29
30
|
|
|
30
31
|
const assistDocument = useDocumentState<StudioAssistDocument>(
|
|
31
32
|
assistDocumentId(documentTypeName),
|
|
32
|
-
assistDocumentTypeName
|
|
33
|
+
assistDocumentTypeName,
|
|
33
34
|
)
|
|
34
35
|
const assistTasksStatus = useDocumentState<AssistTasksStatus>(
|
|
35
36
|
assistTasksStatusId(documentId ?? ''),
|
|
36
|
-
assistTasksStatusTypeName
|
|
37
|
+
assistTasksStatusTypeName,
|
|
37
38
|
)
|
|
38
39
|
|
|
39
40
|
const client = useClient({apiVersion: '2023-01-01'})
|
|
@@ -45,7 +46,7 @@ export function useStudioAssistDocument({
|
|
|
45
46
|
_id: assistDocumentId(documentTypeName),
|
|
46
47
|
_type: assistDocumentTypeName,
|
|
47
48
|
})
|
|
48
|
-
.catch((
|
|
49
|
+
.catch(() => {
|
|
49
50
|
// best effort
|
|
50
51
|
})
|
|
51
52
|
}
|
|
@@ -83,7 +84,7 @@ export function useStudioAssistDocument({
|
|
|
83
84
|
|
|
84
85
|
function asStudioInstruction(
|
|
85
86
|
instruction: StudioInstruction,
|
|
86
|
-
run: InstructionTask[]
|
|
87
|
+
run: InstructionTask[],
|
|
87
88
|
): StudioInstruction {
|
|
88
89
|
return {
|
|
89
90
|
...instruction,
|
|
@@ -92,7 +93,7 @@ function asStudioInstruction(
|
|
|
92
93
|
.filter(
|
|
93
94
|
(task) =>
|
|
94
95
|
task.started &&
|
|
95
|
-
new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs
|
|
96
|
+
new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs,
|
|
96
97
|
),
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {FieldProps, isArraySchemaType, pathToString} from 'sanity'
|
|
2
|
-
import {useAssistPresence} from '../presence/useAssistPresence'
|
|
3
|
-
import {useContext, useMemo} from 'react'
|
|
4
1
|
import {Box, Flex} from '@sanity/ui'
|
|
5
|
-
import {
|
|
2
|
+
import {useContext, useMemo} from 'react'
|
|
3
|
+
import {FieldProps, isArraySchemaType, pathToString} from 'sanity'
|
|
4
|
+
|
|
5
|
+
import {assistFormId} from '../_lib/form/constants'
|
|
6
6
|
import {isAssistSupported} from '../helpers/assistSupported'
|
|
7
7
|
import {isPortableTextArray, isType} from '../helpers/typeUtils'
|
|
8
|
-
import {AiFieldPresence} from '../presence/AiFieldPresence'
|
|
9
8
|
import {AssistOnboardingPopover} from '../onboarding/FieldActionsOnboarding'
|
|
10
9
|
import {FirstAssistedPathContext} from '../onboarding/FirstAssistedPathProvider'
|
|
11
10
|
import {fieldOnboardingKey, useOnboardingFeature} from '../onboarding/onboardingStore'
|
|
12
|
-
import {
|
|
11
|
+
import {AiFieldPresence} from '../presence/AiFieldPresence'
|
|
12
|
+
import {useAssistPresence} from '../presence/useAssistPresence'
|
|
13
|
+
import {contextDocumentTypeName} from '../types'
|
|
13
14
|
|
|
14
15
|
export function AssistFieldWrapper(props: FieldProps) {
|
|
15
16
|
const {schemaType} = props
|
|
@@ -39,7 +40,7 @@ export function AssistField(props: FieldProps) {
|
|
|
39
40
|
|
|
40
41
|
const isPortableText = useMemo(
|
|
41
42
|
() => !!(isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)),
|
|
42
|
-
[props.schemaType]
|
|
43
|
+
[props.schemaType],
|
|
43
44
|
)
|
|
44
45
|
|
|
45
46
|
const presence = useAssistPresence(props.path, isPortableText)
|
|
@@ -47,7 +48,7 @@ export function AssistField(props: FieldProps) {
|
|
|
47
48
|
const firstAssistedPath = useContext(FirstAssistedPathContext)
|
|
48
49
|
const isFirstAssisted = useMemo(
|
|
49
50
|
() => pathToString(path) === firstAssistedPath,
|
|
50
|
-
[path, firstAssistedPath]
|
|
51
|
+
[path, firstAssistedPath],
|
|
51
52
|
)
|
|
52
53
|
|
|
53
54
|
const {showOnboarding, dismissOnboarding} = useOnboardingFeature(fieldOnboardingKey)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {BlockProps, PatchEvent, useFormCallbacks} from 'sanity'
|
|
2
|
-
import {useAssistPresence} from '../presence/useAssistPresence'
|
|
3
1
|
import {Box, Flex} from '@sanity/ui'
|
|
4
|
-
import {ErrorWrapper} from '../components/SafeValueInput'
|
|
5
2
|
import {useCallback} from 'react'
|
|
3
|
+
import {BlockProps, PatchEvent, useFormCallbacks} from 'sanity'
|
|
4
|
+
|
|
5
|
+
import {ErrorWrapper} from '../components/SafeValueInput'
|
|
6
6
|
import {AiFieldPresence} from '../presence/AiFieldPresence'
|
|
7
|
+
import {useAssistPresence} from '../presence/useAssistPresence'
|
|
7
8
|
|
|
8
9
|
export function AssistFormBlock(props: BlockProps) {
|
|
9
10
|
const presence = useAssistPresence(props.path, true)
|
|
@@ -16,7 +17,7 @@ export function AssistFormBlock(props: BlockProps) {
|
|
|
16
17
|
}
|
|
17
18
|
onChange(PatchEvent.from(patchEvent).prefixAll({_key: key}))
|
|
18
19
|
},
|
|
19
|
-
[onChange, key]
|
|
20
|
+
[onChange, key],
|
|
20
21
|
)
|
|
21
22
|
const singlePresence = presence[0]
|
|
22
23
|
return (
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {ItemProps} from 'sanity'
|
|
2
|
-
import {useAssistPresence} from '../presence/useAssistPresence'
|
|
3
1
|
import {Box, Flex} from '@sanity/ui'
|
|
2
|
+
import {ItemProps} from 'sanity'
|
|
3
|
+
|
|
4
4
|
import {AiFieldPresence} from '../presence/AiFieldPresence'
|
|
5
|
+
import {useAssistPresence} from '../presence/useAssistPresence'
|
|
5
6
|
|
|
6
7
|
export function AssistItem(props: ItemProps) {
|
|
7
8
|
const {path} = props
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Box, type ButtonTone, Flex, MenuItem, Stack, Text} from '@sanity/ui'
|
|
2
2
|
import {useCallback} from 'react'
|
|
3
|
-
import {
|
|
4
|
-
import styled from 'styled-components'
|
|
3
|
+
import type {Path, ValidationMarker} from 'sanity'
|
|
4
|
+
import {styled} from 'styled-components'
|
|
5
5
|
|
|
6
6
|
interface ValidationListItemProps {
|
|
7
7
|
marker: ValidationMarker
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {Container} from '@sanity/ui'
|
|
1
2
|
import {useCallback} from 'react'
|
|
2
3
|
import {
|
|
3
4
|
isValidationErrorMarker,
|
|
@@ -7,7 +8,7 @@ import {
|
|
|
7
8
|
Path,
|
|
8
9
|
ValidationMarker,
|
|
9
10
|
} from 'sanity'
|
|
10
|
-
|
|
11
|
+
|
|
11
12
|
import {ListItem} from './listItem'
|
|
12
13
|
|
|
13
14
|
/** @internal */
|
|
@@ -31,7 +32,7 @@ export function ValidationList(props: ValidationListProps) {
|
|
|
31
32
|
if (onFocus) onFocus(path)
|
|
32
33
|
if (onClose) onClose()
|
|
33
34
|
},
|
|
34
|
-
[onFocus, onClose]
|
|
35
|
+
[onFocus, onClose],
|
|
35
36
|
)
|
|
36
37
|
|
|
37
38
|
const resolvePathTitle = (path: Path) => {
|