@prismicio/types-internal 2.4.0-alpha.5 → 2.4.0-alpha.7

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.
@@ -119,41 +119,40 @@ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content,
119
119
  const primary = Object.entries(content.widget.primary).reduce((acc, [fieldKey, fieldContent]) => {
120
120
  var _a, _b;
121
121
  const fieldDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b[fieldKey];
122
- if ((0, GroupContent_1.isGroupContent)(fieldContent) && (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) {
123
- const transformedGroupField = (0, GroupContent_1.traverseGroupContent)({
124
- path: path.concat([
125
- { key: "primary", type: "primary" },
126
- { key: fieldKey, type: "Widget" },
127
- ]),
128
- key: fieldKey,
129
- apiId: sliceName,
130
- content: fieldContent,
131
- model: fieldDef,
132
- })(transformWidget);
133
- // Can happen if the transform function returns undefined to filter out a field
134
- if (!transformedGroupField)
135
- return acc;
136
- return {
137
- ...acc,
138
- [fieldKey]: transformedGroupField,
139
- };
140
- }
141
- const transformedField = transformWidget({
142
- path: path.concat([
143
- { key: "primary", type: "primary" },
144
- { key: fieldKey, type: "Widget" },
145
- ]),
146
- key: fieldKey,
147
- apiId: sliceName,
148
- model: fieldDef,
149
- content: fieldContent,
150
- });
122
+ const transformedField = (() => {
123
+ if ((0, GroupContent_1.isGroupContent)(fieldContent)) {
124
+ return (0, GroupContent_1.traverseGroupContent)({
125
+ path: path.concat([
126
+ { key: "primary", type: "primary" },
127
+ { key: fieldKey, type: "Widget" },
128
+ ]),
129
+ key: fieldKey,
130
+ apiId: fieldKey,
131
+ content: fieldContent,
132
+ model: (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType ? fieldDef : undefined,
133
+ })(transformWidget);
134
+ }
135
+ else if ((0, nestable_1.isNestableContent)(fieldContent)) {
136
+ return transformWidget({
137
+ path: path.concat([
138
+ { key: "primary", type: "primary" },
139
+ { key: fieldKey, type: "Widget" },
140
+ ]),
141
+ key: fieldKey,
142
+ apiId: fieldKey,
143
+ model: fieldDef,
144
+ content: fieldContent,
145
+ });
146
+ }
147
+ else {
148
+ return undefined;
149
+ }
150
+ })();
151
151
  // Can happen if the transform function returns undefined to filter out a field
152
152
  if (!transformedField)
153
153
  return acc;
154
- if (!(0, nestable_1.isNestableContent)(transformedField)) {
155
- console.warn(`Warn: Non nestable content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`);
156
- return acc;
154
+ if (!(0, SlicePrimaryContent_1.isSlicePrimaryContent)(transformedField)) {
155
+ console.warn(`Warn: Non nestable or group content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`);
157
156
  }
158
157
  return {
159
158
  ...acc,
@@ -325,3 +325,329 @@ export declare const SlicePrimaryWidget: t.UnionC<[t.UnionC<[t.ExactC<t.Intersec
325
325
  }>]>>]>;
326
326
  export declare type SlicePrimaryWidget = t.TypeOf<typeof SlicePrimaryWidget>;
327
327
  export declare type SlicePrimaryFieldTypes = SlicePrimaryWidget["type"];
328
+ export declare const isSlicePrimaryWidget: (u: unknown) => u is ({
329
+ type: "Boolean";
330
+ } & {
331
+ config?: {
332
+ label?: string | null | undefined;
333
+ default_value?: boolean;
334
+ placeholder_true?: string;
335
+ placeholder_false?: string;
336
+ };
337
+ }) | ({
338
+ type: "Color";
339
+ } & {
340
+ fieldset?: string | null | undefined;
341
+ config?: {
342
+ label?: string | null | undefined;
343
+ placeholder?: string;
344
+ };
345
+ }) | ({
346
+ type: "Date";
347
+ } & {
348
+ fieldset?: string | null | undefined;
349
+ config?: {
350
+ label?: string | null | undefined;
351
+ placeholder?: string;
352
+ default?: string;
353
+ };
354
+ }) | ({
355
+ type: "Embed";
356
+ } & {
357
+ fieldset?: string | null | undefined;
358
+ config?: {
359
+ label?: string | null | undefined;
360
+ placeholder?: string;
361
+ useAsTitle?: boolean;
362
+ };
363
+ }) | ({
364
+ type: "GeoPoint";
365
+ } & {
366
+ fieldset?: string | null | undefined;
367
+ config?: {
368
+ label?: string | null | undefined;
369
+ };
370
+ }) | ({
371
+ type: "Image";
372
+ } & {
373
+ fieldset?: string | null | undefined;
374
+ config?: {
375
+ label?: string | null | undefined;
376
+ placeholder?: string;
377
+ constraint?: {
378
+ width?: number | null;
379
+ height?: number | null;
380
+ };
381
+ thumbnails?: readonly ({
382
+ name: string;
383
+ } & {
384
+ width?: number | null;
385
+ height?: number | null;
386
+ })[];
387
+ };
388
+ }) | ({
389
+ type: "IntegrationFields";
390
+ } & {
391
+ fieldset?: string | null | undefined;
392
+ config?: {
393
+ label?: string | null | undefined;
394
+ placeholder?: string;
395
+ catalog?: string;
396
+ };
397
+ }) | ({
398
+ type: "Link";
399
+ } & {
400
+ fieldset?: string | null | undefined;
401
+ config?: {
402
+ label?: string | null | undefined;
403
+ useAsTitle?: boolean;
404
+ placeholder?: string;
405
+ select?: "media" | "document" | "web" | null;
406
+ customtypes?: readonly string[];
407
+ masks?: readonly string[];
408
+ tags?: readonly string[];
409
+ allowTargetBlank?: boolean;
410
+ };
411
+ }) | ({
412
+ type: "Number";
413
+ } & {
414
+ fieldset?: string | null | undefined;
415
+ config?: {
416
+ label?: string | null | undefined;
417
+ placeholder?: string;
418
+ min?: number;
419
+ max?: number;
420
+ step?: number;
421
+ };
422
+ }) | ({
423
+ type: "Range";
424
+ } & {
425
+ fieldset?: string | null | undefined;
426
+ config?: {
427
+ label?: string | null | undefined;
428
+ placeholder?: string;
429
+ min?: number;
430
+ max?: number;
431
+ step?: number;
432
+ };
433
+ }) | ({
434
+ type: "StructuredText";
435
+ } & {
436
+ fieldset?: string | null | undefined;
437
+ config?: {
438
+ label?: string | null | undefined;
439
+ placeholder?: string;
440
+ useAsTitle?: boolean;
441
+ single?: string;
442
+ multi?: string;
443
+ imageConstraint?: {
444
+ width?: number | null;
445
+ height?: number | null;
446
+ };
447
+ labels?: readonly string[];
448
+ allowTargetBlank?: boolean;
449
+ };
450
+ }) | ({
451
+ type: "Select";
452
+ } & {
453
+ fieldset?: string | null | undefined;
454
+ config?: {
455
+ label?: string | null | undefined;
456
+ placeholder?: string;
457
+ default_value?: string;
458
+ options?: readonly string[];
459
+ };
460
+ }) | ({
461
+ type: "Separator";
462
+ } & {
463
+ config?: {
464
+ label?: string | null | undefined;
465
+ };
466
+ }) | ({
467
+ type: "Text";
468
+ } & {
469
+ fieldset?: string | null | undefined;
470
+ config?: {
471
+ label?: string | null | undefined;
472
+ useAsTitle?: boolean;
473
+ placeholder?: string;
474
+ };
475
+ }) | ({
476
+ type: "Timestamp";
477
+ } & {
478
+ fieldset?: string | null | undefined;
479
+ config?: {
480
+ label?: string | null | undefined;
481
+ placeholder?: string;
482
+ default?: string;
483
+ };
484
+ }) | ({
485
+ type: "Group";
486
+ } & {
487
+ fieldset?: string | null | undefined;
488
+ icon?: string;
489
+ description?: string;
490
+ config?: {
491
+ label?: string | null | undefined;
492
+ repeat?: boolean;
493
+ fields?: {
494
+ [x: string]: ({
495
+ type: "Boolean";
496
+ } & {
497
+ config?: {
498
+ label?: string | null | undefined;
499
+ default_value?: boolean;
500
+ placeholder_true?: string;
501
+ placeholder_false?: string;
502
+ };
503
+ }) | ({
504
+ type: "Color";
505
+ } & {
506
+ fieldset?: string | null | undefined;
507
+ config?: {
508
+ label?: string | null | undefined;
509
+ placeholder?: string;
510
+ };
511
+ }) | ({
512
+ type: "Date";
513
+ } & {
514
+ fieldset?: string | null | undefined;
515
+ config?: {
516
+ label?: string | null | undefined;
517
+ placeholder?: string;
518
+ default?: string;
519
+ };
520
+ }) | ({
521
+ type: "Embed";
522
+ } & {
523
+ fieldset?: string | null | undefined;
524
+ config?: {
525
+ label?: string | null | undefined;
526
+ placeholder?: string;
527
+ useAsTitle?: boolean;
528
+ };
529
+ }) | ({
530
+ type: "GeoPoint";
531
+ } & {
532
+ fieldset?: string | null | undefined;
533
+ config?: {
534
+ label?: string | null | undefined;
535
+ };
536
+ }) | ({
537
+ type: "Image";
538
+ } & {
539
+ fieldset?: string | null | undefined;
540
+ config?: {
541
+ label?: string | null | undefined;
542
+ placeholder?: string;
543
+ constraint?: {
544
+ width?: number | null;
545
+ height?: number | null;
546
+ };
547
+ thumbnails?: readonly ({
548
+ name: string;
549
+ } & {
550
+ width?: number | null;
551
+ height?: number | null;
552
+ })[];
553
+ };
554
+ }) | ({
555
+ type: "IntegrationFields";
556
+ } & {
557
+ fieldset?: string | null | undefined;
558
+ config?: {
559
+ label?: string | null | undefined;
560
+ placeholder?: string;
561
+ catalog?: string;
562
+ };
563
+ }) | ({
564
+ type: "Link";
565
+ } & {
566
+ fieldset?: string | null | undefined;
567
+ config?: {
568
+ label?: string | null | undefined;
569
+ useAsTitle?: boolean;
570
+ placeholder?: string;
571
+ select?: "media" | "document" | "web" | null;
572
+ customtypes?: readonly string[];
573
+ masks?: readonly string[];
574
+ tags?: readonly string[];
575
+ allowTargetBlank?: boolean;
576
+ };
577
+ }) | ({
578
+ type: "Number";
579
+ } & {
580
+ fieldset?: string | null | undefined;
581
+ config?: {
582
+ label?: string | null | undefined;
583
+ placeholder?: string;
584
+ min?: number;
585
+ max?: number;
586
+ step?: number;
587
+ };
588
+ }) | ({
589
+ type: "Range";
590
+ } & {
591
+ fieldset?: string | null | undefined;
592
+ config?: {
593
+ label?: string | null | undefined;
594
+ placeholder?: string;
595
+ min?: number;
596
+ max?: number;
597
+ step?: number;
598
+ };
599
+ }) | ({
600
+ type: "StructuredText";
601
+ } & {
602
+ fieldset?: string | null | undefined;
603
+ config?: {
604
+ label?: string | null | undefined;
605
+ placeholder?: string;
606
+ useAsTitle?: boolean;
607
+ single?: string;
608
+ multi?: string;
609
+ imageConstraint?: {
610
+ width?: number | null;
611
+ height?: number | null;
612
+ };
613
+ labels?: readonly string[];
614
+ allowTargetBlank?: boolean;
615
+ };
616
+ }) | ({
617
+ type: "Select";
618
+ } & {
619
+ fieldset?: string | null | undefined;
620
+ config?: {
621
+ label?: string | null | undefined;
622
+ placeholder?: string;
623
+ default_value?: string;
624
+ options?: readonly string[];
625
+ };
626
+ }) | ({
627
+ type: "Separator";
628
+ } & {
629
+ config?: {
630
+ label?: string | null | undefined;
631
+ };
632
+ }) | ({
633
+ type: "Text";
634
+ } & {
635
+ fieldset?: string | null | undefined;
636
+ config?: {
637
+ label?: string | null | undefined;
638
+ useAsTitle?: boolean;
639
+ placeholder?: string;
640
+ };
641
+ }) | ({
642
+ type: "Timestamp";
643
+ } & {
644
+ fieldset?: string | null | undefined;
645
+ config?: {
646
+ label?: string | null | undefined;
647
+ placeholder?: string;
648
+ default?: string;
649
+ };
650
+ });
651
+ };
652
+ };
653
+ });
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlicePrimaryWidget = void 0;
3
+ exports.isSlicePrimaryWidget = exports.SlicePrimaryWidget = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
6
  const Group_1 = require("../Group");
7
7
  const nestable_1 = require("../nestable");
8
8
  exports.SlicePrimaryWidget = t.union([nestable_1.NestableWidget, Group_1.Group]);
9
+ const isSlicePrimaryWidget = (u) => nestable_1.NestableWidget.is(u) || Group_1.Group.is(u);
10
+ exports.isSlicePrimaryWidget = isSlicePrimaryWidget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.4.0-alpha.5",
3
+ "version": "2.4.0-alpha.7",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -32,7 +32,11 @@ import {
32
32
  } from "../../withDefaultValues"
33
33
  import type { SharedSliceItemContent } from "../SliceItem"
34
34
  import { RepeatableWidgets, RepeatableWidgetsLegacy } from "./RepeatableContent"
35
- import { SlicePrimaryContent, SlicePrimaryLegacy } from "./SlicePrimaryContent"
35
+ import {
36
+ isSlicePrimaryContent,
37
+ SlicePrimaryContent,
38
+ SlicePrimaryLegacy,
39
+ } from "./SlicePrimaryContent"
36
40
 
37
41
  export const SharedSliceContentType = "SharedSliceContent"
38
42
 
@@ -199,45 +203,42 @@ export function traverseSharedSliceContent({
199
203
  >((acc, [fieldKey, fieldContent]) => {
200
204
  const fieldDef = model?.fields?.primary?.[fieldKey]
201
205
 
202
- if (isGroupContent(fieldContent) && fieldDef?.type === GroupFieldType) {
203
- const transformedGroupField = traverseGroupContent({
204
- path: path.concat([
205
- { key: "primary", type: "primary" },
206
- { key: fieldKey, type: "Widget" },
207
- ]),
208
- key: fieldKey,
209
- apiId: sliceName,
210
- content: fieldContent,
211
- model: fieldDef,
212
- })(transformWidget)
213
-
214
- // Can happen if the transform function returns undefined to filter out a field
215
- if (!transformedGroupField) return acc
216
-
217
- return {
218
- ...acc,
219
- [fieldKey]: transformedGroupField,
206
+ const transformedField = (() => {
207
+ if (isGroupContent(fieldContent)) {
208
+ return traverseGroupContent({
209
+ path: path.concat([
210
+ { key: "primary", type: "primary" },
211
+ { key: fieldKey, type: "Widget" },
212
+ ]),
213
+ key: fieldKey,
214
+ apiId: fieldKey,
215
+ content: fieldContent,
216
+ model: fieldDef?.type === GroupFieldType ? fieldDef : undefined,
217
+ })(transformWidget)
218
+ } else if (isNestableContent(fieldContent)) {
219
+ return transformWidget({
220
+ path: path.concat([
221
+ { key: "primary", type: "primary" },
222
+ { key: fieldKey, type: "Widget" },
223
+ ]),
224
+ key: fieldKey,
225
+ apiId: fieldKey,
226
+ model: fieldDef,
227
+ content: fieldContent,
228
+ })
229
+ } else {
230
+ return undefined
220
231
  }
221
- }
232
+ })()
222
233
 
223
- const transformedField = transformWidget({
224
- path: path.concat([
225
- { key: "primary", type: "primary" },
226
- { key: fieldKey, type: "Widget" },
227
- ]),
228
- key: fieldKey,
229
- apiId: sliceName,
230
- model: fieldDef,
231
- content: fieldContent,
232
- })
233
234
  // Can happen if the transform function returns undefined to filter out a field
234
235
  if (!transformedField) return acc
235
- if (!isNestableContent(transformedField)) {
236
+ if (!isSlicePrimaryContent(transformedField)) {
236
237
  console.warn(
237
- `Warn: Non nestable content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`,
238
+ `Warn: Non nestable or group content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`,
238
239
  )
239
- return acc
240
240
  }
241
+
241
242
  return {
242
243
  ...acc,
243
244
  [fieldKey]: transformedField,
@@ -7,3 +7,6 @@ export const SlicePrimaryWidget = t.union([NestableWidget, Group])
7
7
 
8
8
  export type SlicePrimaryWidget = t.TypeOf<typeof SlicePrimaryWidget>
9
9
  export type SlicePrimaryFieldTypes = SlicePrimaryWidget["type"]
10
+
11
+ export const isSlicePrimaryWidget = (u: unknown): u is SlicePrimaryWidget =>
12
+ NestableWidget.is(u) || Group.is(u)