@sanity/assist 1.2.10 → 1.2.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/assist",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "sanity",
@@ -1,5 +1,4 @@
1
1
  import {BlockProps} from 'sanity'
2
- import {Box} from '@sanity/ui'
3
2
  import {createContext} from 'react'
4
3
 
5
4
  // workaround for preview value sometimes lagging behind
@@ -8,7 +7,7 @@ export const InlineBlockValueContext = createContext<unknown>(undefined)
8
7
  export function AssistInlineFormBlock(props: BlockProps) {
9
8
  return (
10
9
  <InlineBlockValueContext.Provider value={props.value}>
11
- <Box flex={1}>{props.renderDefault(props)}</Box>
10
+ <>{props.renderDefault(props)}</>
12
11
  </InlineBlockValueContext.Provider>
13
12
  )
14
13
  }
@@ -1,9 +1,10 @@
1
1
  import {createContext, useEffect, useMemo, useState} from 'react'
2
- import {InputProps, pathToString} from 'sanity'
2
+ import {InputProps, pathToString, useSyncState} from 'sanity'
3
3
  import {getCaptionFieldOption} from '../helpers/typeUtils'
4
4
  import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
5
5
  import {useApiClient, useGenerateCaption} from '../useApiClient'
6
6
  import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
7
+ import {publicId} from '../helpers/ids'
7
8
 
8
9
  export interface ImageContextValue {
9
10
  captionPath: string
@@ -17,18 +18,20 @@ export function ImageContextProvider(props: InputProps) {
17
18
  const assetRef = (value as any)?.asset?._ref
18
19
  const [assetRefState, setAssetRefState] = useState<string | undefined>(assetRef)
19
20
 
20
- const {documentId} = useAssistDocumentContext()
21
+ const {documentId, documentSchemaType} = useAssistDocumentContext()
21
22
  const {config} = useAiAssistanceConfig()
22
23
  const apiClient = useApiClient(config?.__customApiClient)
23
24
  const {generateCaption} = useGenerateCaption(apiClient)
24
25
 
26
+ const {isSyncing} = useSyncState(publicId(documentId), documentSchemaType.name)
27
+
25
28
  useEffect(() => {
26
29
  const captionField = getCaptionFieldOption(schemaType)
27
- if (assetRef && documentId && captionField && assetRef !== assetRefState) {
30
+ if (assetRef && documentId && captionField && assetRef !== assetRefState && !isSyncing) {
28
31
  setAssetRefState(assetRef)
29
32
  generateCaption({path: pathToString([...path, captionField]), documentId: documentId})
30
33
  }
31
- }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption])
34
+ }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing])
32
35
 
33
36
  const context: ImageContextValue | undefined = useMemo(() => {
34
37
  const captionField = getCaptionFieldOption(schemaType)