@sanity/assist 2.0.1 → 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/dist/index.esm.js
CHANGED
|
@@ -1865,6 +1865,7 @@ function FieldsInitializer(_ref9) {
|
|
|
1865
1865
|
}, [documentPresets, pathKey, existingField]);
|
|
1866
1866
|
const initialized = useRef(false);
|
|
1867
1867
|
useEffect(() => {
|
|
1868
|
+
var _a;
|
|
1868
1869
|
if (initialized.current || !pathKey) {
|
|
1869
1870
|
return;
|
|
1870
1871
|
}
|
|
@@ -1876,16 +1877,22 @@ function FieldsInitializer(_ref9) {
|
|
|
1876
1877
|
event = event.append(insert([typed({
|
|
1877
1878
|
_key: pathKey,
|
|
1878
1879
|
_type: assistFieldTypeName,
|
|
1879
|
-
path: pathKey
|
|
1880
|
+
path: pathKey,
|
|
1881
|
+
instructions: []
|
|
1880
1882
|
})], "after", ["fields", -1]));
|
|
1881
1883
|
}
|
|
1884
|
+
if (!((_a = existingField == null ? void 0 : existingField.instructions) == null ? void 0 : _a.length)) {
|
|
1885
|
+
event = event.append([setIfMissing([], ["fields", {
|
|
1886
|
+
_key: pathKey
|
|
1887
|
+
}, "instructions"])]);
|
|
1888
|
+
}
|
|
1882
1889
|
if (missingPresetInstructions == null ? void 0 : missingPresetInstructions.length) {
|
|
1883
1890
|
event = event.append(insert(missingPresetInstructions.map(preset => {
|
|
1884
|
-
var
|
|
1891
|
+
var _a2;
|
|
1885
1892
|
return {
|
|
1886
1893
|
...preset,
|
|
1887
1894
|
_type: "sanity.assist.instruction",
|
|
1888
|
-
prompt: (
|
|
1895
|
+
prompt: (_a2 = preset.prompt) == null ? void 0 : _a2.map(p => ({
|
|
1889
1896
|
markDefs: [],
|
|
1890
1897
|
...p
|
|
1891
1898
|
}))
|
|
@@ -6166,11 +6173,12 @@ function PrivateIcon() {
|
|
|
6166
6173
|
}
|
|
6167
6174
|
const ImageContext = createContext({});
|
|
6168
6175
|
function ImageContextProvider(props) {
|
|
6169
|
-
var _a;
|
|
6176
|
+
var _a, _b;
|
|
6170
6177
|
const {
|
|
6171
6178
|
schemaType,
|
|
6172
6179
|
path,
|
|
6173
|
-
value
|
|
6180
|
+
value,
|
|
6181
|
+
readOnly
|
|
6174
6182
|
} = props;
|
|
6175
6183
|
const assetRef = (_a = value == null ? void 0 : value.asset) == null ? void 0 : _a._ref;
|
|
6176
6184
|
const [assetRefState, setAssetRefState] = useState(assetRef);
|
|
@@ -6189,16 +6197,20 @@ function ImageContextProvider(props) {
|
|
|
6189
6197
|
const {
|
|
6190
6198
|
isSyncing
|
|
6191
6199
|
} = useSyncState(publicId(documentId), documentSchemaType.name);
|
|
6200
|
+
const router = usePaneRouter();
|
|
6201
|
+
const isShowingOlderRevision = !!((_b = router.params) == null ? void 0 : _b.rev);
|
|
6192
6202
|
useEffect(() => {
|
|
6193
6203
|
const descriptionField = getDescriptionFieldOption(schemaType);
|
|
6194
|
-
if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing &&
|
|
6204
|
+
if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly) {
|
|
6195
6205
|
setAssetRefState(assetRef);
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6206
|
+
if (canUseAssist(status)) {
|
|
6207
|
+
generateCaption({
|
|
6208
|
+
path: pathToString([...path, descriptionField]),
|
|
6209
|
+
documentId
|
|
6210
|
+
});
|
|
6211
|
+
}
|
|
6200
6212
|
}
|
|
6201
|
-
}, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing, status]);
|
|
6213
|
+
}, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing, status, readOnly, isShowingOlderRevision]);
|
|
6202
6214
|
const context = useMemo(() => {
|
|
6203
6215
|
const descriptionField = getDescriptionFieldOption(schemaType);
|
|
6204
6216
|
const imageInstructionField = getImageInstructionFieldOption(schemaType);
|