-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbig-block.avif
674 lines (674 loc) · 20 KB
/
big-block.avif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
ased on menuItems provided
*/
menuItems(menuItems) {
return this.clone({
menuItems
});
}
/** Get Component menu items
* @returns menu items
*/
getMenuItems() {
return this.spec.menuItems;
}
/** Set Component menu item groups
* @param menuItemGroups - component menu item groups
* @returns component builder based on menuItemGroups provided
*/
menuItemGroups(menuItemGroups) {
return this.clone({
menuItemGroups
});
}
/** Get Component menu item groups
* @returns menu item groups
*/
getMenuItemGroups() {
return this.spec.menuItemGroups;
}
/** Serialize component
* @param options - serialization options
* @returns component object based on path provided in options
*
*/
serialize() {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
path: []
};
const {
id,
title,
child,
options: componentOptions,
component
} = this.spec;
if (!id) {
throw new SerializeError("`id` is required for `component` structure item", options.path, options.index).withHelpUrl(HELP_URL.ID_REQUIRED);
}
if (!component) {
throw new SerializeError("`component` is required for `component` structure item", options.path, options.index).withHelpUrl(HELP_URL.ID_REQUIRED);
}
return {
id: validateId(id, options.path, options.index),
title,
type: "component",
child,
component,
options: componentOptions || {},
menuItems: (this.spec.menuItems || []).map((item, i) => maybeSerializeMenuItem(item, i, options.path)),
menuItemGroups: (this.spec.menuItemGroups || []).map((item, i) => maybeSerializeMenuItemGroup(item, i, options.path))
};
}
/** Clone component builder (allows for options overriding)
* @param withSpec - component builder options
* @returns cloned builder
*/
clone(withSpec) {
const builder = new ComponentBuilder();
builder.spec = {
...this.spec,
...(withSpec || {})
};
return builder;
}
}
async function resolveTypeForDocument(getClient, id) {
const query = "*[_id in [$documentId, $draftId]]._type";
const documentId = sanity.getPublishedId(id);
const draftId = sanity.getDraftId(id);
const types = await getClient(sanity.DEFAULT_STUDIO_CLIENT_OPTIONS).fetch(query, {
documentId,
draftId
}, {
tag: "structure.resolve-type"
});
return types[0];
}
var __defProp$a = Object.defineProperty;
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, {
enumerable: true,
configurable: true,
writable: true,
value
}) : obj[key] = value;
var __publicField$a = (obj, key, value) => {
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
class GenericViewBuilder {
constructor() {
/** Generic view option object */
__publicField$a(this, "spec", {});
}
/** Set generic view ID
* @param id - generic view ID
* @returns generic view builder based on ID provided. See {@link ConcreteImpl}
*/
id(id) {
return this.clone({
id
});
}
/** Get generic view ID
* @returns generic view ID
*/
getId() {
return this.spec.id;
}
/** Set generic view title
* @param title - generic view title
* @returns generic view builder based on title provided and (if provided) its ID. See {@link ConcreteImpl}
*/
title(title) {
return this.clone({
title,
id: this.spec.id || kebabCase__default.default(title)
});
}
/** Get generic view title
* @returns generic view title
*/
getTitle() {
return this.spec.title;
}
/** Set generic view icon
* @param icon - generic view icon
* @returns generic view builder based on icon provided. See {@link ConcreteImpl}
*/
icon(icon) {
return this.clone({
icon
});
}
/** Get generic view icon
* @returns generic view icon
*/
getIcon() {
return this.spec.icon;
}
/** Serialize generic view
* @param options - serialization options. See {@link SerializeOptions}
* @returns generic view object based on path provided in options. See {@link BaseView}
*/
serialize() {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
path: []
};
const {
id,
title,
icon
} = this.spec;
if (!id) {
throw new SerializeError("`id` is required for view item", options.path, options.index).withHelpUrl(HELP_URL.ID_REQUIRED);
}
if (!title) {
throw new SerializeError("`title` is required for view item", options.path, options.index).withHelpUrl(HELP_URL.TITLE_REQUIRED);
}
return {
id: validateId(id, options.path, options.index),
title,
icon
};
}
}
function isSerializable(view) {
return typeof view.serialize === "function";
}
function maybeSerializeView(item, index, path) {
return isSerializable(item) ? item.serialize({
path,
index
}) : item;
}
var __defProp$9 = Object.defineProperty;
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, {
enumerable: true,
configurable: true,
writable: true,
value
}) : obj[key] = value;
var __publicField$9 = (obj, key, value) => {
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
const isComponentSpec = spec => sanity.isRecord(spec) && spec.type === "component";
class ComponentViewBuilder extends GenericViewBuilder {
constructor(componentOrSpec) {
const spec = isComponentSpec(componentOrSpec) ? {
...componentOrSpec
} : {
options: {}
};
super();
/** Partial Component view option object. See {@link ComponentView} */
__publicField$9(this, "spec");
this.spec = spec;
const userComponent = typeof componentOrSpec === "function" ? componentOrSpec : this.spec.component;
if (userComponent) {
this.spec = this.component(userComponent).spec;
}
}
/** Set view Component
* @param component - component view component. See {@link UserViewComponent}
* @returns component view builder based on component view provided. See {@link ComponentViewBuilder}
*/
component(component) {
return this.clone({
component
});
}
/** Get view Component
* @returns Partial component view. See {@link ComponentView}
*/
getComponent() {
return this.spec.component;
}
/** Set view Component options
* @param options - component view options
* @returns component view builder based on options provided. See {@link ComponentViewBuilder}
*/
options(options) {
return this.clone({
options
});
}
/** Get view Component options
* @returns component view options. See {@link ComponentView}
*/
getOptions() {
return this.spec.options || {};
}
/** Serialize view Component
* @param options - serialization options. See {@link SerializeOptions}
* @returns component view based on path provided in options. See {@link ComponentView}
*
*/
serialize() {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
path: []
};
const base = super.serialize(options);
const component = this.spec.component;
if (typeof component !== "function") {
throw new SerializeError("`component` is required and must be a function for `component()` view item", options.path, options.index).withHelpUrl(HELP_URL.COMPONENT_REQUIRED);
}
return {
...base,
component,
options: this.spec.options || {},
type: "component"
};
}
/** Clone Component view builder (allows for options overriding)
* @param withSpec - partial for component view option. See {@link ComponentView}
* @returns component view builder. See {@link ComponentViewBuilder}
*/
clone(withSpec) {
const builder = new ComponentViewBuilder();
builder.spec = {
...this.spec,
...(withSpec || {})
};
return builder;
}
}
var __defProp$8 = Object.defineProperty;
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, {
enumerable: true,
configurable: true,
writable: true,
value
}) : obj[key] = value;
var __publicField$8 = (obj, key, value) => {
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
class FormViewBuilder extends GenericViewBuilder {
constructor(spec) {
super();
/** Document list options. See {@link FormView} */
__publicField$8(this, "spec");
this.spec = {
id: "editor",
title: "Editor",
...(spec ? spec : {})
};
}
/**
* Serialize Form view builder
* @param options - Serialize options. See {@link SerializeOptions}
* @returns form view builder based on path provided in options. See {@link FormView}
*/
serialize() {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
path: []
};
return {
...super.serialize(options),
type: "form"
};
}
/**
* Clone Form view builder (allows for options overriding)
* @param withSpec - Partial form view builder options. See {@link FormView}
* @returns form view builder. See {@link FormViewBuilder}
*/
clone(withSpec) {
const builder = new FormViewBuilder();
builder.spec = {
...this.spec,
...(withSpec || {})
};
return builder;
}
}
const form = spec => new FormViewBuilder(spec);
const component = componentOrSpec => new ComponentViewBuilder(componentOrSpec);
var views = /*#__PURE__*/Object.freeze({
__proto__: null,
ComponentViewBuilder: ComponentViewBuilder,
FormViewBuilder: FormViewBuilder,
GenericViewBuilder: GenericViewBuilder,
component: component,
form: form,
maybeSerializeView: maybeSerializeView
});
var __defProp$7 = Object.defineProperty;
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, {
enumerable: true,
configurable: true,
writable: true,
value
}) : obj[key] = value;
var __publicField$7 = (obj, key, value) => {
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
const createDocumentChildResolver = _ref44 => {
let {
resolveDocumentNode,
getClient
} = _ref44;
return async (itemId, _ref45) => {
let {
params,
path
} = _ref45;
let type = params.type;
const parentPath = path.slice(0, path.length - 1);
const currentSegment = path[path.length - 1];
if (!type) {
type = await resolveTypeForDocument(getClient, itemId);
}
if (!type) {
throw new SerializeError("Failed to resolve document, and no type provided in parameters.", parentPath, currentSegment);
}
return resolveDocumentNode({
documentId: itemId,
schemaType: type
});
};
};
class DocumentBuilder {
constructor(_context, spec) {
this._context = _context;
/** Component builder option object See {@link PartialDocumentNode} */
__publicField$7(this, "spec");
this.spec = spec ? spec : {};
}
/** Set Document Builder ID
* @param id - document builder ID
* @returns document builder based on ID provided. See {@link DocumentBuilder}
*/
id(id) {
return this.clone({
id
});
}
/** Get Document Builder ID
* @returns document ID. See {@link PartialDocumentNode}
*/
getId() {
return this.spec.id;
}
/** Set Document title
* @param title - document title
* @returns document builder based on title provided (and ID). See {@link DocumentBuilder}
*/
title(title) {
return this.clone({
title,
id: getStructureNodeId(title, this.spec.id)
});
}
/** Get Document title
* @returns document title. See {@link PartialDocumentNode}
*/
getTitle() {
return this.spec.title;
}
/** Set Document child
* @param child - document child
* @returns document builder based on child provided. See {@link DocumentBuilder}
*/
child(child) {
return this.clone({
child
});
}
/** Get Document child
* @returns document child. See {@link PartialDocumentNode}
*/
getChild() {
return this.spec.child;
}
/** Set Document ID
* @param documentId - document ID
* @returns document builder with document based on ID provided. See {@link DocumentBuilder}
*/
documentId(documentId) {
const paneId = this.spec.id || documentId;
return this.clone({
id: paneId,
options: {
...(this.spec.options || {}),
id: documentId
}
});
}
/** Get Document ID
* @returns document ID. See {@link DocumentOptions}
*/
getDocumentId() {
var _a;
return (_a = this.spec.options) == null ? void 0 : _a.id;
}
/** Set Document Type
* @param documentType - document type
* @returns document builder with document based on type provided. See {@link DocumentBuilder}
*/
schemaType(documentType) {
return this.clone({
options: {
...(this.spec.options || {}),
type: typeof documentType === "string" ? documentType : documentType.name
}
});
}
/** Get Document Type
* @returns document type. See {@link DocumentOptions}
*/
getSchemaType() {
var _a;
return (_a = this.spec.options) == null ? void 0 : _a.type;
}
/** Set Document Template
* @param templateId - document template ID
* @param parameters - document template parameters
* @returns document builder with document based on template provided. See {@link DocumentBuilder}
*/
initialValueTemplate(templateId, parameters) {
return this.clone({
options: {
...(this.spec.options || {}),
template: templateId,
templateParameters: parameters
}
});
}
/** Get Document Template
* @returns document template. See {@link DocumentOptions}
*/
getInitialValueTemplate() {
var _a;
return (_a = this.spec.options) == null ? void 0 : _a.template;
}
/** Get Document's initial value Template parameters
* @returns document template parameters. See {@link DocumentOptions}
*/
getInitialValueTemplateParameters() {
var _a;
return (_a = this.spec.options) == null ? void 0 : _a.templateParameters;
}
/** Set Document views
* @param views - document views. See {@link ViewBuilder} and {@link View}
* @returns document builder with document based on views provided. See {@link DocumentBuilder}
*/
views(views) {
return this.clone({
views
});
}
/** Get Document views
* @returns document views. See {@link ViewBuilder} and {@link View}
*/
getViews() {
return this.spec.views || [];
}
/** Serialize Document builder
* @param options - serialization options. See {@link SerializeOptions}
* @returns document node based on path, index and hint provided in options. See {@link DocumentNode}
*/
serialize() {
let {
path = [],
index,
hint
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
path: []
};
const urlId = path[index || path.length - 1];
const id = this.spec.id || urlId && "".concat(urlId) || "";
const options = {
id,
type: void 0,
template: void 0,
templateParameters: void 0,
...this.spec.options
};
if (typeof id !== "string" || !id) {
throw new SerializeError("`id` is required for document nodes", path, index, hint).withHelpUrl(HELP_URL.ID_REQUIRED);
}
if (!options || !options.id) {
throw new SerializeError("document id (`id`) is required for document nodes", path, id, hint).withHelpUrl(HELP_URL.DOCUMENT_ID_REQUIRED);
}
if (!options || !options.type) {
throw new SerializeError("document type (`schemaType`) is required for document nodes", path, id, hint);
}
const views = (this.spec.views && this.spec.views.length > 0 ? this.spec.views : [form()]).map((item, i) => maybeSerializeView(item, i, path));
const viewIds = views.map(view => view.id);
const dupes = uniq__default.default(viewIds.filter((viewId, i) => viewIds.includes(viewId, i + 1)));
if (dupes.length > 0) {
throw new SerializeError("document node has views with duplicate IDs: ".concat(dupes.join(", ")), path, id, hint);
}
return {
...this.spec,
child: this.spec.child || createDocumentChildResolver(this._context),
id: validateId(id, path, index),
type: "document",
options: getDocumentOptions(options),
views
};
}
/** Clone Document builder
* @param withSpec - partial document node specification used to extend the cloned builder. See {@link PartialDocumentNode}
* @returns document builder based on context and spec provided. See {@link DocumentBuilder}
*/
clone() {
let withSpec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const builder = new DocumentBuilder(this._context);
const options = {
...(this.spec.options || {}),
...(withSpec.options || {})
};
builder.spec = {
...this.spec,
...withSpec,
options
};
return builder;
}
}
function getDocumentOptions(spec) {
const opts = {
id: spec.id || "",
type: spec.type || "*"
};
if (spec.template) {
opts.template = spec.template;
}
if (spec.templateParameters) {
opts.templateParameters = spec.templateParameters;
}
return opts;
}
function documentFromEditor(context, spec) {
let doc = (spec == null ? void 0 : spec.type) ?
// Use user-defined document fragment as base if possible
context.resolveDocumentNode({
schemaType: spec.type
}) :
// Fall back to plain old document builder
new DocumentBuilder(context);
if (!spec) return doc;
const {
id,
type,
template,
templateParameters
} = spec.options;
doc = doc.id(spec.id).documentId(id);
if (type) {
doc = doc.schemaType(type);
}
if (template) {
doc = doc.initialValueTemplate(template, templateParameters);
}
if (spec.child) {
doc = doc.child(spec.child);
}
return doc;
}
function documentFromEditorWithInitialValue(_ref46, templateId, parameters) {
let {
resolveDocumentNode,
templates
} = _ref46;
const template = templates.find(t => t.id === templateId);
if (!template) {
throw new Error("Template with ID \"".concat(templateId, "\" not defined"));
}
return resolveDocumentNode({
schemaType: template.schemaType
}).initialValueTemplate(templateId, parameters);
}
const layoutOptions = ["default", "card", "media", "detail", "block"];
const DEFAULT_INTENT_HANDLER = Symbol("Document type list canHandleIntent");
const defaultIntentChecker = (intentName, params, _ref47) => {
let {
pane
} = _ref47;
var _a, _b;
const isEdit = intentName === "edit";
const isCreate = intentName === "create";
const typedSpec = pane;
const paneFilter = ((_a = typedSpec.options) == null ? void 0 : _a.filter) || "";
const paneParams = ((_b = typedSpec.options) == null ? void 0 : _b.params) || {};
const typeNames = typedSpec.schemaTypeName ? [typedSpec.schemaTypeName] : getTypeNamesFromFilter(paneFilter, paneParams);
const initialValueTemplates = typedSpec.initialValueTemplates || [];
if (isCreate && params.template) {
return initialValueTemplates.some(tpl => tpl.templateId === params.template);
}
return isEdit && params.id && typeNames.includes(params.type) || isCreate && typeNames.includes(params.type);
};
defaultIntentChecker.identity = DEFAULT_INTENT_HANDLER;
var __defProp$6 = Object.defineProperty;
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, {
enumerable: true,
configurable: true,
writable: true,
value
}) : obj[key] = value;
var __publicField$6 = (obj, key, value) => {
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
class InitialValueTemplateItemBuilder {
constructor(_context, spec) {
this._context = _context;
/** Initial Value template item option object. See {@link InitialValueTemplateItem} */
__publicField$6(this, "spec");
this.spec = spec ? spec : {};
}
/** Set initial value template item builder ID
* @param id - initial value template item ID
* @returns initial value template item based on ID provided. See {@link InitialValueTemplateItemBuilder}
*/
id(id) {
return this.clone({
id
});
}
/** Get initial value template item builder ID
* @returns ini