@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.js CHANGED
@@ -1878,6 +1878,7 @@ function FieldsInitializer(_ref9) {
1878
1878
  }, [documentPresets, pathKey, existingField]);
1879
1879
  const initialized = react.useRef(false);
1880
1880
  react.useEffect(() => {
1881
+ var _a;
1881
1882
  if (initialized.current || !pathKey) {
1882
1883
  return;
1883
1884
  }
@@ -1889,16 +1890,22 @@ function FieldsInitializer(_ref9) {
1889
1890
  event = event.append(sanity.insert([sanity.typed({
1890
1891
  _key: pathKey,
1891
1892
  _type: assistFieldTypeName,
1892
- path: pathKey
1893
+ path: pathKey,
1894
+ instructions: []
1893
1895
  })], "after", ["fields", -1]));
1894
1896
  }
1897
+ if (!((_a = existingField == null ? void 0 : existingField.instructions) == null ? void 0 : _a.length)) {
1898
+ event = event.append([sanity.setIfMissing([], ["fields", {
1899
+ _key: pathKey
1900
+ }, "instructions"])]);
1901
+ }
1895
1902
  if (missingPresetInstructions == null ? void 0 : missingPresetInstructions.length) {
1896
1903
  event = event.append(sanity.insert(missingPresetInstructions.map(preset => {
1897
- var _a;
1904
+ var _a2;
1898
1905
  return {
1899
1906
  ...preset,
1900
1907
  _type: "sanity.assist.instruction",
1901
- prompt: (_a = preset.prompt) == null ? void 0 : _a.map(p => ({
1908
+ prompt: (_a2 = preset.prompt) == null ? void 0 : _a2.map(p => ({
1902
1909
  markDefs: [],
1903
1910
  ...p
1904
1911
  }))
@@ -6179,11 +6186,12 @@ function PrivateIcon() {
6179
6186
  }
6180
6187
  const ImageContext = react.createContext({});
6181
6188
  function ImageContextProvider(props) {
6182
- var _a;
6189
+ var _a, _b;
6183
6190
  const {
6184
6191
  schemaType,
6185
6192
  path,
6186
- value
6193
+ value,
6194
+ readOnly
6187
6195
  } = props;
6188
6196
  const assetRef = (_a = value == null ? void 0 : value.asset) == null ? void 0 : _a._ref;
6189
6197
  const [assetRefState, setAssetRefState] = react.useState(assetRef);
@@ -6202,16 +6210,20 @@ function ImageContextProvider(props) {
6202
6210
  const {
6203
6211
  isSyncing
6204
6212
  } = sanity.useSyncState(publicId(documentId), documentSchemaType.name);
6213
+ const router = desk.usePaneRouter();
6214
+ const isShowingOlderRevision = !!((_b = router.params) == null ? void 0 : _b.rev);
6205
6215
  react.useEffect(() => {
6206
6216
  const descriptionField = getDescriptionFieldOption(schemaType);
6207
- if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing && canUseAssist(status)) {
6217
+ if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly) {
6208
6218
  setAssetRefState(assetRef);
6209
- generateCaption({
6210
- path: sanity.pathToString([...path, descriptionField]),
6211
- documentId
6212
- });
6219
+ if (canUseAssist(status)) {
6220
+ generateCaption({
6221
+ path: sanity.pathToString([...path, descriptionField]),
6222
+ documentId
6223
+ });
6224
+ }
6213
6225
  }
6214
- }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing, status]);
6226
+ }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing, status, readOnly, isShowingOlderRevision]);
6215
6227
  const context = react.useMemo(() => {
6216
6228
  const descriptionField = getDescriptionFieldOption(schemaType);
6217
6229
  const imageInstructionField = getImageInstructionFieldOption(schemaType);