@prismicio/types-internal 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +110 -0
  3. package/dist/customtypes/index.cjs +864 -0
  4. package/dist/customtypes/index.cjs.map +1 -0
  5. package/dist/customtypes/index.d.ts +18433 -0
  6. package/dist/customtypes/index.d.ts.map +1 -0
  7. package/dist/customtypes/index.js +864 -0
  8. package/dist/customtypes/index.js.map +1 -0
  9. package/dist/customtypes/widgets/index.cjs +735 -0
  10. package/dist/customtypes/widgets/index.cjs.map +1 -0
  11. package/dist/customtypes/widgets/index.d.ts +11697 -0
  12. package/dist/customtypes/widgets/index.d.ts.map +1 -0
  13. package/dist/customtypes/widgets/index.js +735 -0
  14. package/dist/customtypes/widgets/index.js.map +1 -0
  15. package/dist/customtypes/widgets/slices/index.cjs +671 -0
  16. package/dist/customtypes/widgets/slices/index.cjs.map +1 -0
  17. package/dist/customtypes/widgets/slices/index.d.ts +7079 -0
  18. package/dist/customtypes/widgets/slices/index.d.ts.map +1 -0
  19. package/dist/customtypes/widgets/slices/index.js +671 -0
  20. package/dist/customtypes/widgets/slices/index.js.map +1 -0
  21. package/dist/index.cjs +870 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +18455 -0
  24. package/dist/index.js +844 -0
  25. package/dist/index.js.map +1 -0
  26. package/package.json +84 -0
  27. package/src/customtypes/CustomType.ts +142 -0
  28. package/src/customtypes/Format.ts +4 -0
  29. package/src/customtypes/Section.ts +25 -0
  30. package/src/customtypes/index.ts +4 -0
  31. package/src/customtypes/widgets/Group.ts +30 -0
  32. package/src/customtypes/widgets/UID.ts +27 -0
  33. package/src/customtypes/widgets/Widget.ts +33 -0
  34. package/src/customtypes/widgets/WidgetTypes.ts +24 -0
  35. package/src/customtypes/widgets/index.ts +7 -0
  36. package/src/customtypes/widgets/nestable/BooleanField.ts +30 -0
  37. package/src/customtypes/widgets/nestable/Color.ts +26 -0
  38. package/src/customtypes/widgets/nestable/Date.ts +27 -0
  39. package/src/customtypes/widgets/nestable/Embed.ts +27 -0
  40. package/src/customtypes/widgets/nestable/GeoPoint.ts +25 -0
  41. package/src/customtypes/widgets/nestable/Image.ts +40 -0
  42. package/src/customtypes/widgets/nestable/IntegrationField.ts +27 -0
  43. package/src/customtypes/widgets/nestable/Link.ts +85 -0
  44. package/src/customtypes/widgets/nestable/NestableWidget.ts +39 -0
  45. package/src/customtypes/widgets/nestable/Number.ts +30 -0
  46. package/src/customtypes/widgets/nestable/Range.ts +30 -0
  47. package/src/customtypes/widgets/nestable/RichText.ts +160 -0
  48. package/src/customtypes/widgets/nestable/Select.ts +32 -0
  49. package/src/customtypes/widgets/nestable/Separator.ts +24 -0
  50. package/src/customtypes/widgets/nestable/Text.ts +27 -0
  51. package/src/customtypes/widgets/nestable/Timestamp.ts +27 -0
  52. package/src/customtypes/widgets/nestable/index.ts +15 -0
  53. package/src/customtypes/widgets/shared/ImageConstraint.ts +39 -0
  54. package/src/customtypes/widgets/shared/index.ts +1 -0
  55. package/src/customtypes/widgets/slices/CompositeSlice.ts +32 -0
  56. package/src/customtypes/widgets/slices/LegacySlice.ts +15 -0
  57. package/src/customtypes/widgets/slices/SharedSlice.ts +44 -0
  58. package/src/customtypes/widgets/slices/SharedSliceRef.ts +12 -0
  59. package/src/customtypes/widgets/slices/Slice.ts +7 -0
  60. package/src/customtypes/widgets/slices/Slices.ts +100 -0
  61. package/src/customtypes/widgets/slices/SlicesTypes.ts +6 -0
  62. package/src/customtypes/widgets/slices/index.ts +7 -0
  63. package/src/index.ts +1 -0
  64. package/src/validators/IntFromNumber.ts +24 -0
  65. package/src/validators/IntFromPixels.ts +31 -0
  66. package/src/validators/StringFromBoolean.ts +21 -0
  67. package/src/validators/StringFromNumber.ts +21 -0
  68. package/src/validators/StringOrNull.ts +3 -0
@@ -0,0 +1,864 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const t = require('io-ts');
6
+ const NumberFromString = require('io-ts-types/lib/NumberFromString');
7
+ const Either = require('fp-ts/lib/Either');
8
+ const IntFromString = require('io-ts-types/lib/IntFromString');
9
+ const pipeable = require('fp-ts/lib/pipeable');
10
+ const withFallback = require('io-ts-types/lib/withFallback');
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () {
22
+ return e[k];
23
+ }
24
+ });
25
+ }
26
+ });
27
+ }
28
+ n['default'] = e;
29
+ return Object.freeze(n);
30
+ }
31
+
32
+ const t__namespace = /*#__PURE__*/_interopNamespace(t);
33
+
34
+ exports.Format = void 0;
35
+ (function(Format2) {
36
+ Format2["Static"] = "static";
37
+ Format2["Dynamic"] = "dynamic";
38
+ })(exports.Format || (exports.Format = {}));
39
+
40
+ const StringOrNull = t__namespace.union([t__namespace.string, t__namespace.null, t__namespace.undefined]);
41
+
42
+ var WidgetTypes;
43
+ (function(WidgetTypes2) {
44
+ WidgetTypes2["Text"] = "Text";
45
+ WidgetTypes2["RichText"] = "StructuredText";
46
+ WidgetTypes2["Color"] = "Color";
47
+ WidgetTypes2["Image"] = "Image";
48
+ WidgetTypes2["Date"] = "Date";
49
+ WidgetTypes2["Timestamp"] = "Timestamp";
50
+ WidgetTypes2["Number"] = "Number";
51
+ WidgetTypes2["Range"] = "Range";
52
+ WidgetTypes2["Select"] = "Select";
53
+ WidgetTypes2["Link"] = "Link";
54
+ WidgetTypes2["Embed"] = "Embed";
55
+ WidgetTypes2["GeoPoint"] = "GeoPoint";
56
+ WidgetTypes2["Separator"] = "Separator";
57
+ WidgetTypes2["UID"] = "UID";
58
+ WidgetTypes2["BooleanField"] = "Boolean";
59
+ WidgetTypes2["IntegrationField"] = "IntegrationFields";
60
+ WidgetTypes2["Group"] = "Group";
61
+ WidgetTypes2["Slices"] = "Slices";
62
+ WidgetTypes2["LegacySlices"] = "Choice";
63
+ })(WidgetTypes || (WidgetTypes = {}));
64
+ const WidgetTypes$1 = WidgetTypes;
65
+
66
+ const UIDConfig = t__namespace.exact(t__namespace.partial({
67
+ label: StringOrNull,
68
+ useAsTitle: t__namespace.boolean,
69
+ placeholder: t__namespace.string
70
+ }));
71
+ const UID = t__namespace.exact(t__namespace.intersection([
72
+ t__namespace.type({
73
+ type: t__namespace.literal(WidgetTypes$1.UID)
74
+ }),
75
+ t__namespace.partial({
76
+ fieldset: StringOrNull,
77
+ config: UIDConfig
78
+ })
79
+ ]));
80
+
81
+ const ColorConfig = t__namespace.exact(t__namespace.partial({
82
+ label: StringOrNull,
83
+ placeholder: t__namespace.string
84
+ }));
85
+ const Color = t__namespace.exact(t__namespace.intersection([
86
+ t__namespace.type({
87
+ type: t__namespace.literal(WidgetTypes$1.Color)
88
+ }),
89
+ t__namespace.partial({
90
+ fieldset: StringOrNull,
91
+ config: ColorConfig
92
+ })
93
+ ]));
94
+
95
+ const BooleanConfig = t__namespace.exact(t__namespace.partial({
96
+ label: StringOrNull,
97
+ default_value: t__namespace.boolean,
98
+ placeholder_true: t__namespace.string,
99
+ placeholder_false: t__namespace.string
100
+ }));
101
+ const BooleanField = t__namespace.exact(t__namespace.intersection([
102
+ t__namespace.type({
103
+ type: t__namespace.literal(WidgetTypes$1.BooleanField)
104
+ }),
105
+ t__namespace.partial({
106
+ config: BooleanConfig
107
+ })
108
+ ]));
109
+
110
+ const DateConfig = t__namespace.exact(t__namespace.partial({
111
+ label: StringOrNull,
112
+ placeholder: t__namespace.string,
113
+ default: t__namespace.string
114
+ }));
115
+ const Date = t__namespace.exact(t__namespace.intersection([
116
+ t__namespace.type({
117
+ type: t__namespace.literal(WidgetTypes$1.Date)
118
+ }),
119
+ t__namespace.partial({
120
+ fieldset: StringOrNull,
121
+ config: DateConfig
122
+ })
123
+ ]));
124
+
125
+ const EmbedConfig = t__namespace.exact(t__namespace.partial({
126
+ label: StringOrNull,
127
+ placeholder: t__namespace.string,
128
+ useAsTitle: t__namespace.boolean
129
+ }));
130
+ const Embed = t__namespace.exact(t__namespace.intersection([
131
+ t__namespace.type({
132
+ type: t__namespace.literal(WidgetTypes$1.Embed)
133
+ }),
134
+ t__namespace.partial({
135
+ fieldset: StringOrNull,
136
+ config: EmbedConfig
137
+ })
138
+ ]));
139
+
140
+ const GeoPointConfig = t__namespace.exact(t__namespace.partial({
141
+ label: StringOrNull
142
+ }));
143
+ const GeoPoint = t__namespace.exact(t__namespace.intersection([
144
+ t__namespace.type({
145
+ type: t__namespace.literal(WidgetTypes$1.GeoPoint)
146
+ }),
147
+ t__namespace.partial({
148
+ fieldset: StringOrNull,
149
+ config: GeoPointConfig
150
+ })
151
+ ]));
152
+
153
+ const NumberConfig = t__namespace.exact(t__namespace.partial({
154
+ label: StringOrNull,
155
+ placeholder: t__namespace.string,
156
+ min: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
157
+ max: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
158
+ step: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString])
159
+ }));
160
+ const Number = t__namespace.exact(t__namespace.intersection([
161
+ t__namespace.type({
162
+ type: t__namespace.literal(WidgetTypes$1.Number)
163
+ }),
164
+ t__namespace.partial({
165
+ fieldset: StringOrNull,
166
+ config: NumberConfig
167
+ })
168
+ ]));
169
+
170
+ const RangeConfig = t__namespace.exact(t__namespace.partial({
171
+ label: StringOrNull,
172
+ placeholder: t__namespace.string,
173
+ min: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
174
+ max: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
175
+ step: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString])
176
+ }));
177
+ const Range = t__namespace.exact(t__namespace.intersection([
178
+ t__namespace.type({
179
+ type: t__namespace.literal(WidgetTypes$1.Range)
180
+ }),
181
+ t__namespace.partial({
182
+ fieldset: StringOrNull,
183
+ config: RangeConfig
184
+ })
185
+ ]));
186
+
187
+ const IntFromNumber = new t__namespace.Type("IntFromNumber", t__namespace.Int.is, (u, c) => pipeable.pipe(t__namespace.number.validate(u, c), Either.chain((n) => {
188
+ if (t__namespace.Int.is(n))
189
+ return t__namespace.success(n);
190
+ else {
191
+ return t__namespace.success(Math.round(n));
192
+ }
193
+ })), t__namespace.Int.encode);
194
+
195
+ const PixelsRegex = /^([0-9]+)px$/;
196
+ const IntFromPixels = new t__namespace.Type("IntFromPixels", t__namespace.Int.is, (u, c) => pipeable.pipe(t__namespace.string.validate(u, c), Either.chain((strPixels) => {
197
+ try {
198
+ const matched = strPixels.match(PixelsRegex);
199
+ if (!matched)
200
+ return t__namespace.failure(u, c);
201
+ else {
202
+ const parsed = parseInt(matched[1]);
203
+ return t__namespace.success(parsed);
204
+ }
205
+ } catch (e) {
206
+ return t__namespace.failure(u, c);
207
+ }
208
+ })), String);
209
+
210
+ const SideConstraint = new t__namespace.Type("SideConstraints", (u) => {
211
+ return !u || typeof u === "number";
212
+ }, (u, context) => {
213
+ return Either.either.chain(t__namespace.union([
214
+ t__namespace.literal("auto"),
215
+ t__namespace.literal(""),
216
+ t__namespace.Int,
217
+ IntFromString.IntFromString,
218
+ IntFromNumber,
219
+ IntFromPixels,
220
+ t__namespace.null
221
+ ]).validate(u, context), (constraint) => {
222
+ if (constraint === "auto" || constraint === "")
223
+ return t__namespace.success(null);
224
+ return t__namespace.success(constraint);
225
+ });
226
+ }, (res) => res);
227
+ const ImageConstraint = t__namespace.partial({
228
+ width: SideConstraint,
229
+ height: SideConstraint
230
+ });
231
+
232
+ const DEFAULT_OPTION = "paragraph";
233
+ const options = [
234
+ "heading1",
235
+ "heading2",
236
+ "heading3",
237
+ "heading4",
238
+ "heading5",
239
+ "heading6",
240
+ "paragraph",
241
+ "strong",
242
+ "em",
243
+ "preformatted",
244
+ "hyperlink",
245
+ "image",
246
+ "embed",
247
+ "list-item",
248
+ "o-list-item",
249
+ "rtl"
250
+ ];
251
+ const RichTextOptions = new t__namespace.Type("RichTextOptions", (u) => typeof u === "string", (u, context) => {
252
+ return Either.either.chain(t__namespace.union([
253
+ t__namespace.string,
254
+ t__namespace.null
255
+ ]).validate(u, context), (s) => {
256
+ if (!s)
257
+ return t__namespace.success(DEFAULT_OPTION);
258
+ const entries = s.split(",").map((e) => e.trim());
259
+ const filtered = entries.filter((entry) => options.includes(entry));
260
+ if (!filtered.length)
261
+ return t__namespace.success(DEFAULT_OPTION);
262
+ return t__namespace.success(filtered.join(","));
263
+ });
264
+ }, (a) => a);
265
+ const NoLabels = (labels) => {
266
+ if (!labels)
267
+ return t__namespace.success([]);
268
+ };
269
+ const LabelsAsObject = (labels) => {
270
+ if (labels instanceof Object) {
271
+ const labelsObj = labels;
272
+ if (!Object.entries(labelsObj).length)
273
+ return t__namespace.success([]);
274
+ if (labelsObj[""]) {
275
+ return t__namespace.success(labelsObj[""].map((l) => l.name));
276
+ }
277
+ const convertedObjectToArray = Object.entries(labelsObj).reduce((acc, [, labelsEntries]) => {
278
+ return acc.concat(labelsEntries.map((l) => l.name));
279
+ }, []).filter(Boolean);
280
+ return t__namespace.success(convertedObjectToArray);
281
+ }
282
+ };
283
+ const LabelsAsArray = (labels) => {
284
+ if (labels instanceof Array) {
285
+ const isValidLabels = labels.reduce((acc, l) => acc && typeof l === "string", true);
286
+ if (isValidLabels)
287
+ return t__namespace.success(labels);
288
+ }
289
+ };
290
+ const LabelsAsString = (labels) => {
291
+ if (typeof labels === "string") {
292
+ return t__namespace.success([labels]);
293
+ }
294
+ };
295
+ const RichTextLabels = new t__namespace.Type("RichTextLabels", (u) => {
296
+ return u instanceof Array;
297
+ }, (u, context) => {
298
+ const legacyValidator = t__namespace.record(t__namespace.string, t__namespace.array(t__namespace.record(t__namespace.literal("name"), t__namespace.string)));
299
+ const validator = t__namespace.array(t__namespace.string);
300
+ return Either.either.chain(t__namespace.union([
301
+ legacyValidator,
302
+ validator,
303
+ t__namespace.string,
304
+ t__namespace.null
305
+ ]).validate(u, context), (labels) => {
306
+ return NoLabels(labels) || LabelsAsArray(labels) || LabelsAsObject(labels) || LabelsAsString(labels) || t__namespace.failure(u, context);
307
+ });
308
+ }, (res) => res);
309
+ const RichTextConfig = t__namespace.exact(t__namespace.partial({
310
+ label: StringOrNull,
311
+ placeholder: t__namespace.string,
312
+ useAsTitle: t__namespace.boolean,
313
+ single: RichTextOptions,
314
+ multi: RichTextOptions,
315
+ imageConstraint: ImageConstraint,
316
+ labels: RichTextLabels,
317
+ allowTargetBlank: t__namespace.boolean
318
+ }));
319
+ const RichText = t__namespace.exact(t__namespace.intersection([
320
+ t__namespace.type({
321
+ type: t__namespace.literal(WidgetTypes$1.RichText)
322
+ }),
323
+ t__namespace.partial({
324
+ fieldset: StringOrNull,
325
+ config: RichTextConfig
326
+ })
327
+ ]));
328
+
329
+ const StringFromBoolean = new t__namespace.Type("StringFromInt", t__namespace.string.is, (u, c) => pipeable.pipe(t__namespace.boolean.validate(u, c), Either.chain((i) => {
330
+ return t__namespace.success(i.toString());
331
+ })), (i) => i);
332
+
333
+ const StringFromNumber = new t__namespace.Type("StringFromInt", t__namespace.string.is, (u, c) => pipeable.pipe(t__namespace.number.validate(u, c), Either.chain((i) => {
334
+ return t__namespace.success(i.toString());
335
+ })), (i) => i);
336
+
337
+ const SelectConfig = t__namespace.exact(t__namespace.partial({
338
+ label: StringOrNull,
339
+ placeholder: t__namespace.string,
340
+ default_value: t__namespace.string,
341
+ options: t__namespace.array(t__namespace.union([t__namespace.string, StringFromNumber, StringFromBoolean]))
342
+ }));
343
+ const Select = t__namespace.exact(t__namespace.intersection([
344
+ t__namespace.type({
345
+ type: t__namespace.literal(WidgetTypes$1.Select)
346
+ }),
347
+ t__namespace.partial({
348
+ fieldset: StringOrNull,
349
+ config: SelectConfig
350
+ })
351
+ ]));
352
+
353
+ const SeparatorConfig = t__namespace.exact(t__namespace.partial({
354
+ label: StringOrNull
355
+ }));
356
+ const Separator = t__namespace.exact(t__namespace.intersection([
357
+ t__namespace.type({
358
+ type: t__namespace.literal(WidgetTypes$1.Separator)
359
+ }),
360
+ t__namespace.partial({
361
+ config: SeparatorConfig
362
+ })
363
+ ]));
364
+
365
+ const TextConfig = t__namespace.exact(t__namespace.partial({
366
+ label: StringOrNull,
367
+ useAsTitle: t__namespace.boolean,
368
+ placeholder: t__namespace.string
369
+ }));
370
+ const Text = t__namespace.exact(t__namespace.intersection([
371
+ t__namespace.type({
372
+ type: t__namespace.literal(WidgetTypes$1.Text)
373
+ }),
374
+ t__namespace.partial({
375
+ fieldset: StringOrNull,
376
+ config: TextConfig
377
+ })
378
+ ]));
379
+
380
+ const TimestampConfig = t__namespace.exact(t__namespace.partial({
381
+ label: StringOrNull,
382
+ placeholder: t__namespace.string,
383
+ default: t__namespace.string
384
+ }));
385
+ const Timestamp = t__namespace.exact(t__namespace.intersection([
386
+ t__namespace.type({
387
+ type: t__namespace.literal(WidgetTypes$1.Timestamp)
388
+ }),
389
+ t__namespace.partial({
390
+ fieldset: StringOrNull,
391
+ config: TimestampConfig
392
+ })
393
+ ]));
394
+
395
+ const arrayString = (entries) => {
396
+ if (entries instanceof Array) {
397
+ const isValidEntries = entries.reduce((acc, l) => acc && typeof l === "string", true);
398
+ if (isValidEntries)
399
+ return t__namespace.success(entries);
400
+ }
401
+ };
402
+ const plainString = (entries) => {
403
+ if (typeof entries === "string") {
404
+ return t__namespace.success([entries]);
405
+ }
406
+ };
407
+ const MasksArrayString = new t__namespace.Type("MasksArrayString", (u) => {
408
+ return u instanceof Array;
409
+ }, (u, context) => {
410
+ return Either.either.chain(t__namespace.union([
411
+ t__namespace.array(t__namespace.string),
412
+ t__namespace.string
413
+ ]).validate(u, context), (masks) => {
414
+ return arrayString(masks) || plainString(masks) || t__namespace.failure(u, context);
415
+ });
416
+ }, (res) => res);
417
+ const LinkConfig = t__namespace.exact(t__namespace.partial({
418
+ label: StringOrNull,
419
+ useAsTitle: t__namespace.boolean,
420
+ placeholder: t__namespace.string,
421
+ select: withFallback.withFallback(t__namespace.union([
422
+ t__namespace.literal("media"),
423
+ t__namespace.literal("document"),
424
+ t__namespace.literal("web"),
425
+ t__namespace.null
426
+ ]), null),
427
+ customtypes: t__namespace.array(t__namespace.string),
428
+ masks: MasksArrayString,
429
+ tags: MasksArrayString,
430
+ allowTargetBlank: t__namespace.boolean
431
+ }));
432
+ const Link = t__namespace.exact(t__namespace.intersection([
433
+ t__namespace.type({
434
+ type: t__namespace.literal(WidgetTypes$1.Link)
435
+ }),
436
+ t__namespace.partial({
437
+ fieldset: StringOrNull,
438
+ config: LinkConfig
439
+ })
440
+ ]));
441
+
442
+ const Thumbnail = t__namespace.exact(t__namespace.intersection([
443
+ t__namespace.type({
444
+ name: t__namespace.string
445
+ }),
446
+ ImageConstraint
447
+ ]));
448
+ const ImageConfig = t__namespace.exact(t__namespace.partial({
449
+ label: StringOrNull,
450
+ placeholder: t__namespace.string,
451
+ constraint: ImageConstraint,
452
+ thumbnails: t__namespace.array(Thumbnail)
453
+ }));
454
+ const Image = t__namespace.exact(t__namespace.intersection([
455
+ t__namespace.type({
456
+ type: t__namespace.literal(WidgetTypes$1.Image)
457
+ }),
458
+ t__namespace.partial({
459
+ fieldset: StringOrNull,
460
+ config: ImageConfig
461
+ })
462
+ ]));
463
+
464
+ const IntegrationFieldConfig = t__namespace.exact(t__namespace.partial({
465
+ label: StringOrNull,
466
+ placeholder: t__namespace.string,
467
+ catalog: t__namespace.string
468
+ }));
469
+ const IntegrationField = t__namespace.exact(t__namespace.intersection([
470
+ t__namespace.type({
471
+ type: t__namespace.literal(WidgetTypes$1.IntegrationField)
472
+ }),
473
+ t__namespace.partial({
474
+ fieldset: StringOrNull,
475
+ config: IntegrationFieldConfig
476
+ })
477
+ ]));
478
+
479
+ const NestableWidget = t__namespace.union([
480
+ Color,
481
+ BooleanField,
482
+ Embed,
483
+ GeoPoint,
484
+ Date,
485
+ Number,
486
+ Range,
487
+ RichText,
488
+ Select,
489
+ Separator,
490
+ Text,
491
+ Timestamp,
492
+ Link,
493
+ Image,
494
+ IntegrationField
495
+ ]);
496
+
497
+ const GroupConfig = t__namespace.exact(t__namespace.partial({
498
+ label: StringOrNull,
499
+ repeat: t__namespace.boolean,
500
+ fields: t__namespace.record(t__namespace.string, NestableWidget)
501
+ }));
502
+ const Group = t__namespace.exact(t__namespace.intersection([
503
+ t__namespace.type({
504
+ type: t__namespace.literal(WidgetTypes$1.Group)
505
+ }),
506
+ t__namespace.partial({
507
+ fieldset: StringOrNull,
508
+ icon: t__namespace.string,
509
+ description: t__namespace.string,
510
+ config: GroupConfig
511
+ })
512
+ ]));
513
+
514
+ const LegacySlice = t__namespace.union([
515
+ UID,
516
+ NestableWidget,
517
+ Group
518
+ ]);
519
+
520
+ var SlicesTypes;
521
+ (function(SlicesTypes2) {
522
+ SlicesTypes2["Slice"] = "Slice";
523
+ SlicesTypes2["SharedSlice"] = "SharedSlice";
524
+ })(SlicesTypes || (SlicesTypes = {}));
525
+ const SlicesTypes$1 = SlicesTypes;
526
+
527
+ const CompositeSliceConfig = t__namespace.exact(t__namespace.partial({
528
+ label: StringOrNull
529
+ }));
530
+ const CompositeSlice = t__namespace.exact(t__namespace.intersection([
531
+ t__namespace.type({
532
+ type: t__namespace.literal(SlicesTypes$1.Slice)
533
+ }),
534
+ t__namespace.partial({
535
+ fieldset: StringOrNull,
536
+ description: t__namespace.string,
537
+ icon: t__namespace.string,
538
+ display: t__namespace.string,
539
+ "non-repeat": t__namespace.record(t__namespace.string, NestableWidget),
540
+ repeat: t__namespace.record(t__namespace.string, NestableWidget),
541
+ config: CompositeSliceConfig
542
+ })
543
+ ]));
544
+
545
+ const SharedSliceRef = t__namespace.exact(t__namespace.type({
546
+ type: t__namespace.literal(SlicesTypes$1.SharedSlice)
547
+ }));
548
+
549
+ const IMAGE_PLACEHOLDER_URL = "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format";
550
+ const Variation = t__namespace.exact(t__namespace.intersection([
551
+ t__namespace.type({
552
+ id: t__namespace.string,
553
+ name: t__namespace.string,
554
+ description: t__namespace.string,
555
+ imageUrl: withFallback.withFallback(t__namespace.string, IMAGE_PLACEHOLDER_URL),
556
+ docURL: t__namespace.string,
557
+ version: t__namespace.string
558
+ }),
559
+ t__namespace.partial({
560
+ display: t__namespace.string,
561
+ primary: t__namespace.record(t__namespace.string, NestableWidget),
562
+ items: t__namespace.record(t__namespace.string, NestableWidget)
563
+ })
564
+ ]));
565
+ const SharedSlice = t__namespace.exact(t__namespace.intersection([
566
+ t__namespace.type({
567
+ id: t__namespace.string,
568
+ type: t__namespace.literal(SlicesTypes$1.SharedSlice),
569
+ name: t__namespace.string,
570
+ variations: t__namespace.array(Variation)
571
+ }),
572
+ t__namespace.partial({
573
+ description: t__namespace.string
574
+ })
575
+ ]));
576
+
577
+ const SlicesLabels = t__namespace.union([
578
+ t__namespace.record(t__namespace.string, t__namespace.array(t__namespace.exact(t__namespace.intersection([
579
+ t__namespace.type({
580
+ name: t__namespace.string
581
+ }),
582
+ t__namespace.partial({
583
+ display: t__namespace.string
584
+ })
585
+ ])))),
586
+ t__namespace.null
587
+ ]);
588
+ function slicesConfigReader(format) {
589
+ return t__namespace.exact(t__namespace.partial({
590
+ label: StringOrNull,
591
+ labels: SlicesLabels,
592
+ choices: t__namespace.record(t__namespace.string, t__namespace.union([
593
+ LegacySlice,
594
+ CompositeSlice,
595
+ (() => {
596
+ switch (format) {
597
+ case exports.Format.Static:
598
+ return SharedSlice;
599
+ case exports.Format.Dynamic:
600
+ return SharedSliceRef;
601
+ default:
602
+ throw new Error(`Invalid Format Exception: ${format} doesn't exist`);
603
+ }
604
+ })()
605
+ ]))
606
+ }));
607
+ }
608
+ const StaticSlicesConfig = slicesConfigReader(exports.Format.Static);
609
+ const DynamicSlicesConfig = slicesConfigReader(exports.Format.Dynamic);
610
+ const SlicesConfig = {
611
+ toStatic(config, sharedSlices) {
612
+ const choices = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
613
+ if (slice.type === SlicesTypes$1.SharedSlice) {
614
+ const sharedSlice = sharedSlices.get(ref);
615
+ if (sharedSlice)
616
+ return { ...acc, [ref]: sharedSlice };
617
+ else
618
+ return acc;
619
+ } else {
620
+ return { ...acc, [ref]: slice };
621
+ }
622
+ }, {});
623
+ return { ...config, choices };
624
+ }
625
+ };
626
+ function slicesReader(format) {
627
+ return t__namespace.exact(t__namespace.intersection([
628
+ t__namespace.type({
629
+ type: t__namespace.union([t__namespace.literal(WidgetTypes$1.Slices), t__namespace.literal(WidgetTypes$1.LegacySlices)])
630
+ }),
631
+ t__namespace.partial({
632
+ fieldset: StringOrNull,
633
+ config: slicesConfigReader(format)
634
+ })
635
+ ]));
636
+ }
637
+ const StaticSlices = slicesReader(exports.Format.Static);
638
+ const DynamicSlices = slicesReader(exports.Format.Dynamic);
639
+ const Slices = {
640
+ toStatic(slices, sharedSlices) {
641
+ if (!slices.config)
642
+ return slices;
643
+ else {
644
+ return { ...slices, config: SlicesConfig.toStatic(slices.config, sharedSlices) };
645
+ }
646
+ }
647
+ };
648
+
649
+ const Slices$1 = /*#__PURE__*/Object.freeze({
650
+ __proto__: null,
651
+ slicesConfigReader: slicesConfigReader,
652
+ StaticSlicesConfig: StaticSlicesConfig,
653
+ DynamicSlicesConfig: DynamicSlicesConfig,
654
+ slicesReader: slicesReader,
655
+ StaticSlices: StaticSlices,
656
+ DynamicSlices: DynamicSlices,
657
+ Slices: Slices
658
+ });
659
+
660
+ function widgetReader(format) {
661
+ return t__namespace.union([
662
+ UID,
663
+ NestableWidget,
664
+ Group,
665
+ slicesReader(format)
666
+ ]);
667
+ }
668
+ const StaticWidget = widgetReader(exports.Format.Static);
669
+ const DynamicWidget = widgetReader(exports.Format.Dynamic);
670
+ const Widgets = {
671
+ toStatic(widget, sharedSlices) {
672
+ switch (widget.type) {
673
+ case WidgetTypes$1.Slices:
674
+ return Slices.toStatic(widget, sharedSlices);
675
+ default:
676
+ return widget;
677
+ }
678
+ }
679
+ };
680
+
681
+ const Widget = /*#__PURE__*/Object.freeze({
682
+ __proto__: null,
683
+ widgetReader: widgetReader,
684
+ StaticWidget: StaticWidget,
685
+ DynamicWidget: DynamicWidget,
686
+ Widgets: Widgets
687
+ });
688
+
689
+ function sectionReader(format) {
690
+ return t__namespace.record(t__namespace.string, widgetReader(format));
691
+ }
692
+ const StaticSection = sectionReader(exports.Format.Static);
693
+ const DynamicSection = sectionReader(exports.Format.Dynamic);
694
+ const Sections = {
695
+ toStatic(dynamic, sharedSlices) {
696
+ const section = Object.entries(dynamic).reduce((acc, [widgetKey, widget]) => {
697
+ return { ...acc, [widgetKey]: Widgets.toStatic(widget, sharedSlices) };
698
+ }, {});
699
+ return section;
700
+ }
701
+ };
702
+
703
+ const Section = /*#__PURE__*/Object.freeze({
704
+ __proto__: null,
705
+ sectionReader: sectionReader,
706
+ StaticSection: StaticSection,
707
+ DynamicSection: DynamicSection,
708
+ Sections: Sections
709
+ });
710
+
711
+ const index$3 = /*#__PURE__*/Object.freeze({
712
+ __proto__: null,
713
+ BooleanField: BooleanField,
714
+ Color: Color,
715
+ Date: Date,
716
+ GeoPoint: GeoPoint,
717
+ Image: Image,
718
+ IntegrationField: IntegrationField,
719
+ Link: Link,
720
+ NestableWidget: NestableWidget,
721
+ Number: Number,
722
+ Range: Range,
723
+ RichText: RichText,
724
+ Select: Select,
725
+ Separator: Separator,
726
+ Text: Text,
727
+ Timestamp: Timestamp
728
+ });
729
+
730
+ const index$2 = /*#__PURE__*/Object.freeze({
731
+ __proto__: null,
732
+ ImageConstraint: ImageConstraint
733
+ });
734
+
735
+ const Slice = /*#__PURE__*/Object.freeze({
736
+ __proto__: null
737
+ });
738
+
739
+ const index$1 = /*#__PURE__*/Object.freeze({
740
+ __proto__: null,
741
+ Slice: Slice,
742
+ SliceZone: Slices$1,
743
+ CompositeSlice: CompositeSlice,
744
+ LegacySlice: LegacySlice,
745
+ SharedSlice: SharedSlice,
746
+ SharedSliceRef: SharedSliceRef,
747
+ SlicesTypes: SlicesTypes$1
748
+ });
749
+
750
+ const index = /*#__PURE__*/Object.freeze({
751
+ __proto__: null,
752
+ Nestable: index$3,
753
+ Shared: index$2,
754
+ Slices: index$1,
755
+ Widget: Widget,
756
+ Group: Group,
757
+ UID: UID,
758
+ WidgetTypes: WidgetTypes$1
759
+ });
760
+
761
+ class CustomTypeSlicesError extends Error {
762
+ constructor(slices) {
763
+ super();
764
+ this.slices = slices;
765
+ this.message = this._formatError(slices);
766
+ }
767
+ _formatError(slicesRefs) {
768
+ const slicesMsg = slicesRefs.map((ref) => ` - ${ref}`);
769
+ return `The following slices doesn't exists in your Prismic repository:
770
+ ${slicesMsg.join("\n")}
771
+ `;
772
+ }
773
+ }
774
+ function customTypeReader(format) {
775
+ return t__namespace.exact(t__namespace.intersection([
776
+ t__namespace.type({
777
+ id: t__namespace.string,
778
+ label: StringOrNull,
779
+ repeatable: withFallback.withFallback(t__namespace.boolean, true),
780
+ json: t__namespace.record(t__namespace.string, sectionReader(format)),
781
+ status: withFallback.withFallback(t__namespace.boolean, true)
782
+ }),
783
+ t__namespace.partial({
784
+ hash: t__namespace.string
785
+ })
786
+ ]));
787
+ }
788
+ const StaticCustomType = customTypeReader(exports.Format.Static);
789
+ const CustomType = customTypeReader(exports.Format.Dynamic);
790
+ function _retrieveSharedSlicesRef(customType) {
791
+ const flattenWidgets = Object.entries(customType.json).reduce((acc, [, section]) => {
792
+ const sectionWidgets = Object.entries(section);
793
+ return acc.concat(sectionWidgets);
794
+ }, []);
795
+ const slicezones = flattenWidgets.filter(([, widget]) => widget.type === WidgetTypes$1.Slices);
796
+ const allSharedRefs = slicezones.reduce((acc, [, slicezone]) => {
797
+ const sharedRefs = Object.entries(slicezone.config && slicezone.config.choices ? slicezone.config.choices : {}).filter(([, slice]) => slice.type === SlicesTypes$1.SharedSlice).map(([key]) => key);
798
+ return acc.concat(sharedRefs);
799
+ }, []);
800
+ return allSharedRefs;
801
+ }
802
+ function _mapSharedSlicesRefs(customType) {
803
+ const refs = _retrieveSharedSlicesRef(customType);
804
+ return function(mapFn) {
805
+ return refs.map(mapFn);
806
+ };
807
+ }
808
+ function toStatic(customType, sharedSlices) {
809
+ const json = Object.entries(customType.json).reduce((acc, [sectionKey, dynSection]) => {
810
+ return { ...acc, [sectionKey]: Sections.toStatic(dynSection, sharedSlices) };
811
+ }, {});
812
+ return { ...customType, json };
813
+ }
814
+ function validateSlices(customType, sharedSlices) {
815
+ const missingSlices = _mapSharedSlicesRefs(customType)((ref) => {
816
+ const slice = sharedSlices.get(ref);
817
+ const isMissing = !Boolean(slice);
818
+ if (isMissing)
819
+ return ref;
820
+ }).filter(Boolean);
821
+ if (missingSlices.length > 0)
822
+ return Either.left(new CustomTypeSlicesError(missingSlices));
823
+ else
824
+ return Either.right(customType);
825
+ }
826
+ function collectWidgets(customType, f) {
827
+ const json = Object.entries(customType.json).reduce((acc, [sectionId, section]) => {
828
+ const updatedSection = Object.entries(section).reduce((acc2, [ref, widget]) => {
829
+ const updatedWidget = f(ref, widget);
830
+ if (!!updatedWidget) {
831
+ return { ...acc2, [ref]: updatedWidget };
832
+ }
833
+ return acc2;
834
+ }, {});
835
+ return { ...acc, [sectionId]: updatedSection };
836
+ }, {});
837
+ return { ...customType, json };
838
+ }
839
+ function filterMissingSharedSlices(customType, sharedSlices) {
840
+ return collectWidgets(customType, (_widgetId, widget) => {
841
+ if (widget.type === WidgetTypes$1.Slices) {
842
+ if (!widget.config || !widget.config.choices)
843
+ return widget;
844
+ const choices = Object.entries(widget.config.choices).reduce((acc, [sliceId, sliceValue]) => {
845
+ if (sliceValue.type === SlicesTypes$1.SharedSlice && !sharedSlices.get(sliceId))
846
+ return acc;
847
+ return { ...acc, [sliceId]: sliceValue };
848
+ }, {});
849
+ const config = { ...widget.config, choices };
850
+ return { ...widget, config };
851
+ }
852
+ return widget;
853
+ });
854
+ }
855
+
856
+ exports.CustomType = CustomType;
857
+ exports.Section = Section;
858
+ exports.StaticCustomType = StaticCustomType;
859
+ exports.Widgets = index;
860
+ exports.collectWidgets = collectWidgets;
861
+ exports.filterMissingSharedSlices = filterMissingSharedSlices;
862
+ exports.toStatic = toStatic;
863
+ exports.validateSlices = validateSlices;
864
+ //# sourceMappingURL=index.js.map