@sanity/assist 1.2.9 → 1.2.11

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
@@ -3587,9 +3587,13 @@ function FieldRefPathInput(props) {
3587
3587
  if (!field.key.includes("|") || !typePath) {
3588
3588
  return true;
3589
3589
  }
3590
- const dotSplit = typePath.split(".");
3591
- const base = dotSplit.slice(0, dotSplit.length - 1).join(".");
3592
- return field.key.includes(base);
3590
+ if (field.key.includes("|") && !typePath.includes("|")) {
3591
+ return false;
3592
+ }
3593
+ const fieldSegments = field.key.split(".");
3594
+ const lastArrayItemIndex = fieldSegments.findLastIndex(s => s.includes("|"));
3595
+ const mustStartWith = fieldSegments.slice(0, lastArrayItemIndex + 1).join(".");
3596
+ return typePath.startsWith(mustStartWith);
3593
3597
  }, [typePath]);
3594
3598
  if (!documentSchema) {
3595
3599
  return props.renderDefault(props);
@@ -4307,7 +4311,8 @@ function ImageContextProvider(props) {
4307
4311
  const assetRef = (_a = value == null ? void 0 : value.asset) == null ? void 0 : _a._ref;
4308
4312
  const [assetRefState, setAssetRefState] = react.useState(assetRef);
4309
4313
  const {
4310
- documentId
4314
+ documentId,
4315
+ documentSchemaType
4311
4316
  } = useAssistDocumentContext();
4312
4317
  const {
4313
4318
  config
@@ -4316,16 +4321,19 @@ function ImageContextProvider(props) {
4316
4321
  const {
4317
4322
  generateCaption
4318
4323
  } = useGenerateCaption(apiClient);
4324
+ const {
4325
+ isSyncing
4326
+ } = sanity.useSyncState(publicId(documentId), documentSchemaType.name);
4319
4327
  react.useEffect(() => {
4320
4328
  const captionField = getCaptionFieldOption(schemaType);
4321
- if (assetRef && documentId && captionField && assetRef !== assetRefState) {
4329
+ if (assetRef && documentId && captionField && assetRef !== assetRefState && !isSyncing) {
4322
4330
  setAssetRefState(assetRef);
4323
4331
  generateCaption({
4324
4332
  path: sanity.pathToString([...path, captionField]),
4325
4333
  documentId
4326
4334
  });
4327
4335
  }
4328
- }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption]);
4336
+ }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing]);
4329
4337
  const context = react.useMemo(() => {
4330
4338
  const captionField = getCaptionFieldOption(schemaType);
4331
4339
  return captionField ? {