@sanity/schema 6.7.0-next.36 → 6.7.0-next.5

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.
@@ -0,0 +1,1729 @@
1
+ import cloneDeep from "lodash-es/cloneDeep.js";
2
+ import startCase from "lodash-es/startCase.js";
3
+ import omit from "lodash-es/omit.js";
4
+ import pick from "lodash-es/pick.js";
5
+ import arrify from "arrify";
6
+ import isUndefined from "lodash-es/isUndefined.js";
7
+ import omitBy from "lodash-es/omitBy.js";
8
+ import capitalize from "lodash-es/capitalize.js";
9
+ import isFinite from "lodash-es/isFinite.js";
10
+ import uniqBy from "lodash-es/uniqBy.js";
11
+ import castArray from "lodash-es/castArray.js";
12
+ import flatMap from "lodash-es/flatMap.js";
13
+ import isPlainObject from "lodash-es/isPlainObject.js";
14
+ import toPath from "lodash-es/toPath.js";
15
+ const FIELD_REF = /* @__PURE__ */ Symbol.for("@sanity/schema/field-ref"), ruleConstraintTypes = [
16
+ "Array",
17
+ "Boolean",
18
+ "Date",
19
+ "Number",
20
+ "Object",
21
+ "String"
22
+ ], Rule = class Rule2 {
23
+ static FIELD_REF = FIELD_REF;
24
+ static array = (def) => new Rule2(def).type("Array");
25
+ static object = (def) => new Rule2(def).type("Object");
26
+ static string = (def) => new Rule2(def).type("String");
27
+ static number = (def) => new Rule2(def).type("Number");
28
+ static boolean = (def) => new Rule2(def).type("Boolean");
29
+ static dateTime = (def) => new Rule2(def).type("Date");
30
+ static valueOfField = (path) => ({
31
+ type: FIELD_REF,
32
+ path
33
+ });
34
+ _type = void 0;
35
+ _level = void 0;
36
+ _required = void 0;
37
+ _typeDef = void 0;
38
+ _message = void 0;
39
+ _rules = [];
40
+ _fieldRules = void 0;
41
+ constructor(typeDef) {
42
+ this._typeDef = typeDef, this.reset();
43
+ }
44
+ _mergeRequired(next) {
45
+ if (this._required === "required" || next._required === "required") return "required";
46
+ if (this._required === "optional" || next._required === "optional") return "optional";
47
+ }
48
+ // Alias to static method, since we often have access to an _instance_ of a rule but not the actual Rule class
49
+ valueOfField = Rule2.valueOfField.bind(Rule2);
50
+ error(message) {
51
+ const rule = this.clone();
52
+ return rule._level = "error", rule._message = message || void 0, rule;
53
+ }
54
+ warning(message) {
55
+ const rule = this.clone();
56
+ return rule._level = "warning", rule._message = message || void 0, rule;
57
+ }
58
+ info(message) {
59
+ const rule = this.clone();
60
+ return rule._level = "info", rule._message = message || void 0, rule;
61
+ }
62
+ reset() {
63
+ return this._type = this._type || void 0, this._rules = (this._rules || []).filter((rule) => rule.flag === "type"), this._message = void 0, this._required = void 0, this._level = "error", this._fieldRules = void 0, this;
64
+ }
65
+ isRequired() {
66
+ return this._required === "required";
67
+ }
68
+ clone() {
69
+ const rule = new Rule2();
70
+ return rule._type = this._type, rule._message = this._message, rule._required = this._required, rule._rules = cloneDeep(this._rules), rule._level = this._level, rule._fieldRules = this._fieldRules, rule._typeDef = this._typeDef, rule;
71
+ }
72
+ cloneWithRules(rules) {
73
+ const rule = this.clone(), newRules = /* @__PURE__ */ new Set();
74
+ return rules.forEach((curr) => {
75
+ curr.flag === "type" && (rule._type = curr.constraint), newRules.add(curr.flag);
76
+ }), rule._rules = rule._rules.filter((curr) => {
77
+ const disallowDuplicate = ["type", "uri", "email"].includes(curr.flag), isDuplicate = newRules.has(curr.flag);
78
+ return !(disallowDuplicate && isDuplicate);
79
+ }).concat(rules), rule;
80
+ }
81
+ merge(rule) {
82
+ if (this._type && rule._type && this._type !== rule._type)
83
+ throw new Error("merge() failed: conflicting types");
84
+ const newRule = this.cloneWithRules(rule._rules);
85
+ return newRule._type = this._type || rule._type, newRule._message = this._message || rule._message, newRule._required = this._mergeRequired(rule), newRule._level = this._level === "error" ? rule._level : this._level, newRule;
86
+ }
87
+ // Validation flag setters
88
+ type(targetType) {
89
+ const type = `${targetType.slice(0, 1).toUpperCase()}${targetType.slice(1)}`;
90
+ if (!ruleConstraintTypes.includes(type))
91
+ throw new Error(`Unknown type "${targetType}"`);
92
+ const rule = this.cloneWithRules([{ flag: "type", constraint: type }]);
93
+ return rule._type = type, rule;
94
+ }
95
+ all(children) {
96
+ return this.cloneWithRules([{ flag: "all", constraint: children }]);
97
+ }
98
+ either(children) {
99
+ return this.cloneWithRules([{ flag: "either", constraint: children }]);
100
+ }
101
+ // Shared rules
102
+ optional() {
103
+ const rule = this.cloneWithRules([{ flag: "presence", constraint: "optional" }]);
104
+ return rule._required = "optional", rule;
105
+ }
106
+ skip() {
107
+ const rule = this.clone();
108
+ return rule._rules = [], rule._required = "optional", rule._message = void 0, rule._level = "error", rule._fieldRules = void 0, rule;
109
+ }
110
+ required() {
111
+ const rule = this.cloneWithRules([{ flag: "presence", constraint: "required" }]);
112
+ return rule._required = "required", rule;
113
+ }
114
+ custom(fn, options = {}) {
115
+ return options.bypassConcurrencyLimit && Object.assign(fn, { bypassConcurrencyLimit: !0 }), this.cloneWithRules([{ flag: "custom", constraint: fn }]);
116
+ }
117
+ min(len) {
118
+ return this.cloneWithRules([{ flag: "min", constraint: len }]);
119
+ }
120
+ max(len) {
121
+ return this.cloneWithRules([{ flag: "max", constraint: len }]);
122
+ }
123
+ length(len) {
124
+ return this.cloneWithRules([{ flag: "length", constraint: len }]);
125
+ }
126
+ valid(value) {
127
+ const values = Array.isArray(value) ? value : [value];
128
+ return this.cloneWithRules([{ flag: "valid", constraint: values }]);
129
+ }
130
+ // Numbers only
131
+ integer() {
132
+ return this.cloneWithRules([{ flag: "integer" }]);
133
+ }
134
+ precision(limit) {
135
+ return this.cloneWithRules([{ flag: "precision", constraint: limit }]);
136
+ }
137
+ positive() {
138
+ return this.cloneWithRules([{ flag: "min", constraint: 0 }]);
139
+ }
140
+ negative() {
141
+ return this.cloneWithRules([{ flag: "lessThan", constraint: 0 }]);
142
+ }
143
+ greaterThan(num) {
144
+ return this.cloneWithRules([{ flag: "greaterThan", constraint: num }]);
145
+ }
146
+ lessThan(num) {
147
+ return this.cloneWithRules([{ flag: "lessThan", constraint: num }]);
148
+ }
149
+ // String only
150
+ uppercase() {
151
+ return this.cloneWithRules([{ flag: "stringCasing", constraint: "uppercase" }]);
152
+ }
153
+ lowercase() {
154
+ return this.cloneWithRules([{ flag: "stringCasing", constraint: "lowercase" }]);
155
+ }
156
+ regex(pattern, a, b) {
157
+ const name = typeof a == "string" ? a : a?.name ?? b?.name, invert = typeof a == "string" ? !1 : a?.invert ?? b?.invert, constraint = {
158
+ pattern,
159
+ name,
160
+ invert: invert || !1
161
+ };
162
+ return this.cloneWithRules([{ flag: "regex", constraint }]);
163
+ }
164
+ email() {
165
+ return this.cloneWithRules([{ flag: "email" }]);
166
+ }
167
+ uri(opts) {
168
+ const optsScheme = opts?.scheme || ["http", "https"], schemes = Array.isArray(optsScheme) ? optsScheme : [optsScheme];
169
+ if (!schemes.length)
170
+ throw new Error("scheme must have at least 1 scheme specified");
171
+ const constraint = {
172
+ options: {
173
+ scheme: schemes.map((scheme) => {
174
+ if (!(scheme instanceof RegExp) && typeof scheme != "string")
175
+ throw new Error("scheme must be a RegExp or a String");
176
+ return typeof scheme == "string" ? new RegExp(`^${escapeRegex(scheme)}$`) : scheme;
177
+ }),
178
+ allowRelative: opts?.allowRelative || !1,
179
+ relativeOnly: opts?.relativeOnly || !1,
180
+ allowCredentials: opts?.allowCredentials || !1
181
+ }
182
+ };
183
+ return this.cloneWithRules([{ flag: "uri", constraint }]);
184
+ }
185
+ // Array only
186
+ unique() {
187
+ return this.cloneWithRules([{ flag: "unique" }]);
188
+ }
189
+ // Objects only
190
+ reference() {
191
+ return this.cloneWithRules([{ flag: "reference" }]);
192
+ }
193
+ fields(rules) {
194
+ if (this._type !== "Object")
195
+ throw new Error("fields() can only be called on an object type");
196
+ const rule = this.cloneWithRules([]);
197
+ return rule._fieldRules = rules, rule;
198
+ }
199
+ assetRequired() {
200
+ const base = getBaseType(this._typeDef);
201
+ let assetType;
202
+ return base && ["image", "file"].includes(base.name) ? assetType = base.name === "image" ? "image" : "file" : assetType = "asset", this.cloneWithRules([{ flag: "assetRequired", constraint: { assetType } }]);
203
+ }
204
+ media(fn) {
205
+ return this.cloneWithRules([{ flag: "media", constraint: fn }]);
206
+ }
207
+ /**
208
+ * The validate method is not implemented in the base Rule class.
209
+ * It should be implemented by extending this class or injecting validation logic.
210
+ */
211
+ async validate(value, options) {
212
+ throw new Error("validate() method must be implemented by extending Rule class");
213
+ }
214
+ };
215
+ function getBaseType(type) {
216
+ return type && type.type ? getBaseType(type.type) : type;
217
+ }
218
+ function escapeRegex(string) {
219
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
220
+ }
221
+ const DEFAULT_OVERRIDEABLE_FIELDS = [
222
+ "jsonType",
223
+ "type",
224
+ "name",
225
+ "title",
226
+ "description",
227
+ "options",
228
+ "fieldsets",
229
+ "validation",
230
+ "readOnly",
231
+ "hidden",
232
+ "components",
233
+ "diffComponent",
234
+ "initialValue",
235
+ "deprecated"
236
+ ], OWN_PROPS_NAME = "_internal_ownProps", ALL_FIELDS_GROUP_NAME = "all-fields", DEFAULT_MAX_FIELD_DEPTH = 5, stringFieldsSymbols = {}, getStringFieldSymbol = (maxDepth) => (stringFieldsSymbols[maxDepth] || (stringFieldsSymbols[maxDepth] = /* @__PURE__ */ Symbol(`__cachedStringFields_${maxDepth}`)), stringFieldsSymbols[maxDepth]), isReference = (type) => type.type && type.type.name === "reference", portableTextFields = ["style", "list"], isPortableTextBlock = (type) => type.name === "block" || type.type && isPortableTextBlock(type.type), isPortableTextArray = (type) => type.jsonType === "array" && Array.isArray(type.of) && type.of.some(isPortableTextBlock);
237
+ function reduceType(type, reducer, acc, path = [], maxDepth) {
238
+ if (maxDepth < 0)
239
+ return acc;
240
+ const accumulator = reducer(acc, type, path);
241
+ return type.jsonType === "array" && Array.isArray(type.of) ? reduceArray(type, reducer, accumulator, path, maxDepth) : type.jsonType === "object" && Array.isArray(type.fields) && !isReference(type) ? reduceObject(type, reducer, accumulator, path, maxDepth) : accumulator;
242
+ }
243
+ function reduceArray(arrayType, reducer, accumulator, path, maxDepth) {
244
+ return arrayType.of.reduce(
245
+ (acc, ofType) => reduceType(ofType, reducer, acc, path, maxDepth - 1),
246
+ accumulator
247
+ );
248
+ }
249
+ function reduceObject(objectType, reducer, accumulator, path, maxDepth) {
250
+ const isPtBlock = isPortableTextBlock(objectType);
251
+ return objectType.fields.reduce((acc, field) => {
252
+ if (isPtBlock && portableTextFields.includes(field.name))
253
+ return acc;
254
+ const segment = [field.name].concat(field.type.jsonType === "array" ? [[]] : []);
255
+ return reduceType(field.type, reducer, acc, path.concat(segment), maxDepth - 1);
256
+ }, accumulator);
257
+ }
258
+ const BASE_WEIGHTS = [
259
+ { weight: 1, path: ["_id"] },
260
+ { weight: 1, path: ["_type"] }
261
+ ], PREVIEW_FIELD_WEIGHT_MAP = {
262
+ title: 10,
263
+ subtitle: 5,
264
+ description: 1.5
265
+ };
266
+ function deriveFromPreview(type, maxDepth) {
267
+ const select = type?.preview?.select;
268
+ if (!select)
269
+ return [];
270
+ const fields = [];
271
+ for (const fieldName of Object.keys(select)) {
272
+ if (!(fieldName in PREVIEW_FIELD_WEIGHT_MAP))
273
+ continue;
274
+ const path = select[fieldName].split(".");
275
+ maxDepth > -1 && path.length - 1 > maxDepth || fields.push({
276
+ weight: PREVIEW_FIELD_WEIGHT_MAP[fieldName],
277
+ path
278
+ });
279
+ }
280
+ return fields;
281
+ }
282
+ function getCachedStringFieldPaths(type, maxDepth) {
283
+ const symbol = getStringFieldSymbol(maxDepth);
284
+ return type[symbol] || (type[symbol] = uniqBy(
285
+ [
286
+ ...BASE_WEIGHTS,
287
+ ...deriveFromPreview(type, maxDepth),
288
+ ...getStringFieldPaths(type, maxDepth).map((path) => ({ weight: 1, path })),
289
+ ...getPortableTextFieldPaths(type, maxDepth).map((path) => ({
290
+ weight: 1,
291
+ path,
292
+ mapWith: "pt::text"
293
+ }))
294
+ ],
295
+ (spec) => spec.path.join(".")
296
+ )), type[symbol];
297
+ }
298
+ function getCachedBaseFieldPaths(type, maxDepth) {
299
+ const symbol = getStringFieldSymbol(maxDepth);
300
+ return type[symbol] || (type[symbol] = uniqBy(
301
+ [...BASE_WEIGHTS, ...deriveFromPreview(type, maxDepth)],
302
+ (spec) => spec.path.join(".")
303
+ )), type[symbol];
304
+ }
305
+ function getStringFieldPaths(type, maxDepth) {
306
+ return reduceType(type, (accumulator, childType, path) => childType.jsonType === "string" ? [...accumulator, path] : accumulator, [], [], maxDepth);
307
+ }
308
+ function getPortableTextFieldPaths(type, maxDepth) {
309
+ return reduceType(type, (accumulator, childType, path) => isPortableTextArray(childType) ? [...accumulator, path] : accumulator, [], [], maxDepth);
310
+ }
311
+ function resolveSearchConfigForBaseFieldPaths(type, maxDepth) {
312
+ return getCachedBaseFieldPaths(type, normalizeMaxDepth(maxDepth));
313
+ }
314
+ function resolveSearchConfig(type, maxDepth) {
315
+ return getCachedStringFieldPaths(type, normalizeMaxDepth(maxDepth));
316
+ }
317
+ function normalizeMaxDepth(maxDepth) {
318
+ return !isFinite(maxDepth) || maxDepth < 1 || maxDepth > DEFAULT_MAX_FIELD_DEPTH ? DEFAULT_MAX_FIELD_DEPTH - 1 : maxDepth - 1;
319
+ }
320
+ function lazyGetter(target, key, getter, config = {}) {
321
+ return Object.defineProperty(target, key, {
322
+ configurable: !0,
323
+ enumerable: config.enumerable !== !1,
324
+ get() {
325
+ const val = getter();
326
+ return Object.defineProperty(target, key, {
327
+ value: val,
328
+ writable: !!config.writable,
329
+ configurable: !1
330
+ }), val;
331
+ }
332
+ }), target;
333
+ }
334
+ function hiddenGetter(target, key, value) {
335
+ Object.defineProperty(target, key, {
336
+ enumerable: !1,
337
+ writable: !1,
338
+ configurable: !1,
339
+ value
340
+ });
341
+ }
342
+ const OVERRIDABLE_FIELDS$f = [...DEFAULT_OVERRIDEABLE_FIELDS], ANY_CORE = {
343
+ name: "any",
344
+ type: null,
345
+ jsonType: "any"
346
+ }, AnyType = {
347
+ get() {
348
+ return ANY_CORE;
349
+ },
350
+ extend(subTypeDef, extendMember) {
351
+ const ownProps = {
352
+ ...subTypeDef,
353
+ of: subTypeDef.of.map((fieldDef) => ({
354
+ name: fieldDef.name,
355
+ type: extendMember(omit(fieldDef, "name"))
356
+ }))
357
+ }, parsed = Object.assign(pick(ANY_CORE, OVERRIDABLE_FIELDS$f), ownProps, {
358
+ type: ANY_CORE
359
+ });
360
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
361
+ function subtype(parent) {
362
+ return {
363
+ get() {
364
+ return parent;
365
+ },
366
+ extend: (extensionDef) => {
367
+ if (extensionDef.of)
368
+ throw new Error('Cannot override `of` property of subtypes of "array"');
369
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$f), current = Object.assign({}, parent, subOwnProps, {
370
+ type: parent
371
+ });
372
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
373
+ }
374
+ };
375
+ }
376
+ }
377
+ }, OVERRIDABLE_FIELDS$e = [...DEFAULT_OVERRIDEABLE_FIELDS], ARRAY_CORE = {
378
+ name: "array",
379
+ type: null,
380
+ jsonType: "array",
381
+ of: []
382
+ }, ArrayType = {
383
+ get() {
384
+ return ARRAY_CORE;
385
+ },
386
+ extend(subTypeDef, createMemberType) {
387
+ const parsed = Object.assign(pick(ARRAY_CORE, OVERRIDABLE_FIELDS$e), subTypeDef, {
388
+ type: ARRAY_CORE
389
+ });
390
+ return lazyGetter(parsed, "of", () => subTypeDef.of.map((ofTypeDef) => createMemberType.cached(ofTypeDef))), lazyGetter(parsed, OWN_PROPS_NAME, () => ({ ...subTypeDef, of: parsed.of }), {
391
+ enumerable: !1,
392
+ writable: !1
393
+ }), subtype(parsed);
394
+ function subtype(parent) {
395
+ return {
396
+ get() {
397
+ return parent;
398
+ },
399
+ extend: (extensionDef) => {
400
+ if (extensionDef.of)
401
+ throw new Error('Cannot override `of` property of subtypes of "array"');
402
+ const ownProps = pick(extensionDef, OVERRIDABLE_FIELDS$e), current = Object.assign({}, parent, ownProps, {
403
+ type: parent
404
+ });
405
+ return hiddenGetter(current, OWN_PROPS_NAME, ownProps), subtype(current);
406
+ }
407
+ };
408
+ }
409
+ }
410
+ };
411
+ function warnIfPreviewOnOptions(type) {
412
+ type.options && type.options.preview && console.warn(`Heads up! The preview config is no longer defined on "options", but instead on the type/field itself.
413
+ Please move {options: {preview: ...}} to {..., preview: ...} on the type/field definition of "${type.name}".
414
+ `);
415
+ }
416
+ function warnIfPreviewHasFields(type) {
417
+ const preview = type.preview || (type.options || {}).preview;
418
+ preview && "fields" in preview && console.warn(`Heads up! "preview.fields" should be renamed to "preview.select". Please update the preview config for "${type.name}".
419
+ `);
420
+ }
421
+ function isEmpty(object) {
422
+ for (const key in object)
423
+ if (object.hasOwnProperty(key))
424
+ return !1;
425
+ return !0;
426
+ }
427
+ function _stringify(value, options, depth) {
428
+ if (depth > options.maxDepth)
429
+ return "...";
430
+ if (Array.isArray(value)) {
431
+ if (value.length === 0)
432
+ return "[empty]";
433
+ const capLength = Math.max(value.length - options.maxBreadth), asString2 = value.slice(0, options.maxBreadth).map((item, index) => _stringify(item, options, depth + 1)).concat(capLength > 0 ? `\u2026+${capLength}` : []).join(", ");
434
+ return depth === 0 ? asString2 : `[${asString2}]`;
435
+ }
436
+ if (typeof value == "object" && value !== null) {
437
+ const keys = Object.keys(value).filter(
438
+ (key) => !options.ignoreKeys.includes(key) && typeof value[key] < "u"
439
+ );
440
+ if (isEmpty(pick(value, keys)))
441
+ return "{empty}";
442
+ const asString2 = keys.slice(0, options.maxBreadth).map((key) => `${key}: ${_stringify(value[key], options, depth + 1)}`).join(", ");
443
+ return depth === 0 ? asString2 : `{${asString2}}`;
444
+ }
445
+ const asString = String(value);
446
+ return asString === "" ? '""' : asString;
447
+ }
448
+ function stringify(value, options = {}) {
449
+ const opts = {
450
+ maxDepth: "maxDepth" in options ? options.maxDepth : 2,
451
+ maxBreadth: "maxBreadth" in options ? options.maxBreadth : 2,
452
+ ignoreKeys: "ignoreKeys" in options ? options.ignoreKeys : []
453
+ };
454
+ return _stringify(value, opts, 0);
455
+ }
456
+ const OPTIONS = {
457
+ maxEntries: 2,
458
+ maxDepth: 2,
459
+ maxBreadth: 2,
460
+ ignoreKeys: ["_id", "_type", "_key", "_ref"]
461
+ };
462
+ function createFallbackPrepare(fieldNames) {
463
+ return (value) => ({
464
+ title: stringify(pick(value, fieldNames), OPTIONS)
465
+ });
466
+ }
467
+ function isBlockField(field) {
468
+ return field.type === "array" && field.of && field.of.some((member) => member.type === "block") || !1;
469
+ }
470
+ const TITLE_CANDIDATES = ["title", "name", "label", "heading", "header", "caption"], DESCRIPTION_CANDIDATES = ["description", ...TITLE_CANDIDATES];
471
+ function fieldHasReferenceTo(fieldDef, refType) {
472
+ return arrify(fieldDef.to || []).some((memberTypeDef) => memberTypeDef.type === refType);
473
+ }
474
+ function isImageAssetField(fieldDef) {
475
+ return fieldHasReferenceTo(fieldDef, "sanity.imageAsset");
476
+ }
477
+ function resolveImageAssetPath(typeDef) {
478
+ const fields = typeDef.fields || [], imageAssetField = fields.find(isImageAssetField);
479
+ if (imageAssetField)
480
+ return imageAssetField.name;
481
+ const fieldWithImageAsset = fields.find(
482
+ (fieldDef) => (fieldDef.fields || []).some(isImageAssetField)
483
+ );
484
+ return fieldWithImageAsset ? `${fieldWithImageAsset.name}.asset` : void 0;
485
+ }
486
+ function isFileAssetField(fieldDef) {
487
+ return fieldHasReferenceTo(fieldDef, "sanity.fileAsset");
488
+ }
489
+ function resolveFileAssetPath(typeDef) {
490
+ const fields = typeDef.fields || [], assetField = fields.find(isFileAssetField);
491
+ if (assetField)
492
+ return assetField.name;
493
+ const fieldWithFileAsset = fields.find(
494
+ (fieldDef) => (fieldDef.fields || []).some(isFileAssetField)
495
+ );
496
+ return fieldWithFileAsset ? `${fieldWithFileAsset.name}.asset` : void 0;
497
+ }
498
+ function guessPreviewFields(rawObjectTypeDef) {
499
+ const objectTypeDef = { fields: [], ...rawObjectTypeDef }, stringFieldNames = objectTypeDef.fields.filter((field) => field.type === "string").map((field) => field.name), blockFieldNames = objectTypeDef.fields.filter(isBlockField).map((field) => field.name);
500
+ let titleField = TITLE_CANDIDATES.find(
501
+ (candidate) => stringFieldNames.includes(candidate) || blockFieldNames.includes(candidate)
502
+ ), descField = DESCRIPTION_CANDIDATES.find(
503
+ (candidate) => candidate !== titleField && (stringFieldNames.includes(candidate) || blockFieldNames.includes(candidate))
504
+ );
505
+ titleField || (titleField = stringFieldNames[0] || blockFieldNames[0], descField = stringFieldNames[1] || blockFieldNames[1]);
506
+ const mediaField = objectTypeDef.fields.find((field) => field.type === "image"), imageAssetPath = resolveImageAssetPath(objectTypeDef);
507
+ if (!titleField) {
508
+ const fileAssetPath = resolveFileAssetPath(objectTypeDef);
509
+ fileAssetPath && (titleField = `${fileAssetPath}.originalFilename`), imageAssetPath && (titleField = `${imageAssetPath}.originalFilename`);
510
+ }
511
+ if (!titleField && !imageAssetPath) {
512
+ const fieldNames = objectTypeDef.fields.map((field) => field.name);
513
+ return {
514
+ select: fieldNames.reduce((acc, fieldName) => (acc[fieldName] = fieldName, acc), {}),
515
+ prepare: createFallbackPrepare(fieldNames)
516
+ };
517
+ }
518
+ return {
519
+ select: omitBy(
520
+ {
521
+ title: titleField,
522
+ description: descField,
523
+ media: mediaField ? mediaField.name : imageAssetPath
524
+ },
525
+ isUndefined
526
+ )
527
+ };
528
+ }
529
+ function parseSelection(selection) {
530
+ return selection.reduce((acc, field) => (acc[field] = field, acc), {});
531
+ }
532
+ function parsePreview(preview) {
533
+ if (!preview)
534
+ return preview;
535
+ const select = preview.select || preview.fields || {};
536
+ return Array.isArray(select) ? {
537
+ ...pick(preview, ["prepare", "component"]),
538
+ select: parseSelection(select)
539
+ } : {
540
+ ...pick(preview, ["prepare", "component"]),
541
+ select
542
+ };
543
+ }
544
+ function createPreviewGetter(objectTypeDef) {
545
+ return function() {
546
+ return warnIfPreviewOnOptions(objectTypeDef), warnIfPreviewHasFields(objectTypeDef), parsePreview(objectTypeDef.preview || (objectTypeDef.options || {}).preview) || guessPreviewFields(objectTypeDef);
547
+ };
548
+ }
549
+ const DEFAULT_LINK_ANNOTATION = {
550
+ type: "object",
551
+ name: "link",
552
+ title: "Link",
553
+ i18nTitleKey: "inputs.portable-text.annotation.link",
554
+ options: {
555
+ modal: { type: "popover" }
556
+ },
557
+ fields: [
558
+ {
559
+ name: "href",
560
+ type: "url",
561
+ title: "Link",
562
+ description: "A valid web, email, phone, or relative link.",
563
+ validation: (Rule3) => Rule3.uri({
564
+ scheme: ["http", "https", "tel", "mailto"],
565
+ allowRelative: !0
566
+ })
567
+ }
568
+ ]
569
+ }, DEFAULT_TEXT_FIELD = {
570
+ type: "text",
571
+ name: "text",
572
+ title: "Text"
573
+ }, DEFAULT_MARKS_FIELD = {
574
+ name: "marks",
575
+ type: "array",
576
+ of: [{ type: "string" }],
577
+ title: "Marks"
578
+ }, LIST_TYPES = {
579
+ bullet: {
580
+ title: "Bulleted list",
581
+ value: "bullet",
582
+ i18nTitleKey: "inputs.portable-text.list-type.bullet"
583
+ },
584
+ numbered: {
585
+ title: "Numbered list",
586
+ value: "number",
587
+ i18nTitleKey: "inputs.portable-text.list-type.number"
588
+ }
589
+ }, DEFAULT_LIST_TYPES = [LIST_TYPES.bullet, LIST_TYPES.numbered], BLOCK_STYLES = {
590
+ normal: { title: "Normal", value: "normal", i18nTitleKey: "inputs.portable-text.style.normal" },
591
+ h1: { title: "Heading 1", value: "h1", i18nTitleKey: "inputs.portable-text.style.h1" },
592
+ h2: { title: "Heading 2", value: "h2", i18nTitleKey: "inputs.portable-text.style.h2" },
593
+ h3: { title: "Heading 3", value: "h3", i18nTitleKey: "inputs.portable-text.style.h3" },
594
+ h4: { title: "Heading 4", value: "h4", i18nTitleKey: "inputs.portable-text.style.h4" },
595
+ h5: { title: "Heading 5", value: "h5", i18nTitleKey: "inputs.portable-text.style.h5" },
596
+ h6: { title: "Heading 6", value: "h6", i18nTitleKey: "inputs.portable-text.style.h6" },
597
+ blockquote: {
598
+ title: "Quote",
599
+ value: "blockquote",
600
+ i18nTitleKey: "inputs.portable-text.style.quote"
601
+ }
602
+ }, DEFAULT_BLOCK_STYLES = [
603
+ BLOCK_STYLES.normal,
604
+ BLOCK_STYLES.h1,
605
+ BLOCK_STYLES.h2,
606
+ BLOCK_STYLES.h3,
607
+ BLOCK_STYLES.h4,
608
+ BLOCK_STYLES.h5,
609
+ BLOCK_STYLES.h6,
610
+ BLOCK_STYLES.blockquote
611
+ ], DECORATOR_STRONG = {
612
+ title: "Strong",
613
+ value: "strong",
614
+ i18nTitleKey: "inputs.portable-text.decorator.strong"
615
+ }, DECORATOR_EMPHASIS = {
616
+ title: "Italic",
617
+ value: "em",
618
+ i18nTitleKey: "inputs.portable-text.decorator.emphasis"
619
+ }, DECORATOR_CODE = {
620
+ title: "Code",
621
+ value: "code",
622
+ i18nTitleKey: "inputs.portable-text.decorator.code"
623
+ }, DECORATOR_UNDERLINE = {
624
+ title: "Underline",
625
+ value: "underline",
626
+ i18nTitleKey: "inputs.portable-text.decorator.underline"
627
+ }, DECORATOR_STRIKE = {
628
+ title: "Strike",
629
+ value: "strike-through",
630
+ i18nTitleKey: "inputs.portable-text.decorator.strike-through"
631
+ }, DECORATORS = {
632
+ strong: DECORATOR_STRONG,
633
+ em: DECORATOR_EMPHASIS,
634
+ code: DECORATOR_CODE,
635
+ underline: DECORATOR_UNDERLINE,
636
+ strikeThrough: DECORATOR_STRIKE
637
+ }, DEFAULT_DECORATORS = [
638
+ DECORATORS.strong,
639
+ DECORATORS.em,
640
+ DECORATORS.code,
641
+ DECORATORS.underline,
642
+ DECORATORS.strikeThrough
643
+ ], DEFAULT_ANNOTATIONS = [DEFAULT_LINK_ANNOTATION], INHERITED_FIELDS$1 = [
644
+ "type",
645
+ "name",
646
+ "title",
647
+ "jsonType",
648
+ "description",
649
+ "options",
650
+ "fieldsets",
651
+ "icon"
652
+ ], BLOCK_CORE = {
653
+ name: "block",
654
+ title: "Block",
655
+ type: null,
656
+ jsonType: "object"
657
+ }, DEFAULT_OPTIONS$3 = {}, BlockType = {
658
+ get() {
659
+ return BLOCK_CORE;
660
+ },
661
+ extend(subTypeDef, extendMember) {
662
+ const options = { ...subTypeDef.options || DEFAULT_OPTIONS$3 }, { marks, styles, lists, of, ...rest } = subTypeDef, childrenField = createChildrenField(marks, of), styleField = createStyleField(styles), listItemField = createListItemField(lists), markDefsField = {
663
+ name: "markDefs",
664
+ title: "Mark definitions",
665
+ type: "array",
666
+ of: marks?.annotations || DEFAULT_ANNOTATIONS
667
+ }, fields = [childrenField, styleField, listItemField, markDefsField, {
668
+ name: "level",
669
+ title: "Indentation",
670
+ type: "number"
671
+ }].concat(
672
+ subTypeDef.fields || []
673
+ ), ownProps = { ...rest, options }, parsed = Object.assign(pick(BLOCK_CORE, INHERITED_FIELDS$1), ownProps, {
674
+ type: BLOCK_CORE
675
+ });
676
+ return lazyGetter(parsed, "fields", () => fields.map((fieldDef) => extendMember.cachedField(fieldDef))), lazyGetter(parsed, "preview", createPreviewGetter(subTypeDef)), lazyGetter(
677
+ parsed,
678
+ OWN_PROPS_NAME,
679
+ () => ({
680
+ ...ownProps,
681
+ fields: parsed.fields,
682
+ preview: parsed.preview
683
+ }),
684
+ { enumerable: !1, writable: !1 }
685
+ ), subtype(parsed);
686
+ function subtype(parent) {
687
+ return {
688
+ get() {
689
+ return parent;
690
+ },
691
+ extend: (extensionDef) => {
692
+ if (extensionDef.fields)
693
+ throw new Error('Cannot override `fields` of subtypes of "block"');
694
+ const subOwnProps = pick(extensionDef, INHERITED_FIELDS$1), current = Object.assign({}, parent, subOwnProps, {
695
+ type: parent
696
+ });
697
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
698
+ }
699
+ };
700
+ }
701
+ }
702
+ };
703
+ function ensureNormalStyle(styles) {
704
+ return styles.some((style) => style.value === "normal") ? styles : [BLOCK_STYLES.normal, ...styles];
705
+ }
706
+ function createStyleField(styles) {
707
+ return {
708
+ name: "style",
709
+ title: "Style",
710
+ type: "string",
711
+ options: {
712
+ list: ensureNormalStyle(styles || DEFAULT_BLOCK_STYLES)
713
+ }
714
+ };
715
+ }
716
+ function createListItemField(lists) {
717
+ return {
718
+ name: "listItem",
719
+ title: "List type",
720
+ type: "string",
721
+ options: {
722
+ list: lists || DEFAULT_LIST_TYPES
723
+ }
724
+ };
725
+ }
726
+ function createChildrenField(marks, of = []) {
727
+ return {
728
+ name: "children",
729
+ title: "Content",
730
+ type: "array",
731
+ of: [
732
+ {
733
+ type: "span",
734
+ fields: [DEFAULT_TEXT_FIELD, DEFAULT_MARKS_FIELD],
735
+ annotations: marks && marks.annotations ? marks.annotations : DEFAULT_ANNOTATIONS,
736
+ decorators: marks && marks.decorators ? marks.decorators : DEFAULT_DECORATORS
737
+ },
738
+ ...of.filter((memberType) => memberType.type !== "span")
739
+ ]
740
+ };
741
+ }
742
+ const INHERITED_FIELDS = [
743
+ "type",
744
+ "name",
745
+ "title",
746
+ "jsonType",
747
+ "description",
748
+ "options",
749
+ "fieldsets",
750
+ "icon"
751
+ ], SPAN_CORE = {
752
+ name: "span",
753
+ title: "Span",
754
+ type: null,
755
+ jsonType: "object"
756
+ }, MARKS_FIELD = {
757
+ name: "marks",
758
+ title: "Marks",
759
+ type: "array",
760
+ of: [{ type: "string" }]
761
+ }, TEXT_FIELD = {
762
+ name: "text",
763
+ title: "Text",
764
+ type: "string"
765
+ }, DEFAULT_OPTIONS$2 = {}, SpanType = {
766
+ get() {
767
+ return SPAN_CORE;
768
+ },
769
+ extend(subTypeDef, extendMember) {
770
+ const options = { ...subTypeDef.options || DEFAULT_OPTIONS$2 }, { annotations = [], marks = [] } = subTypeDef, fields = [MARKS_FIELD, TEXT_FIELD], ownProps = { ...subTypeDef, options }, parsed = Object.assign(pick(SPAN_CORE, INHERITED_FIELDS), ownProps, {
771
+ type: SPAN_CORE
772
+ });
773
+ return lazyGetter(parsed, "fields", () => fields.map((fieldDef) => extendMember.cachedField(fieldDef))), lazyGetter(parsed, "annotations", () => annotations.map(extendMember)), lazyGetter(parsed, "marks", () => marks.map(extendMember)), lazyGetter(parsed, "preview", createPreviewGetter(subTypeDef)), lazyGetter(
774
+ parsed,
775
+ OWN_PROPS_NAME,
776
+ () => ({
777
+ ...ownProps,
778
+ fields: parsed.fields,
779
+ annotations: parsed.annotations,
780
+ marks: parsed.marks,
781
+ preview: parsed.preview
782
+ }),
783
+ { enumerable: !1, writable: !1 }
784
+ ), subtype(parsed);
785
+ function subtype(parent) {
786
+ return {
787
+ get() {
788
+ return parent;
789
+ },
790
+ extend: (extensionDef) => {
791
+ if (extensionDef.fields)
792
+ throw new Error('Cannot override `fields` of subtypes of "span"');
793
+ const subOwnProps = pick(extensionDef, INHERITED_FIELDS), current = Object.assign({}, parent, subOwnProps, {
794
+ type: parent
795
+ });
796
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
797
+ }
798
+ };
799
+ }
800
+ }
801
+ };
802
+ var primitivePreview = {
803
+ prepare: (val) => ({ title: String(val) })
804
+ };
805
+ const OVERRIDABLE_FIELDS$d = [...DEFAULT_OVERRIDEABLE_FIELDS], BOOLEAN_CORE = {
806
+ name: "boolean",
807
+ title: "Boolean",
808
+ type: null,
809
+ jsonType: "boolean"
810
+ }, BooleanType = {
811
+ get() {
812
+ return BOOLEAN_CORE;
813
+ },
814
+ extend(subTypeDef) {
815
+ const ownProps = {
816
+ ...subTypeDef,
817
+ preview: primitivePreview
818
+ }, parsed = Object.assign(pick(BOOLEAN_CORE, OVERRIDABLE_FIELDS$d), ownProps, {
819
+ type: BOOLEAN_CORE
820
+ });
821
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
822
+ function subtype(parent) {
823
+ return {
824
+ get() {
825
+ return parent;
826
+ },
827
+ extend: (extensionDef) => {
828
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$d), current = Object.assign({}, parent, subOwnProps, {
829
+ type: parent
830
+ });
831
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
832
+ }
833
+ };
834
+ }
835
+ }
836
+ }, REF_FIELD$2 = {
837
+ name: "_ref",
838
+ title: "Referenced document ID",
839
+ type: "string"
840
+ }, WEAK_FIELD$2 = {
841
+ name: "_weak",
842
+ title: "Weak reference marker",
843
+ type: "boolean"
844
+ }, DATASET_FIELD = {
845
+ name: "_dataset",
846
+ title: "Target dataset",
847
+ type: "string"
848
+ }, PROJECT_ID_FIELD = {
849
+ name: "_projectId",
850
+ title: "Target project ID",
851
+ type: "string",
852
+ hidden: !0
853
+ }, REFERENCE_FIELDS$2 = [REF_FIELD$2, WEAK_FIELD$2, DATASET_FIELD, PROJECT_ID_FIELD], OVERRIDABLE_FIELDS$c = [...DEFAULT_OVERRIDEABLE_FIELDS], CROSS_DATASET_REFERENCE_CORE = {
854
+ name: "crossDatasetReference",
855
+ type: null,
856
+ jsonType: "object"
857
+ };
858
+ function humanize$2(arr, conjunction) {
859
+ const len = arr.length;
860
+ if (len === 1)
861
+ return arr[0];
862
+ const first = arr.slice(0, len - 1), last = arr[len - 1];
863
+ return `${first.join(", ")} ${conjunction} ${last}`;
864
+ }
865
+ function buildTitle$2(type) {
866
+ return !type.to || type.to.length === 0 ? "Cross dataset Reference" : `Cross dataset reference to ${humanize$2(
867
+ arrify(type.to).map((toType) => toType.title || capitalize(toType.type)),
868
+ "or"
869
+ ).toLowerCase()}`;
870
+ }
871
+ const CrossDatasetReferenceType = {
872
+ get() {
873
+ return CROSS_DATASET_REFERENCE_CORE;
874
+ },
875
+ extend(subTypeDef, createMemberType) {
876
+ if (!subTypeDef.to)
877
+ throw new Error(
878
+ `Missing "to" field in cross dataset reference definition. Check the type ${subTypeDef.name}`
879
+ );
880
+ const parsed = Object.assign(
881
+ pick(CROSS_DATASET_REFERENCE_CORE, OVERRIDABLE_FIELDS$c),
882
+ subTypeDef,
883
+ {
884
+ type: CROSS_DATASET_REFERENCE_CORE
885
+ }
886
+ );
887
+ return lazyGetter(parsed, "fields", () => REFERENCE_FIELDS$2.map((fieldDef) => createMemberType.cachedField(fieldDef))), lazyGetter(parsed, "to", () => arrify(subTypeDef.to).map((toType) => ({
888
+ ...toType,
889
+ __experimental_search: resolveSearchConfigForBaseFieldPaths(toType)
890
+ }))), lazyGetter(parsed, "title", () => subTypeDef.title || buildTitle$2(parsed)), lazyGetter(
891
+ parsed,
892
+ OWN_PROPS_NAME,
893
+ () => ({
894
+ ...subTypeDef,
895
+ fields: parsed.fields,
896
+ to: parsed.to,
897
+ title: parsed.title
898
+ }),
899
+ { enumerable: !1, writable: !1 }
900
+ ), subtype(parsed);
901
+ function subtype(parent) {
902
+ return {
903
+ get() {
904
+ return parent;
905
+ },
906
+ extend: (extensionDef) => {
907
+ if (extensionDef.of)
908
+ throw new Error('Cannot override `of` of subtypes of "reference"');
909
+ const ownProps = pick(extensionDef, OVERRIDABLE_FIELDS$c), current = Object.assign({}, parent, ownProps, {
910
+ type: parent
911
+ });
912
+ return hiddenGetter(current, OWN_PROPS_NAME, ownProps), subtype(current);
913
+ }
914
+ };
915
+ }
916
+ }
917
+ }, OVERRIDABLE_FIELDS$b = [...DEFAULT_OVERRIDEABLE_FIELDS], DATE_CORE = {
918
+ name: "date",
919
+ title: "Datetime",
920
+ type: null,
921
+ jsonType: "string"
922
+ }, DateType = {
923
+ get() {
924
+ return DATE_CORE;
925
+ },
926
+ extend(subTypeDef) {
927
+ const ownProps = {
928
+ ...subTypeDef,
929
+ preview: primitivePreview
930
+ }, parsed = Object.assign(pick(DATE_CORE, OVERRIDABLE_FIELDS$b), ownProps, {
931
+ type: DATE_CORE
932
+ });
933
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
934
+ function subtype(parent) {
935
+ return {
936
+ get() {
937
+ return parent;
938
+ },
939
+ extend: (extensionDef) => {
940
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$b), current = Object.assign({}, parent, subOwnProps, {
941
+ type: parent
942
+ });
943
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
944
+ }
945
+ };
946
+ }
947
+ }
948
+ }, OVERRIDABLE_FIELDS$a = [...DEFAULT_OVERRIDEABLE_FIELDS], DATETIME_CORE = {
949
+ name: "datetime",
950
+ title: "Datetime",
951
+ type: null,
952
+ jsonType: "string"
953
+ }, DateTimeType = {
954
+ get() {
955
+ return DATETIME_CORE;
956
+ },
957
+ extend(subTypeDef) {
958
+ const ownProps = {
959
+ ...subTypeDef,
960
+ preview: primitivePreview
961
+ }, parsed = Object.assign(pick(DATETIME_CORE, OVERRIDABLE_FIELDS$a), ownProps, {
962
+ type: DATETIME_CORE
963
+ });
964
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
965
+ function subtype(parent) {
966
+ return {
967
+ get() {
968
+ return parent;
969
+ },
970
+ extend: (extensionDef) => {
971
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$a), current = Object.assign({}, parent, subOwnProps, {
972
+ type: parent
973
+ });
974
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
975
+ }
976
+ };
977
+ }
978
+ }
979
+ }, CANDIDATES = ["title", "name", "label", "heading", "header", "caption", "description"], PRIMITIVES = ["string", "boolean", "number"], isPrimitive = (field) => PRIMITIVES.includes(field.type);
980
+ function guessOrderingConfig(objectTypeDef) {
981
+ let candidates = CANDIDATES.filter(
982
+ (candidate) => objectTypeDef.fields.some((field) => isPrimitive(field) && field.name === candidate)
983
+ );
984
+ return candidates.length === 0 && (candidates = objectTypeDef.fields.filter(isPrimitive).map((field) => field.name)), candidates.map(
985
+ (name) => ({
986
+ name,
987
+ i18n: {
988
+ title: { key: `default-orderings.${name}`, ns: "studio" }
989
+ },
990
+ title: capitalize(startCase(name)),
991
+ by: [{ field: name, direction: "asc" }]
992
+ })
993
+ );
994
+ }
995
+ function normalizeSearchConfigs(configs) {
996
+ if (!Array.isArray(configs))
997
+ throw new Error(
998
+ "The search config of a document type must be an array of search config objects"
999
+ );
1000
+ return configs.map((conf) => {
1001
+ if (conf === "defaults")
1002
+ return conf;
1003
+ if (!isPlainObject(conf))
1004
+ throw new Error("Search config must be an object of {path: string, weight: number}");
1005
+ return {
1006
+ weight: "weight" in conf ? conf.weight : 1,
1007
+ path: toPath(conf.path),
1008
+ mapWith: typeof conf.mapWith == "string" ? conf.mapWith : void 0
1009
+ };
1010
+ });
1011
+ }
1012
+ const OVERRIDABLE_FIELDS$9 = [
1013
+ ...DEFAULT_OVERRIDEABLE_FIELDS,
1014
+ "orderings",
1015
+ "__experimental_search",
1016
+ "blockEditor",
1017
+ "icon"
1018
+ ], ObjectType = {
1019
+ get() {
1020
+ return {
1021
+ name: "object",
1022
+ title: "Object",
1023
+ type: null,
1024
+ jsonType: "object"
1025
+ };
1026
+ },
1027
+ extend(rawSubTypeDef, createMemberType) {
1028
+ const subTypeDef = { fields: [], ...rawSubTypeDef }, options = { ...subTypeDef.options }, ownProps = {
1029
+ ...subTypeDef,
1030
+ title: subTypeDef.title || (subTypeDef.name ? startCase(subTypeDef.name) : "Object"),
1031
+ options,
1032
+ orderings: subTypeDef.orderings || guessOrderingConfig(subTypeDef),
1033
+ fields: subTypeDef.fields.map(
1034
+ (fieldDef) => createMemberType.cachedObjectField(fieldDef)
1035
+ )
1036
+ }, parsed = Object.assign(pick(this.get(), OVERRIDABLE_FIELDS$9), ownProps, {
1037
+ type: this.get()
1038
+ });
1039
+ return lazyGetter(parsed, "fieldsets", () => createFieldsets(subTypeDef, parsed.fields)), lazyGetter(parsed, "groups", () => createFieldsGroups(subTypeDef, parsed.fields)), lazyGetter(parsed, "preview", createPreviewGetter(subTypeDef)), lazyGetter(
1040
+ parsed,
1041
+ OWN_PROPS_NAME,
1042
+ () => ({
1043
+ ...ownProps,
1044
+ preview: parsed.preview
1045
+ }),
1046
+ { enumerable: !1, writable: !1 }
1047
+ ), lazyGetter(
1048
+ parsed,
1049
+ "__experimental_search",
1050
+ () => {
1051
+ const userProvidedSearchConfig = subTypeDef.__experimental_search ? normalizeSearchConfigs(subTypeDef.__experimental_search) : null;
1052
+ return userProvidedSearchConfig ? userProvidedSearchConfig.map(
1053
+ (entry) => entry === "defaults" ? normalizeSearchConfigs(subTypeDef) : entry
1054
+ ) : resolveSearchConfig(parsed);
1055
+ },
1056
+ {
1057
+ enumerable: !1
1058
+ }
1059
+ ), subtype(parsed);
1060
+ function subtype(parent) {
1061
+ return {
1062
+ get() {
1063
+ return parent;
1064
+ },
1065
+ extend: (extensionDef) => {
1066
+ if (extensionDef.fields)
1067
+ throw new Error('Cannot override `fields` of subtypes of "object"');
1068
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$9);
1069
+ subOwnProps.title = extensionDef.title || subTypeDef.title || (subTypeDef.name ? startCase(subTypeDef.name) : "Object");
1070
+ const current = Object.assign({}, parent, pick(extensionDef, OVERRIDABLE_FIELDS$9), {
1071
+ type: parent
1072
+ });
1073
+ return lazyGetter(current, "__experimental_search", () => parent.__experimental_search), hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
1074
+ }
1075
+ };
1076
+ }
1077
+ }
1078
+ };
1079
+ function createFieldsets(typeDef, fields) {
1080
+ const fieldsetsByName = {};
1081
+ for (const fieldset of typeDef.fieldsets || []) {
1082
+ if (fieldsetsByName[fieldset.name])
1083
+ throw new Error(
1084
+ `Duplicate fieldset name "${fieldset.name}" found for type '${typeDef.title ? typeDef.title : startCase(typeDef.name)}'`
1085
+ );
1086
+ fieldsetsByName[fieldset.name] = { title: startCase(fieldset.name), ...fieldset, fields: [] };
1087
+ }
1088
+ const fieldsets = /* @__PURE__ */ new Set();
1089
+ for (const field of fields) {
1090
+ if (!field.fieldset) {
1091
+ fieldsets.add({ single: !0, field });
1092
+ continue;
1093
+ }
1094
+ const fieldset = fieldsetsByName[field.fieldset];
1095
+ if (!fieldset)
1096
+ throw new Error(
1097
+ `Fieldset '${field.fieldset}' is not defined in schema for type '${typeDef.name}'`
1098
+ );
1099
+ fieldset.fields.push(field), fieldsets.add(fieldset);
1100
+ }
1101
+ return Array.from(fieldsets);
1102
+ }
1103
+ function createFieldsGroups(typeDef, fields) {
1104
+ const groupsByName = {};
1105
+ let numDefaultGroups = 0;
1106
+ for (const group of typeDef.groups || []) {
1107
+ if (groupsByName[group.name])
1108
+ throw new Error(
1109
+ `Duplicate group name "${group.name}" found for type '${typeDef.title ? typeDef.title : startCase(typeDef.name)}'`
1110
+ );
1111
+ if (groupsByName[group.name] = { title: startCase(group.name), ...group, fields: [] }, group.default && ++numDefaultGroups > 1)
1112
+ throw new Error(
1113
+ `More than one field group defined as default for type '${typeDef.title ? typeDef.title : startCase(typeDef.name)}' - only 1 is supported`
1114
+ );
1115
+ }
1116
+ return fields.forEach((field) => {
1117
+ const fieldGroupNames = castArray(field.group || []);
1118
+ fieldGroupNames.length !== 0 && fieldGroupNames.forEach((fieldGroupName) => {
1119
+ const currentGroup = groupsByName[fieldGroupName];
1120
+ if (!currentGroup)
1121
+ throw new Error(
1122
+ `Field group '${fieldGroupName}' is not defined in schema for type '${typeDef.title ? typeDef.name : startCase(typeDef.name)}'`
1123
+ );
1124
+ currentGroup.fields.push(field);
1125
+ });
1126
+ }), flatMap(groupsByName).filter(
1127
+ // All fields group is added by default in structure.
1128
+ // To pass the properties from the schema to the form state, we need to include it in the list of groups.
1129
+ (group) => group.fields.length > 0 || group.name === ALL_FIELDS_GROUP_NAME
1130
+ );
1131
+ }
1132
+ const DOCUMENT_CORE = {
1133
+ name: "document",
1134
+ title: "Document",
1135
+ type: null,
1136
+ jsonType: "object"
1137
+ }, DocumentType = {
1138
+ get() {
1139
+ return DOCUMENT_CORE;
1140
+ },
1141
+ extend: ObjectType.extend
1142
+ }, OVERRIDABLE_FIELDS$8 = [...DEFAULT_OVERRIDEABLE_FIELDS], EMAIL_CORE = {
1143
+ name: "email",
1144
+ title: "Email",
1145
+ type: null,
1146
+ jsonType: "string"
1147
+ };
1148
+ lazyGetter(
1149
+ EMAIL_CORE,
1150
+ OWN_PROPS_NAME,
1151
+ () => ({
1152
+ ...EMAIL_CORE,
1153
+ validation: (Rule3) => Rule3.email()
1154
+ }),
1155
+ { enumerable: !1 }
1156
+ );
1157
+ const EmailType = {
1158
+ get() {
1159
+ return EMAIL_CORE;
1160
+ },
1161
+ extend(subTypeDef) {
1162
+ const ownProps = {
1163
+ ...subTypeDef,
1164
+ preview: primitivePreview
1165
+ }, parsed = Object.assign(pick(EMAIL_CORE, OVERRIDABLE_FIELDS$8), ownProps, {
1166
+ type: EMAIL_CORE
1167
+ });
1168
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
1169
+ function subtype(parent) {
1170
+ return {
1171
+ get() {
1172
+ return parent;
1173
+ },
1174
+ extend: (extensionDef) => {
1175
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$8), current = Object.assign({}, parent, subOwnProps, {
1176
+ type: parent
1177
+ });
1178
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
1179
+ }
1180
+ };
1181
+ }
1182
+ }
1183
+ }, ASSET_FIELD$1 = {
1184
+ name: "asset",
1185
+ type: "reference",
1186
+ to: { type: "sanity.fileAsset" }
1187
+ }, MEDIA_LIBRARY_ASSET_FIELD$1 = {
1188
+ name: "media",
1189
+ type: "globalDocumentReference",
1190
+ hidden: !0,
1191
+ to: [{ type: "sanity.asset" }]
1192
+ }, OVERRIDABLE_FIELDS$7 = [...DEFAULT_OVERRIDEABLE_FIELDS], FILE_CORE = {
1193
+ name: "file",
1194
+ title: "File",
1195
+ type: null,
1196
+ jsonType: "object"
1197
+ }, DEFAULT_OPTIONS$1 = {
1198
+ accept: ""
1199
+ }, FileType = {
1200
+ get() {
1201
+ return FILE_CORE;
1202
+ },
1203
+ extend(rawSubTypeDef, createMemberType) {
1204
+ const options = { ...rawSubTypeDef.options || DEFAULT_OPTIONS$1 }, fields = [ASSET_FIELD$1, MEDIA_LIBRARY_ASSET_FIELD$1, ...rawSubTypeDef.fields || []], subTypeDef = { ...rawSubTypeDef, fields }, parsed = Object.assign(pick(FILE_CORE, OVERRIDABLE_FIELDS$7), subTypeDef, {
1205
+ type: FILE_CORE,
1206
+ title: subTypeDef.title || (subTypeDef.name ? startCase(subTypeDef.name) : FILE_CORE.title),
1207
+ options,
1208
+ fields: subTypeDef.fields.map((fieldDef) => {
1209
+ const { name, fieldset, ...rest } = fieldDef, compiledField = {
1210
+ name,
1211
+ fieldset,
1212
+ isCustomized: !!rawSubTypeDef.fields
1213
+ };
1214
+ return lazyGetter(compiledField, "type", () => createMemberType({
1215
+ ...rest,
1216
+ title: fieldDef.title || startCase(name)
1217
+ }));
1218
+ })
1219
+ });
1220
+ return lazyGetter(parsed, "fieldsets", () => createFieldsets(subTypeDef, parsed.fields)), lazyGetter(parsed, "preview", createPreviewGetter(Object.assign({}, subTypeDef, { fields }))), lazyGetter(
1221
+ parsed,
1222
+ OWN_PROPS_NAME,
1223
+ () => ({
1224
+ ...subTypeDef,
1225
+ options,
1226
+ fields: parsed.fields,
1227
+ title: parsed.title,
1228
+ fieldsets: parsed.fieldsets,
1229
+ preview: parsed.preview
1230
+ }),
1231
+ { enumerable: !1, writable: !1 }
1232
+ ), subtype(parsed);
1233
+ function subtype(parent) {
1234
+ return {
1235
+ get() {
1236
+ return parent;
1237
+ },
1238
+ extend: (extensionDef) => {
1239
+ if (extensionDef.fields)
1240
+ throw new Error('Cannot override `fields` of subtypes of "file"');
1241
+ const ownProps = pick(extensionDef, OVERRIDABLE_FIELDS$7), current = Object.assign({}, parent, ownProps, {
1242
+ type: parent
1243
+ });
1244
+ return hiddenGetter(current, OWN_PROPS_NAME, ownProps), subtype(current);
1245
+ }
1246
+ };
1247
+ }
1248
+ }
1249
+ }, REF_FIELD$1 = {
1250
+ name: "_ref",
1251
+ title: "Referenced document ID",
1252
+ type: "string"
1253
+ }, WEAK_FIELD$1 = {
1254
+ name: "_weak",
1255
+ title: "Weak reference",
1256
+ type: "boolean"
1257
+ }, REFERENCE_FIELDS$1 = [REF_FIELD$1, WEAK_FIELD$1], OVERRIDABLE_FIELDS$6 = [...DEFAULT_OVERRIDEABLE_FIELDS], GLOBAL_DOCUMENT_REFERENCE_CORE = {
1258
+ name: "globalDocumentReference",
1259
+ title: "Global Document Reference",
1260
+ type: null,
1261
+ jsonType: "object"
1262
+ };
1263
+ function humanize$1(arr, conjunction) {
1264
+ const len = arr.length;
1265
+ if (len === 1)
1266
+ return arr[0];
1267
+ const first = arr.slice(0, len - 1), last = arr[len - 1];
1268
+ return `${first.join(", ")} ${conjunction} ${last}`;
1269
+ }
1270
+ function buildTitle$1(type) {
1271
+ return !type.to || type.to.length === 0 ? "Global Document Reference" : `Global Document Reference to ${humanize$1(
1272
+ arrify(type.to).map((toType) => toType.title),
1273
+ "or"
1274
+ ).toLowerCase()}`;
1275
+ }
1276
+ const GlobalDocumentReferenceType = {
1277
+ get() {
1278
+ return GLOBAL_DOCUMENT_REFERENCE_CORE;
1279
+ },
1280
+ extend(subTypeDef, createMemberType) {
1281
+ if (!subTypeDef.to)
1282
+ throw new Error(
1283
+ `Missing "to" field in global document reference definition. Check the type ${subTypeDef.name}`
1284
+ );
1285
+ const parsed = Object.assign(
1286
+ pick(GLOBAL_DOCUMENT_REFERENCE_CORE, OVERRIDABLE_FIELDS$6),
1287
+ subTypeDef,
1288
+ {
1289
+ type: GLOBAL_DOCUMENT_REFERENCE_CORE
1290
+ }
1291
+ );
1292
+ return lazyGetter(parsed, "fields", () => REFERENCE_FIELDS$1.map((fieldDef) => createMemberType.cachedField(fieldDef))), lazyGetter(parsed, "to", () => arrify(subTypeDef.to).map((toType) => ({
1293
+ ...toType
1294
+ }))), lazyGetter(parsed, "title", () => subTypeDef.title || buildTitle$1(parsed)), lazyGetter(
1295
+ parsed,
1296
+ OWN_PROPS_NAME,
1297
+ () => ({
1298
+ ...subTypeDef,
1299
+ fields: parsed.fields,
1300
+ to: parsed.to,
1301
+ title: parsed.title
1302
+ }),
1303
+ { enumerable: !1, writable: !1 }
1304
+ ), subtype(parsed);
1305
+ function subtype(parent) {
1306
+ return {
1307
+ get() {
1308
+ return parent;
1309
+ },
1310
+ extend: (extensionDef) => {
1311
+ if (extensionDef.of)
1312
+ throw new Error('Cannot override `of` of subtypes of "globalDocumentReference"');
1313
+ const ownProps = pick(extensionDef, OVERRIDABLE_FIELDS$6), current = Object.assign({}, parent, ownProps, {
1314
+ type: parent
1315
+ });
1316
+ return hiddenGetter(current, OWN_PROPS_NAME, ownProps), subtype(current);
1317
+ }
1318
+ };
1319
+ }
1320
+ }
1321
+ }, ASSET_FIELD = {
1322
+ name: "asset",
1323
+ type: "reference",
1324
+ to: [{ type: "sanity.imageAsset" }]
1325
+ }, HOTSPOT_FIELD = {
1326
+ name: "hotspot",
1327
+ type: "sanity.imageHotspot"
1328
+ }, CROP_FIELD = {
1329
+ name: "crop",
1330
+ type: "sanity.imageCrop"
1331
+ }, MEDIA_LIBRARY_ASSET_FIELD = {
1332
+ name: "media",
1333
+ type: "globalDocumentReference",
1334
+ hidden: !0,
1335
+ to: [{ type: "sanity.asset" }]
1336
+ }, OVERRIDABLE_FIELDS$5 = [...DEFAULT_OVERRIDEABLE_FIELDS], IMAGE_CORE = {
1337
+ name: "image",
1338
+ title: "Image",
1339
+ type: null,
1340
+ jsonType: "object"
1341
+ }, DEFAULT_OPTIONS = {}, ImageType = {
1342
+ get() {
1343
+ return IMAGE_CORE;
1344
+ },
1345
+ extend(rawSubTypeDef, createMemberType) {
1346
+ const options = { ...rawSubTypeDef.options || DEFAULT_OPTIONS };
1347
+ let hotspotFields = [HOTSPOT_FIELD, CROP_FIELD];
1348
+ options.hotspot || (hotspotFields = hotspotFields.map((field) => ({ ...field, hidden: !0 })));
1349
+ const fields = [
1350
+ ASSET_FIELD,
1351
+ MEDIA_LIBRARY_ASSET_FIELD,
1352
+ ...hotspotFields,
1353
+ ...rawSubTypeDef.fields || []
1354
+ ], subTypeDef = { ...rawSubTypeDef, fields }, parsed = Object.assign(pick(this.get(), OVERRIDABLE_FIELDS$5), subTypeDef, {
1355
+ type: IMAGE_CORE,
1356
+ title: subTypeDef.title || (subTypeDef.name ? startCase(subTypeDef.name) : IMAGE_CORE.title),
1357
+ options,
1358
+ fields: subTypeDef.fields.map((fieldDef) => {
1359
+ const { name, fieldset, ...rest } = fieldDef, compiledField = {
1360
+ name,
1361
+ fieldset,
1362
+ isCustomized: !!rawSubTypeDef.fields
1363
+ };
1364
+ return lazyGetter(compiledField, "type", () => createMemberType({
1365
+ ...rest,
1366
+ title: fieldDef.title || startCase(name)
1367
+ }));
1368
+ })
1369
+ });
1370
+ return lazyGetter(parsed, "fieldsets", () => createFieldsets(subTypeDef, parsed.fields)), lazyGetter(parsed, "preview", createPreviewGetter(Object.assign({}, subTypeDef, { fields }))), lazyGetter(
1371
+ parsed,
1372
+ OWN_PROPS_NAME,
1373
+ () => ({
1374
+ ...subTypeDef,
1375
+ options,
1376
+ fields: parsed.fields,
1377
+ title: parsed.title,
1378
+ fieldsets: parsed.fieldsets,
1379
+ preview: parsed.preview
1380
+ }),
1381
+ { enumerable: !1, writable: !1 }
1382
+ ), subtype(parsed);
1383
+ function subtype(parent) {
1384
+ return {
1385
+ get() {
1386
+ return parent;
1387
+ },
1388
+ extend: (extensionDef) => {
1389
+ if (extensionDef.fields)
1390
+ throw new Error('Cannot override `fields` of subtypes of "image"');
1391
+ const ownProps = pick(extensionDef, OVERRIDABLE_FIELDS$5), current = Object.assign({}, parent, ownProps, {
1392
+ type: parent
1393
+ });
1394
+ return hiddenGetter(current, OWN_PROPS_NAME, ownProps), subtype(current);
1395
+ }
1396
+ };
1397
+ }
1398
+ }
1399
+ }, OVERRIDABLE_FIELDS$4 = [...DEFAULT_OVERRIDEABLE_FIELDS], NUMBER_CORE = {
1400
+ name: "number",
1401
+ title: "Number",
1402
+ type: null,
1403
+ jsonType: "number"
1404
+ }, NumberType = {
1405
+ get() {
1406
+ return NUMBER_CORE;
1407
+ },
1408
+ extend(subTypeDef) {
1409
+ const ownProps = {
1410
+ ...subTypeDef,
1411
+ preview: primitivePreview
1412
+ }, parsed = Object.assign(pick(NUMBER_CORE, OVERRIDABLE_FIELDS$4), ownProps, {
1413
+ type: NUMBER_CORE
1414
+ });
1415
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
1416
+ function subtype(parent) {
1417
+ return {
1418
+ get() {
1419
+ return parent;
1420
+ },
1421
+ extend: (extensionDef) => {
1422
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$4), current = Object.assign({}, parent, subOwnProps, {
1423
+ type: parent
1424
+ });
1425
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
1426
+ }
1427
+ };
1428
+ }
1429
+ }
1430
+ }, REF_FIELD = {
1431
+ name: "_ref",
1432
+ title: "Referenced document ID",
1433
+ type: "string"
1434
+ }, WEAK_FIELD = {
1435
+ name: "_weak",
1436
+ title: "Weak reference",
1437
+ type: "boolean"
1438
+ }, REFERENCE_FIELDS = [REF_FIELD, WEAK_FIELD], OVERRIDABLE_FIELDS$3 = [...DEFAULT_OVERRIDEABLE_FIELDS], REFERENCE_CORE = {
1439
+ name: "reference",
1440
+ title: "Reference",
1441
+ type: null,
1442
+ jsonType: "object"
1443
+ };
1444
+ function humanize(arr, conjunction) {
1445
+ const len = arr.length;
1446
+ if (len === 1)
1447
+ return arr[0];
1448
+ const first = arr.slice(0, len - 1), last = arr[len - 1];
1449
+ return `${first.join(", ")} ${conjunction} ${last}`;
1450
+ }
1451
+ function buildTitle(type) {
1452
+ return !type.to || type.to.length === 0 ? "Reference" : `Reference to ${humanize(
1453
+ arrify(type.to).map((toType) => toType.title),
1454
+ "or"
1455
+ ).toLowerCase()}`;
1456
+ }
1457
+ const ReferenceType = {
1458
+ get() {
1459
+ return REFERENCE_CORE;
1460
+ },
1461
+ extend(subTypeDef, createMemberType) {
1462
+ if (!subTypeDef.to)
1463
+ throw new Error(
1464
+ `Missing "to" field in reference definition. Check the type ${subTypeDef.name}`
1465
+ );
1466
+ const parsed = Object.assign(pick(REFERENCE_CORE, OVERRIDABLE_FIELDS$3), subTypeDef, {
1467
+ type: REFERENCE_CORE
1468
+ });
1469
+ return lazyGetter(parsed, "fields", () => REFERENCE_FIELDS.map((fieldDef) => createMemberType.cachedField(fieldDef))), lazyGetter(parsed, "fieldsets", () => createFieldsets(subTypeDef, parsed.fields)), lazyGetter(parsed, "to", () => arrify(subTypeDef.to).map((toType) => createMemberType(toType))), lazyGetter(parsed, "title", () => subTypeDef.title || buildTitle(parsed)), lazyGetter(
1470
+ parsed,
1471
+ OWN_PROPS_NAME,
1472
+ () => ({
1473
+ ...subTypeDef,
1474
+ fields: parsed.fields,
1475
+ fieldsets: parsed.fieldsets,
1476
+ to: parsed.to,
1477
+ title: parsed.title
1478
+ }),
1479
+ { enumerable: !1, writable: !1 }
1480
+ ), subtype(parsed);
1481
+ function subtype(parent) {
1482
+ return {
1483
+ get() {
1484
+ return parent;
1485
+ },
1486
+ extend: (extensionDef) => {
1487
+ if (extensionDef.of)
1488
+ throw new Error('Cannot override `of` of subtypes of "reference"');
1489
+ const ownProps = pick(extensionDef, OVERRIDABLE_FIELDS$3), current = Object.assign({}, parent, ownProps, {
1490
+ type: parent
1491
+ });
1492
+ return hiddenGetter(current, OWN_PROPS_NAME, ownProps), subtype(current);
1493
+ }
1494
+ };
1495
+ }
1496
+ }
1497
+ }, OVERRIDABLE_FIELDS$2 = [...DEFAULT_OVERRIDEABLE_FIELDS], STRING_CORE = {
1498
+ name: "string",
1499
+ title: "String",
1500
+ type: null,
1501
+ jsonType: "string"
1502
+ }, StringType = {
1503
+ get() {
1504
+ return STRING_CORE;
1505
+ },
1506
+ extend(subTypeDef) {
1507
+ const ownProps = {
1508
+ ...subTypeDef,
1509
+ preview: primitivePreview
1510
+ }, parsed = Object.assign(pick(STRING_CORE, OVERRIDABLE_FIELDS$2), ownProps, {
1511
+ type: STRING_CORE
1512
+ });
1513
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
1514
+ function subtype(parent) {
1515
+ return {
1516
+ get() {
1517
+ return parent;
1518
+ },
1519
+ extend: (extensionDef) => {
1520
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$2), current = Object.assign({}, parent, subOwnProps, {
1521
+ type: parent
1522
+ });
1523
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
1524
+ }
1525
+ };
1526
+ }
1527
+ }
1528
+ }, OVERRIDABLE_FIELDS$1 = [...DEFAULT_OVERRIDEABLE_FIELDS, "rows"], TEXT_CORE = {
1529
+ name: "text",
1530
+ title: "Text",
1531
+ type: null,
1532
+ jsonType: "string"
1533
+ }, TextType = {
1534
+ get() {
1535
+ return TEXT_CORE;
1536
+ },
1537
+ extend(subTypeDef) {
1538
+ const ownProps = {
1539
+ ...subTypeDef,
1540
+ preview: primitivePreview
1541
+ }, parsed = Object.assign(pick(TEXT_CORE, OVERRIDABLE_FIELDS$1), ownProps, {
1542
+ type: TEXT_CORE
1543
+ });
1544
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
1545
+ function subtype(parent) {
1546
+ return {
1547
+ get() {
1548
+ return parent;
1549
+ },
1550
+ extend: (extensionDef) => {
1551
+ const subOwnProps = pick(extensionDef, OVERRIDABLE_FIELDS$1), current = Object.assign({}, parent, subOwnProps, {
1552
+ type: parent
1553
+ });
1554
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnProps), subtype(current);
1555
+ }
1556
+ };
1557
+ }
1558
+ }
1559
+ }, OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS], URL_CORE = {
1560
+ name: "url",
1561
+ title: "Url",
1562
+ type: null,
1563
+ jsonType: "string"
1564
+ }, UrlType = {
1565
+ get() {
1566
+ return URL_CORE;
1567
+ },
1568
+ extend(subTypeDef) {
1569
+ const ownProps = {
1570
+ ...subTypeDef,
1571
+ preview: primitivePreview
1572
+ }, parsed = Object.assign(pick(URL_CORE, OVERRIDABLE_FIELDS), ownProps, {
1573
+ type: URL_CORE
1574
+ });
1575
+ return hiddenGetter(parsed, OWN_PROPS_NAME, ownProps), subtype(parsed);
1576
+ function subtype(parent) {
1577
+ return {
1578
+ get() {
1579
+ return parent;
1580
+ },
1581
+ extend: (extensionDef) => {
1582
+ const subOwnownProps = pick(extensionDef, OVERRIDABLE_FIELDS), current = Object.assign({}, parent, subOwnownProps, {
1583
+ type: parent
1584
+ });
1585
+ return hiddenGetter(current, OWN_PROPS_NAME, subOwnownProps), subtype(current);
1586
+ }
1587
+ };
1588
+ }
1589
+ }
1590
+ };
1591
+ var types = /* @__PURE__ */ Object.freeze({
1592
+ __proto__: null,
1593
+ any: AnyType,
1594
+ array: ArrayType,
1595
+ block: BlockType,
1596
+ boolean: BooleanType,
1597
+ crossDatasetReference: CrossDatasetReferenceType,
1598
+ date: DateType,
1599
+ datetime: DateTimeType,
1600
+ document: DocumentType,
1601
+ email: EmailType,
1602
+ file: FileType,
1603
+ globalDocumentReference: GlobalDocumentReferenceType,
1604
+ image: ImageType,
1605
+ number: NumberType,
1606
+ object: ObjectType,
1607
+ reference: ReferenceType,
1608
+ span: SpanType,
1609
+ string: StringType,
1610
+ text: TextType,
1611
+ url: UrlType
1612
+ });
1613
+ function compileRegistry(schemaDef) {
1614
+ const registry = /* @__PURE__ */ Object.create(null);
1615
+ let localTypeNames;
1616
+ schemaDef.parent ? (Object.assign(registry, schemaDef.parent._registry), localTypeNames = []) : (Object.assign(registry, types), localTypeNames = Object.keys(types));
1617
+ const defsByName = schemaDef.types.reduce((acc, def) => {
1618
+ if (acc[def.name])
1619
+ throw new Error(`Duplicate type name added to schema: ${def.name}`);
1620
+ return acc[def.name] = def, acc;
1621
+ }, {}), memberCache = /* @__PURE__ */ new Map(), fieldCache = /* @__PURE__ */ new Map(), objectFieldCache = /* @__PURE__ */ new Map(), extendHelper = Object.assign(extendMember, {
1622
+ cached(def) {
1623
+ let member = memberCache.get(def);
1624
+ return member || (member = extendMember(def), memberCache.set(def, member)), member;
1625
+ },
1626
+ cachedField(fieldDef) {
1627
+ let field = fieldCache.get(fieldDef);
1628
+ if (!field) {
1629
+ const { name, ...type } = fieldDef;
1630
+ field = {
1631
+ name,
1632
+ type: extendMember(type)
1633
+ }, fieldCache.set(fieldDef, field);
1634
+ }
1635
+ return field;
1636
+ },
1637
+ cachedObjectField(fieldDef) {
1638
+ let field = objectFieldCache.get(fieldDef);
1639
+ if (!field) {
1640
+ const { name, fieldset, group, ...rest } = fieldDef;
1641
+ field = {
1642
+ name,
1643
+ group,
1644
+ fieldset
1645
+ }, lazyGetter(field, "type", () => extendMember({
1646
+ ...rest,
1647
+ title: fieldDef.title || startCase(name)
1648
+ })), objectFieldCache.set(fieldDef, field);
1649
+ }
1650
+ return field;
1651
+ }
1652
+ });
1653
+ return schemaDef.types.forEach(add), {
1654
+ registry,
1655
+ localTypeNames
1656
+ };
1657
+ function ensure(typeName) {
1658
+ if (!registry[typeName]) {
1659
+ if (!defsByName[typeName])
1660
+ throw new Error(`Unknown type: ${typeName}`);
1661
+ add(defsByName[typeName]);
1662
+ }
1663
+ }
1664
+ function extendMember(memberDef) {
1665
+ return ensure(memberDef.type), registry[memberDef.type].extend(memberDef, extendHelper).get();
1666
+ }
1667
+ function add(typeDef) {
1668
+ ensure(typeDef.type), !registry[typeDef.name] && (localTypeNames.push(typeDef.name), registry[typeDef.name] = registry[typeDef.type].extend(typeDef, extendMember));
1669
+ }
1670
+ }
1671
+ class Schema {
1672
+ _original;
1673
+ _registry;
1674
+ #localTypeNames;
1675
+ static compile(schemaDef) {
1676
+ return new Schema(schemaDef);
1677
+ }
1678
+ constructor(schemaDef) {
1679
+ this._original = schemaDef;
1680
+ const { registry, localTypeNames } = compileRegistry(schemaDef);
1681
+ this._registry = registry, this.#localTypeNames = localTypeNames;
1682
+ }
1683
+ get name() {
1684
+ return this._original.name;
1685
+ }
1686
+ /**
1687
+ * Returns the parent schema.
1688
+ */
1689
+ get parent() {
1690
+ return this._original.parent;
1691
+ }
1692
+ get(name) {
1693
+ return this._registry[name] && this._registry[name].get();
1694
+ }
1695
+ has(name) {
1696
+ return name in this._registry;
1697
+ }
1698
+ getTypeNames() {
1699
+ return Object.keys(this._registry);
1700
+ }
1701
+ getLocalTypeNames() {
1702
+ return this.#localTypeNames;
1703
+ }
1704
+ }
1705
+ class DeprecatedDefaultSchema extends Schema {
1706
+ static compile(schemaDef) {
1707
+ return new DeprecatedDefaultSchema(schemaDef);
1708
+ }
1709
+ constructor(schemaDef) {
1710
+ super(schemaDef);
1711
+ const stack = new Error(
1712
+ 'The default export of `@sanity/schema` is deprecated. Use `import {Schema} from "@sanity/schema"` instead.'
1713
+ ).stack.replace(/^Error/, "Warning");
1714
+ console.warn(stack);
1715
+ }
1716
+ }
1717
+ export {
1718
+ ALL_FIELDS_GROUP_NAME,
1719
+ DEFAULT_ANNOTATIONS,
1720
+ DEFAULT_DECORATORS,
1721
+ DEFAULT_MAX_FIELD_DEPTH,
1722
+ DeprecatedDefaultSchema,
1723
+ OWN_PROPS_NAME,
1724
+ Rule,
1725
+ Schema,
1726
+ resolveSearchConfig,
1727
+ resolveSearchConfigForBaseFieldPaths
1728
+ };
1729
+ //# sourceMappingURL=Schema.js.map