@sanity/assist 2.0.2 → 2.0.3

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": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "You create the instructions; Sanity AI Assist does the rest.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -5,6 +5,7 @@ import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
5
5
  import {canUseAssist, useApiClient, useGenerateCaption} from '../useApiClient'
6
6
  import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
7
7
  import {publicId} from '../helpers/ids'
8
+ import {usePaneRouter} from 'sanity/desk'
8
9
 
9
10
  export interface ImageContextValue {
10
11
  imageDescriptionPath?: string
@@ -15,7 +16,7 @@ export interface ImageContextValue {
15
16
  export const ImageContext = createContext<ImageContextValue>({})
16
17
 
17
18
  export function ImageContextProvider(props: InputProps) {
18
- const {schemaType, path, value} = props
19
+ const {schemaType, path, value, readOnly} = props
19
20
  const assetRef = (value as any)?.asset?._ref
20
21
  const [assetRefState, setAssetRefState] = useState<string | undefined>(assetRef)
21
22
 
@@ -26,15 +27,37 @@ export function ImageContextProvider(props: InputProps) {
26
27
 
27
28
  const {isSyncing} = useSyncState(publicId(documentId), documentSchemaType.name)
28
29
 
30
+ const router = usePaneRouter()
31
+ const isShowingOlderRevision = !!router.params?.rev
32
+
29
33
  useEffect(() => {
30
34
  const descriptionField = getDescriptionFieldOption(schemaType)
31
- if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing) {
35
+ if (
36
+ assetRef &&
37
+ documentId &&
38
+ descriptionField &&
39
+ assetRef !== assetRefState &&
40
+ !isSyncing &&
41
+ !isShowingOlderRevision &&
42
+ !readOnly
43
+ ) {
32
44
  setAssetRefState(assetRef)
33
45
  if (canUseAssist(status)) {
34
46
  generateCaption({path: pathToString([...path, descriptionField]), documentId: documentId})
35
47
  }
36
48
  }
37
- }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing, status])
49
+ }, [
50
+ schemaType,
51
+ path,
52
+ assetRef,
53
+ assetRefState,
54
+ documentId,
55
+ generateCaption,
56
+ isSyncing,
57
+ status,
58
+ readOnly,
59
+ isShowingOlderRevision,
60
+ ])
38
61
 
39
62
  const context: ImageContextValue = useMemo(() => {
40
63
  const descriptionField = getDescriptionFieldOption(schemaType)