@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 +10 -0
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.esm.js +13 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/ImageContext.tsx +4 -4
- package/src/helpers/typeUtils.ts +13 -3
- package/src/schemas/typeDefExtensions.ts +12 -1
package/dist/index.js
CHANGED
|
@@ -214,7 +214,16 @@ function isImage(schemaType) {
|
|
|
214
214
|
return isType(schemaType, "image");
|
|
215
215
|
}
|
|
216
216
|
function getDescriptionFieldOption(schemaType) {
|
|
217
|
-
|
|
217
|
+
if (!schemaType)
|
|
218
|
+
return;
|
|
219
|
+
const descriptionField = schemaType.options?.aiAssist?.imageDescriptionField;
|
|
220
|
+
return typeof descriptionField == "string" ? {
|
|
221
|
+
path: descriptionField,
|
|
222
|
+
updateOnImageChange: !0
|
|
223
|
+
} : descriptionField ? {
|
|
224
|
+
path: descriptionField.path,
|
|
225
|
+
updateOnImageChange: descriptionField.updateOnImageChange ?? !0
|
|
226
|
+
} : getDescriptionFieldOption(schemaType.type);
|
|
218
227
|
}
|
|
219
228
|
function getImageInstructionFieldOption(schemaType) {
|
|
220
229
|
return schemaType ? schemaType.options?.aiAssist?.imageInstructionField || getImageInstructionFieldOption(schemaType.type) : void 0;
|
|
@@ -2567,8 +2576,8 @@ function ImageContextProvider(props) {
|
|
|
2567
2576
|
), isShowingOlderRevision = !!structure.usePaneRouter().params?.rev;
|
|
2568
2577
|
react.useEffect(() => {
|
|
2569
2578
|
const descriptionField = getDescriptionFieldOption(schemaType);
|
|
2570
|
-
assetRef && assistableDocumentId && descriptionField && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly && (setAssetRefState(assetRef), canUseAssist(status) && generateCaption({
|
|
2571
|
-
path: sanity.pathToString([...path, descriptionField]),
|
|
2579
|
+
assetRef && assistableDocumentId && descriptionField?.updateOnImageChange && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly && (setAssetRefState(assetRef), canUseAssist(status) && generateCaption({
|
|
2580
|
+
path: sanity.pathToString([...path, descriptionField.path]),
|
|
2572
2581
|
documentId: assistableDocumentId
|
|
2573
2582
|
}));
|
|
2574
2583
|
}, [
|
|
@@ -2586,7 +2595,7 @@ function ImageContextProvider(props) {
|
|
|
2586
2595
|
const context = react.useMemo(() => {
|
|
2587
2596
|
const descriptionField = getDescriptionFieldOption(schemaType), imageInstructionField = getImageInstructionFieldOption(schemaType);
|
|
2588
2597
|
return {
|
|
2589
|
-
imageDescriptionPath: descriptionField ? sanity.pathToString([...path, descriptionField]) : void 0,
|
|
2598
|
+
imageDescriptionPath: descriptionField?.path ? sanity.pathToString([...path, descriptionField.path]) : void 0,
|
|
2590
2599
|
imageInstructionPath: imageInstructionField ? sanity.pathToString([...path, imageInstructionField]) : void 0,
|
|
2591
2600
|
assetRef
|
|
2592
2601
|
};
|