@sanity/assist 2.0.1 → 2.0.2

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
  }))
@@ -6204,12 +6211,14 @@ function ImageContextProvider(props) {
6204
6211
  } = sanity.useSyncState(publicId(documentId), documentSchemaType.name);
6205
6212
  react.useEffect(() => {
6206
6213
  const descriptionField = getDescriptionFieldOption(schemaType);
6207
- if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing && canUseAssist(status)) {
6214
+ if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing) {
6208
6215
  setAssetRefState(assetRef);
6209
- generateCaption({
6210
- path: sanity.pathToString([...path, descriptionField]),
6211
- documentId
6212
- });
6216
+ if (canUseAssist(status)) {
6217
+ generateCaption({
6218
+ path: sanity.pathToString([...path, descriptionField]),
6219
+ documentId
6220
+ });
6221
+ }
6213
6222
  }
6214
6223
  }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing, status]);
6215
6224
  const context = react.useMemo(() => {