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