@sanity/schema 6.2.0-workbench.20260624120929 → 6.2.0

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.
@@ -232,17 +232,17 @@ declare const builtinTypes: ({
232
232
  type: string;
233
233
  title: string;
234
234
  readOnly: boolean;
235
+ fieldset?: undefined;
235
236
  validation?: undefined;
236
237
  hidden?: undefined;
237
- fieldset?: undefined;
238
238
  } | {
239
239
  name: string;
240
240
  type: string;
241
241
  title: string;
242
+ fieldset?: undefined;
243
+ readOnly?: undefined;
242
244
  validation?: undefined;
243
245
  hidden?: undefined;
244
- readOnly?: undefined;
245
- fieldset?: undefined;
246
246
  } | {
247
247
  name: string;
248
248
  type: string;
@@ -257,8 +257,8 @@ declare const builtinTypes: ({
257
257
  readOnly: boolean;
258
258
  hidden: boolean;
259
259
  fieldset: string;
260
- validation?: undefined;
261
260
  title?: undefined;
261
+ validation?: undefined;
262
262
  } | {
263
263
  name: string;
264
264
  type: string;
@@ -311,17 +311,17 @@ declare const builtinTypes: ({
311
311
  type: string;
312
312
  title: string;
313
313
  readOnly: boolean;
314
+ fieldset?: undefined;
314
315
  validation?: undefined;
315
316
  hidden?: undefined;
316
- fieldset?: undefined;
317
317
  } | {
318
318
  name: string;
319
319
  type: string;
320
320
  title: string;
321
+ fieldset?: undefined;
322
+ readOnly?: undefined;
321
323
  validation?: undefined;
322
324
  hidden?: undefined;
323
- readOnly?: undefined;
324
- fieldset?: undefined;
325
325
  } | {
326
326
  name: string;
327
327
  type: string;
@@ -331,21 +331,21 @@ declare const builtinTypes: ({
331
331
  validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
332
332
  hidden?: undefined;
333
333
  } | {
334
- validation?: undefined;
335
334
  name: string;
336
335
  type: string;
337
336
  readOnly: boolean;
338
337
  hidden: boolean;
339
338
  fieldset: string;
340
339
  title?: undefined;
341
- } | {
342
340
  validation?: undefined;
343
- hidden?: undefined;
341
+ } | {
344
342
  name: string;
345
343
  type: string;
346
344
  title: string;
347
345
  readOnly: boolean;
348
346
  fieldset: string;
347
+ validation?: undefined;
348
+ hidden?: undefined;
349
349
  })[];
350
350
  preview: {
351
351
  select: {
@@ -395,17 +395,17 @@ declare const builtinTypes: ({
395
395
  };
396
396
  }[];
397
397
  fields: ({
398
- title?: undefined;
399
- readOnly?: undefined;
400
- fieldset?: undefined;
401
398
  name: string;
402
399
  type: string;
403
- } | {
400
+ fieldset?: undefined;
401
+ title?: undefined;
404
402
  readOnly?: undefined;
403
+ } | {
405
404
  name: string;
406
405
  title: string;
407
406
  type: string;
408
407
  fieldset: string;
408
+ readOnly?: undefined;
409
409
  } | {
410
410
  fieldset?: undefined;
411
411
  name: string;
package/lib/_internal.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { SetBuilder, processSetSynchronization } from "@sanity/descriptors";
2
+ import { isSpanSchemaType } from "@sanity/types";
2
3
  import isEqual from "lodash-es/isEqual.js";
3
4
  import isObject from "lodash-es/isObject.js";
4
5
  import { OWN_PROPS_NAME, Rule, Schema } from "./_chunks-es/Schema.js";
@@ -16,6 +17,60 @@ import leven from "leven";
16
17
  import inspect from "object-inspect";
17
18
  import startCase from "lodash-es/startCase.js";
18
19
  import { createReferenceTypeNode } from "groq-js";
20
+ const DEFAULT_IMAGE_FIELDS = ["asset", "hotspot", "crop", "media"], DEFAULT_FILE_FIELDS = ["asset", "media"], DEFAULT_GEOPOINT_FIELDS = ["lat", "lng", "alt"], DEFAULT_SLUG_FIELDS = ["current", "source"];
21
+ function getCustomFields(type) {
22
+ const fields = type.fieldsets ? type.fieldsets.flatMap((fs) => fs.single ? fs.field : fs.fields.map((field) => ({
23
+ ...field,
24
+ fieldset: fs.name
25
+ }))) : type.fields;
26
+ return isType$1(type, "block") ? [] : isType$1(type, "slug") ? fields.filter((f) => !DEFAULT_SLUG_FIELDS.includes(f.name)) : isType$1(type, "geopoint") ? fields.filter((f) => !DEFAULT_GEOPOINT_FIELDS.includes(f.name)) : isType$1(type, "image") ? fields.filter((f) => !DEFAULT_IMAGE_FIELDS.includes(f.name)) : isType$1(type, "file") ? fields.filter((f) => !DEFAULT_FILE_FIELDS.includes(f.name)) : fields;
27
+ }
28
+ function isReference(type) {
29
+ return isType$1(type, "reference");
30
+ }
31
+ function isCrossDatasetReference(type) {
32
+ return isType$1(type, "crossDatasetReference");
33
+ }
34
+ function isGlobalDocumentReference(type) {
35
+ return isType$1(type, "globalDocumentReference");
36
+ }
37
+ function isObjectField(maybeOjectField) {
38
+ return typeof maybeOjectField == "object" && maybeOjectField !== null && "name" in maybeOjectField;
39
+ }
40
+ function isCustomized(maybeCustomized) {
41
+ const internalOwnProps = getSchemaTypeInternalOwnProps(maybeCustomized);
42
+ return isObjectField(maybeCustomized) && !isReference(maybeCustomized) && !isCrossDatasetReference(maybeCustomized) && !isGlobalDocumentReference(maybeCustomized) && "fields" in maybeCustomized && Array.isArray(maybeCustomized.fields) && // needed to differentiate inline, named array object types from globally defined types
43
+ // we only consider it customized if the _definition_ has fields declared
44
+ // this holds for all customizable object-like types: object, document, image and file
45
+ internalOwnProps?.fields ? !!getCustomFields(maybeCustomized).length : !1;
46
+ }
47
+ function isType$1(schemaType, typeName) {
48
+ return schemaType.name === typeName ? !0 : schemaType.type ? isType$1(schemaType.type, typeName) : !1;
49
+ }
50
+ function isDefined(value) {
51
+ return value != null;
52
+ }
53
+ function isRecord(value) {
54
+ return !!value && typeof value == "object";
55
+ }
56
+ function isPrimitive(value) {
57
+ return isString(value) || isBoolean(value) || isNumber(value);
58
+ }
59
+ function isString(value) {
60
+ return typeof value == "string";
61
+ }
62
+ function isNumber(value) {
63
+ return typeof value == "number";
64
+ }
65
+ function isBoolean(value) {
66
+ return typeof value == "boolean";
67
+ }
68
+ function getSchemaTypeInternalOwnProps(type) {
69
+ return type?._internal_ownProps;
70
+ }
71
+ function getDefinedTypeName(type) {
72
+ return getSchemaTypeInternalOwnProps(type)?.type;
73
+ }
19
74
  const MAX_IDLE_WORK = 8.333333333333334;
20
75
  class IdleScheduler {
21
76
  #durations = [];
@@ -216,9 +271,24 @@ function convertTypeDef(schemaType, path, opts) {
216
271
  };
217
272
  }
218
273
  default:
219
- return { extends: schemaType.type.name, ...common2 };
274
+ return {
275
+ extends: schemaType.type.name,
276
+ ...common2,
277
+ marks: maybeBlockMarks(schemaType)
278
+ };
220
279
  }
221
280
  }
281
+ function maybeBlockMarks(schemaType) {
282
+ if (schemaType.jsonType !== "object" || !isType$1(schemaType, "block"))
283
+ return;
284
+ const spanType = schemaType.fields?.find(
285
+ (field) => field.name === "children"
286
+ )?.type?.of?.find((memberType) => memberType.name === "span");
287
+ if (!spanType || !isSpanSchemaType(spanType))
288
+ return;
289
+ const decorators = convertUnknown(spanType.decorators);
290
+ return decorators === void 0 ? void 0 : { decorators };
291
+ }
222
292
  function maybeString(val) {
223
293
  return typeof val == "string" ? val : void 0;
224
294
  }
@@ -2391,60 +2461,6 @@ function regexPatternToRegExp(val) {
2391
2461
  const match = val.pattern.match(/^\(\?([a-z]+)\)(.*)$/);
2392
2462
  return match ? new RegExp(match[2], match[1]) : new RegExp(val.pattern);
2393
2463
  }
2394
- const DEFAULT_IMAGE_FIELDS = ["asset", "hotspot", "crop", "media"], DEFAULT_FILE_FIELDS = ["asset", "media"], DEFAULT_GEOPOINT_FIELDS = ["lat", "lng", "alt"], DEFAULT_SLUG_FIELDS = ["current", "source"];
2395
- function getCustomFields(type) {
2396
- const fields = type.fieldsets ? type.fieldsets.flatMap((fs) => fs.single ? fs.field : fs.fields.map((field) => ({
2397
- ...field,
2398
- fieldset: fs.name
2399
- }))) : type.fields;
2400
- return isType$1(type, "block") ? [] : isType$1(type, "slug") ? fields.filter((f) => !DEFAULT_SLUG_FIELDS.includes(f.name)) : isType$1(type, "geopoint") ? fields.filter((f) => !DEFAULT_GEOPOINT_FIELDS.includes(f.name)) : isType$1(type, "image") ? fields.filter((f) => !DEFAULT_IMAGE_FIELDS.includes(f.name)) : isType$1(type, "file") ? fields.filter((f) => !DEFAULT_FILE_FIELDS.includes(f.name)) : fields;
2401
- }
2402
- function isReference(type) {
2403
- return isType$1(type, "reference");
2404
- }
2405
- function isCrossDatasetReference(type) {
2406
- return isType$1(type, "crossDatasetReference");
2407
- }
2408
- function isGlobalDocumentReference(type) {
2409
- return isType$1(type, "globalDocumentReference");
2410
- }
2411
- function isObjectField(maybeOjectField) {
2412
- return typeof maybeOjectField == "object" && maybeOjectField !== null && "name" in maybeOjectField;
2413
- }
2414
- function isCustomized(maybeCustomized) {
2415
- const internalOwnProps = getSchemaTypeInternalOwnProps(maybeCustomized);
2416
- return isObjectField(maybeCustomized) && !isReference(maybeCustomized) && !isCrossDatasetReference(maybeCustomized) && !isGlobalDocumentReference(maybeCustomized) && "fields" in maybeCustomized && Array.isArray(maybeCustomized.fields) && // needed to differentiate inline, named array object types from globally defined types
2417
- // we only consider it customized if the _definition_ has fields declared
2418
- // this holds for all customizable object-like types: object, document, image and file
2419
- internalOwnProps?.fields ? !!getCustomFields(maybeCustomized).length : !1;
2420
- }
2421
- function isType$1(schemaType, typeName) {
2422
- return schemaType.name === typeName ? !0 : schemaType.type ? isType$1(schemaType.type, typeName) : !1;
2423
- }
2424
- function isDefined(value) {
2425
- return value != null;
2426
- }
2427
- function isRecord(value) {
2428
- return !!value && typeof value == "object";
2429
- }
2430
- function isPrimitive(value) {
2431
- return isString(value) || isBoolean(value) || isNumber(value);
2432
- }
2433
- function isString(value) {
2434
- return typeof value == "string";
2435
- }
2436
- function isNumber(value) {
2437
- return typeof value == "number";
2438
- }
2439
- function isBoolean(value) {
2440
- return typeof value == "boolean";
2441
- }
2442
- function getSchemaTypeInternalOwnProps(type) {
2443
- return type?._internal_ownProps;
2444
- }
2445
- function getDefinedTypeName(type) {
2446
- return getSchemaTypeInternalOwnProps(type)?.type;
2447
- }
2448
2464
  const MAX_CUSTOM_PROPERTY_DEPTH = 5, noopIconResolver = () => {
2449
2465
  };
2450
2466
  async function extractCreateWorkspaceManifest(workspace, iconResolver = noopIconResolver) {