sanity 5.7.0-next.18 → 5.7.0-next.20

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.
@@ -1,4 +1,4 @@
1
- var version = "5.7.0-next.18+4f5566181e", peerDependencies = {
1
+ var version = "5.7.0-next.20+4f6b9ad18d", peerDependencies = {
2
2
  "styled-components": "^6.1.15"
3
3
  };
4
4
  export {
@@ -7,7 +7,7 @@ try {
7
7
  try {
8
8
  buildVersion = buildVersion || // This is replaced by `@sanity/pkg-utils` at build time
9
9
  // and must always be references by its full static name, e.g. no optional chaining, no `if (process && process.env)` etc.
10
- "5.7.0-next.18+4f5566181e";
10
+ "5.7.0-next.20+4f6b9ad18d";
11
11
  } catch {
12
12
  }
13
13
  const SANITY_VERSION = buildVersion || `${version}-dev`;
package/lib/index.js CHANGED
@@ -16,7 +16,7 @@ import { Hotkeys } from "./_chunks-es/TooltipDelayGroupProvider.js";
16
16
  import { ResizeObserver as ResizeObserver$2 } from "@juggle/resize-observer";
17
17
  import createPubSub from "nano-pubsub";
18
18
  import { I18nextProvider, useTranslation as useTranslation$1, initReactI18next } from "react-i18next";
19
- import { isIndexSegment, isKeySegment, isIndexTuple, isKeyedObject, isReference as isReference$1, isArrayOfBlocksSchemaType, isSlug, isTypedObject, isGlobalDocumentReference, isObjectSchemaType, isArraySchemaType, isPortableTextSpan, isPortableTextTextBlock, isPrimitiveSchemaType, isBooleanSchemaType, isDateTimeSchemaType, isCrossDatasetReferenceSchemaType, isReferenceSchemaType, isStringSchemaType, isNumberSchemaType, isArrayOfObjectsSchemaType, isArrayOfPrimitivesSchemaType, isCrossDatasetReference, isTitledListValue, isImage, isValidationErrorMarker, isImageSchemaType, isSearchStrategy, searchStrategies as searchStrategies$1, defineType, defineField, defineArrayMember, isValidationWarningMarker, isValidationInfoMarker, isDeprecatedSchemaType, isFileSchemaType, isBlockSchemaType } from "@sanity/types";
19
+ import { isIndexSegment, isKeySegment, isIndexTuple, isKeyedObject, isReference as isReference$1, isArrayOfBlocksSchemaType, isSlug, isTypedObject, isGlobalDocumentReference, isObjectSchemaType, isArraySchemaType, isPortableTextSpan, isPortableTextTextBlock, isPrimitiveSchemaType, isBooleanSchemaType, isDateTimeSchemaType, isCrossDatasetReferenceSchemaType, isReferenceSchemaType, isStringSchemaType, isNumberSchemaType, isArrayOfObjectsSchemaType, isArrayOfPrimitivesSchemaType, isCrossDatasetReference, isTitledListValue, isImage, isValidationErrorMarker, isImageSchemaType, isSearchStrategy, searchStrategies as searchStrategies$1, defineType, defineField, defineArrayMember, isValidationWarningMarker, isValidationInfoMarker, isDeprecatedSchemaType, isBlockSchemaType, isSpanSchemaType, isFileSchemaType } from "@sanity/types";
20
20
  export * from "@sanity/types";
21
21
  import { COLOR_HUES, hues, white, red, gray, yellow, purple, black, green, blue } from "@sanity/color";
22
22
  import { of, concat, defer, EMPTY as EMPTY$5, map as map$1, defaultIfEmpty, catchError as catchError$1, switchMap as switchMap$1, take, concatMap, from, Observable, merge, Subject, fromEvent, throwError, timer, NEVER, pipe, distinctUntilChanged as distinctUntilChanged$1, shareReplay as shareReplay$1, BehaviorSubject, tap as tap$1, finalize, share as share$1, ReplaySubject, combineLatest, asyncScheduler, bufferTime, mergeMap as mergeMap$1, firstValueFrom, filter as filter$1, lastValueFrom, partition as partition$1, asapScheduler, using, repeat, iif, startWith as startWith$1, concatWith, scan as scan$1, count, isObservable, retry, expand, reduce as reduce$2, skip as skip$1, forkJoin, debounce as debounce$2, toArray as toArray$2, delay as delay$1, timeout as timeout$1, connect, debounceTime as debounceTime$1 } from "rxjs";
@@ -84648,7 +84648,16 @@ function transformValueToText(value) {
84648
84648
  return value ? isString(value) ? value : Number.isFinite(value) ? value.toString() : Array.isArray(value) ? value.map(transformValueToText).filter(Boolean).join(", ") : typeof value == "object" ? Object.entries(value).map(([key, subValue]) => key.startsWith("_") ? "" : transformValueToText(subValue)).filter(Boolean).join(", ") : "" : "";
84649
84649
  }
84650
84650
  function isEmptyValue(value) {
84651
- return !!(value == null || Array.isArray(value) && value.length === 0);
84651
+ if (value == null) return !0;
84652
+ if (typeof value == "object") {
84653
+ const keys = Object.keys(value);
84654
+ if (keys.length === 1 && keys[0] === "_key")
84655
+ return !0;
84656
+ }
84657
+ return !!(Array.isArray(value) && value.length === 0);
84658
+ }
84659
+ function isPortableTextPreserveEmptyField(member, targetSchemaType) {
84660
+ return member.name === "markDefs" && isBlockSchemaType(targetSchemaType) || member.name === "marks" && isSpanSchemaType(targetSchemaType);
84652
84661
  }
84653
84662
  function isNativeEditableElement(el) {
84654
84663
  return !!(el instanceof HTMLElement && el.isContentEditable || el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement);
@@ -84874,7 +84883,10 @@ async function collateObjectValue({
84874
84883
  errors
84875
84884
  };
84876
84885
  const targetValue = {
84877
- _type: targetSchemaType.name,
84886
+ // Only set _type if the source value had one (preserves anonymous objects)
84887
+ ...isTypedObject(sourceValue) ? {
84888
+ _type: targetSchemaType.name
84889
+ } : {},
84878
84890
  ...sourceValue && typeof sourceValue == "object" && "_key" in sourceValue ? {
84879
84891
  _key: keyGenerator2()
84880
84892
  } : {}
@@ -85061,7 +85073,8 @@ async function collateObjectValue({
85061
85073
  });
85062
85074
  if (isPortableTextBlockWithMarkdefs && member.name === "markDefs" && !isEmptyValue(targetValue.markDefs))
85063
85075
  continue;
85064
- isEmptyValue(collated.targetValue) || (targetValue[member.name] = collated.targetValue);
85076
+ const shouldPreserveEmptyArray = Array.isArray(genericValue) && genericValue.length === 0 && isPortableTextPreserveEmptyField(member, targetSchemaType);
85077
+ isEmptyValue(collated.targetValue) ? shouldPreserveEmptyArray && (targetValue[member.name] = []) : targetValue[member.name] = collated.targetValue;
85065
85078
  }
85066
85079
  }
85067
85080
  const valueAtTargetPath = getValueAtPath(targetValue, targetPath), resultingValue = cleanObjectKeys(valueAtTargetPath);
@@ -85073,6 +85086,10 @@ async function collateObjectValue({
85073
85086
  errors
85074
85087
  };
85075
85088
  }
85089
+ function findMatchingArrayMemberType(item, targetSchemaType) {
85090
+ const itemTypeName = resolveTypeName$1(item);
85091
+ return targetSchemaType.of.find((type) => type.name === itemTypeName);
85092
+ }
85076
85093
  async function collateArrayValue({
85077
85094
  sourceValue,
85078
85095
  targetSchemaType,
@@ -85115,10 +85132,10 @@ async function collateArrayValue({
85115
85132
  }), transferredItems.length > 0 && (targetValue = transferredItems);
85116
85133
  }
85117
85134
  if (isArrayOfObjectsMember) {
85118
- const value = sourceValue, transferredItems = value.filter((item) => targetSchemaType.of.some((type) => type.name === item._type)), nonTransferredItems = value.filter((item) => !targetSchemaType.of.some((type) => type.name === item._type));
85135
+ const value = sourceValue, transferredItems = value.filter((item) => findMatchingArrayMemberType(item, targetSchemaType) !== void 0), nonTransferredItems = value.filter((item) => findMatchingArrayMemberType(item, targetSchemaType) === void 0);
85119
85136
  transferredItems.length === 0 ? targetValue = void 0 : targetValue = (await Promise.all(transferredItems.map((item) => collateObjectValue({
85120
85137
  sourceValue: item,
85121
- targetSchemaType: targetSchemaType.of.find((type) => type.name === item._type),
85138
+ targetSchemaType: findMatchingArrayMemberType(item, targetSchemaType),
85122
85139
  targetPath: [],
85123
85140
  targetRootValue,
85124
85141
  targetRootPath,
@@ -85132,7 +85149,7 @@ async function collateArrayValue({
85132
85149
  i18n: {
85133
85150
  key: "copy-paste.on-paste.validation.array-value-incompatible.description",
85134
85151
  args: {
85135
- type: item._type || typeof item
85152
+ type: resolveTypeName$1(item)
85136
85153
  }
85137
85154
  }
85138
85155
  });