@sanity/assist 4.1.0 → 4.2.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 CHANGED
@@ -407,6 +407,16 @@ The **Generate image description** action will automatically run whenever the im
407
407
  `imageDescriptionField` can be a nested field, if the image has an object field, i.e. `imageDescriptionField: 'wrapper.altText'`.
408
408
  Fields within array items are not supported.
409
409
 
410
+ By default, the caption field will regenerate whenever the image asset changes. To disable this behavior use the following configuration:
411
+ ```ts
412
+ {
413
+ imageDescriptionField: {
414
+ path: 'wrapper.altText',
415
+ updateOnImageChange: false
416
+ }
417
+ }
418
+ ```
419
+
410
420
  ## Image generation
411
421
 
412
422
  <img width="600" alt="image" src="https://github.com/sanity-io/assist/assets/835514/c4de6791-f530-4cd1-b0c2-96ef988bc256">
package/dist/index.d.mts CHANGED
@@ -474,7 +474,18 @@ declare module 'sanity' {
474
474
  * })
475
475
  * ```
476
476
  */
477
- imageDescriptionField?: string
477
+ imageDescriptionField?:
478
+ | string
479
+ | {
480
+ path: string
481
+ /**
482
+ * When updateOnImageChange is true (or undefined), whenever the
483
+ * image asset changes, imageDescriptionField will be regenerated.
484
+ *
485
+ * default: true
486
+ * */
487
+ updateOnImageChange?: boolean
488
+ }
478
489
  }
479
490
  }
480
491
  interface NumberOptions extends AssistOptions {}
package/dist/index.d.ts CHANGED
@@ -474,7 +474,18 @@ declare module 'sanity' {
474
474
  * })
475
475
  * ```
476
476
  */
477
- imageDescriptionField?: string
477
+ imageDescriptionField?:
478
+ | string
479
+ | {
480
+ path: string
481
+ /**
482
+ * When updateOnImageChange is true (or undefined), whenever the
483
+ * image asset changes, imageDescriptionField will be regenerated.
484
+ *
485
+ * default: true
486
+ * */
487
+ updateOnImageChange?: boolean
488
+ }
478
489
  }
479
490
  }
480
491
  interface NumberOptions extends AssistOptions {}
package/dist/index.esm.js CHANGED
@@ -221,7 +221,16 @@ function isImage(schemaType) {
221
221
  return isType(schemaType, "image");
222
222
  }
223
223
  function getDescriptionFieldOption(schemaType) {
224
- return schemaType ? schemaType.options?.aiAssist?.imageDescriptionField || getDescriptionFieldOption(schemaType.type) : void 0;
224
+ if (!schemaType)
225
+ return;
226
+ const descriptionField = schemaType.options?.aiAssist?.imageDescriptionField;
227
+ return typeof descriptionField == "string" ? {
228
+ path: descriptionField,
229
+ updateOnImageChange: !0
230
+ } : descriptionField ? {
231
+ path: descriptionField.path,
232
+ updateOnImageChange: descriptionField.updateOnImageChange ?? !0
233
+ } : getDescriptionFieldOption(schemaType.type);
225
234
  }
226
235
  function getImageInstructionFieldOption(schemaType) {
227
236
  return schemaType ? schemaType.options?.aiAssist?.imageInstructionField || getImageInstructionFieldOption(schemaType.type) : void 0;
@@ -2574,8 +2583,8 @@ function ImageContextProvider(props) {
2574
2583
  ), isShowingOlderRevision = !!usePaneRouter().params?.rev;
2575
2584
  useEffect(() => {
2576
2585
  const descriptionField = getDescriptionFieldOption(schemaType);
2577
- assetRef && assistableDocumentId && descriptionField && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly && (setAssetRefState(assetRef), canUseAssist(status) && generateCaption({
2578
- path: pathToString([...path, descriptionField]),
2586
+ assetRef && assistableDocumentId && descriptionField?.updateOnImageChange && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly && (setAssetRefState(assetRef), canUseAssist(status) && generateCaption({
2587
+ path: pathToString([...path, descriptionField.path]),
2579
2588
  documentId: assistableDocumentId
2580
2589
  }));
2581
2590
  }, [
@@ -2593,7 +2602,7 @@ function ImageContextProvider(props) {
2593
2602
  const context = useMemo(() => {
2594
2603
  const descriptionField = getDescriptionFieldOption(schemaType), imageInstructionField = getImageInstructionFieldOption(schemaType);
2595
2604
  return {
2596
- imageDescriptionPath: descriptionField ? pathToString([...path, descriptionField]) : void 0,
2605
+ imageDescriptionPath: descriptionField?.path ? pathToString([...path, descriptionField.path]) : void 0,
2597
2606
  imageInstructionPath: imageInstructionField ? pathToString([...path, imageInstructionField]) : void 0,
2598
2607
  assetRef
2599
2608
  };