@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 @@
1
+ {"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,671 @@
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
+ var SlicesTypes;
35
+ (function(SlicesTypes2) {
36
+ SlicesTypes2["Slice"] = "Slice";
37
+ SlicesTypes2["SharedSlice"] = "SharedSlice";
38
+ })(SlicesTypes || (SlicesTypes = {}));
39
+ const SlicesTypes$1 = SlicesTypes;
40
+
41
+ const StringOrNull = t__namespace.union([t__namespace.string, t__namespace.null, t__namespace.undefined]);
42
+
43
+ var WidgetTypes;
44
+ (function(WidgetTypes2) {
45
+ WidgetTypes2["Text"] = "Text";
46
+ WidgetTypes2["RichText"] = "StructuredText";
47
+ WidgetTypes2["Color"] = "Color";
48
+ WidgetTypes2["Image"] = "Image";
49
+ WidgetTypes2["Date"] = "Date";
50
+ WidgetTypes2["Timestamp"] = "Timestamp";
51
+ WidgetTypes2["Number"] = "Number";
52
+ WidgetTypes2["Range"] = "Range";
53
+ WidgetTypes2["Select"] = "Select";
54
+ WidgetTypes2["Link"] = "Link";
55
+ WidgetTypes2["Embed"] = "Embed";
56
+ WidgetTypes2["GeoPoint"] = "GeoPoint";
57
+ WidgetTypes2["Separator"] = "Separator";
58
+ WidgetTypes2["UID"] = "UID";
59
+ WidgetTypes2["BooleanField"] = "Boolean";
60
+ WidgetTypes2["IntegrationField"] = "IntegrationFields";
61
+ WidgetTypes2["Group"] = "Group";
62
+ WidgetTypes2["Slices"] = "Slices";
63
+ WidgetTypes2["LegacySlices"] = "Choice";
64
+ })(WidgetTypes || (WidgetTypes = {}));
65
+ const WidgetTypes$1 = WidgetTypes;
66
+
67
+ const ColorConfig = t__namespace.exact(t__namespace.partial({
68
+ label: StringOrNull,
69
+ placeholder: t__namespace.string
70
+ }));
71
+ const Color = t__namespace.exact(t__namespace.intersection([
72
+ t__namespace.type({
73
+ type: t__namespace.literal(WidgetTypes$1.Color)
74
+ }),
75
+ t__namespace.partial({
76
+ fieldset: StringOrNull,
77
+ config: ColorConfig
78
+ })
79
+ ]));
80
+
81
+ const BooleanConfig = t__namespace.exact(t__namespace.partial({
82
+ label: StringOrNull,
83
+ default_value: t__namespace.boolean,
84
+ placeholder_true: t__namespace.string,
85
+ placeholder_false: t__namespace.string
86
+ }));
87
+ const BooleanField = t__namespace.exact(t__namespace.intersection([
88
+ t__namespace.type({
89
+ type: t__namespace.literal(WidgetTypes$1.BooleanField)
90
+ }),
91
+ t__namespace.partial({
92
+ config: BooleanConfig
93
+ })
94
+ ]));
95
+
96
+ const DateConfig = t__namespace.exact(t__namespace.partial({
97
+ label: StringOrNull,
98
+ placeholder: t__namespace.string,
99
+ default: t__namespace.string
100
+ }));
101
+ const Date = t__namespace.exact(t__namespace.intersection([
102
+ t__namespace.type({
103
+ type: t__namespace.literal(WidgetTypes$1.Date)
104
+ }),
105
+ t__namespace.partial({
106
+ fieldset: StringOrNull,
107
+ config: DateConfig
108
+ })
109
+ ]));
110
+
111
+ const EmbedConfig = t__namespace.exact(t__namespace.partial({
112
+ label: StringOrNull,
113
+ placeholder: t__namespace.string,
114
+ useAsTitle: t__namespace.boolean
115
+ }));
116
+ const Embed = t__namespace.exact(t__namespace.intersection([
117
+ t__namespace.type({
118
+ type: t__namespace.literal(WidgetTypes$1.Embed)
119
+ }),
120
+ t__namespace.partial({
121
+ fieldset: StringOrNull,
122
+ config: EmbedConfig
123
+ })
124
+ ]));
125
+
126
+ const GeoPointConfig = t__namespace.exact(t__namespace.partial({
127
+ label: StringOrNull
128
+ }));
129
+ const GeoPoint = t__namespace.exact(t__namespace.intersection([
130
+ t__namespace.type({
131
+ type: t__namespace.literal(WidgetTypes$1.GeoPoint)
132
+ }),
133
+ t__namespace.partial({
134
+ fieldset: StringOrNull,
135
+ config: GeoPointConfig
136
+ })
137
+ ]));
138
+
139
+ const NumberConfig = t__namespace.exact(t__namespace.partial({
140
+ label: StringOrNull,
141
+ placeholder: t__namespace.string,
142
+ min: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
143
+ max: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
144
+ step: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString])
145
+ }));
146
+ const Number = t__namespace.exact(t__namespace.intersection([
147
+ t__namespace.type({
148
+ type: t__namespace.literal(WidgetTypes$1.Number)
149
+ }),
150
+ t__namespace.partial({
151
+ fieldset: StringOrNull,
152
+ config: NumberConfig
153
+ })
154
+ ]));
155
+
156
+ const RangeConfig = t__namespace.exact(t__namespace.partial({
157
+ label: StringOrNull,
158
+ placeholder: t__namespace.string,
159
+ min: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
160
+ max: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString]),
161
+ step: t__namespace.union([t__namespace.number, NumberFromString.NumberFromString])
162
+ }));
163
+ const Range = t__namespace.exact(t__namespace.intersection([
164
+ t__namespace.type({
165
+ type: t__namespace.literal(WidgetTypes$1.Range)
166
+ }),
167
+ t__namespace.partial({
168
+ fieldset: StringOrNull,
169
+ config: RangeConfig
170
+ })
171
+ ]));
172
+
173
+ const IntFromNumber = new t__namespace.Type("IntFromNumber", t__namespace.Int.is, (u, c) => pipeable.pipe(t__namespace.number.validate(u, c), Either.chain((n) => {
174
+ if (t__namespace.Int.is(n))
175
+ return t__namespace.success(n);
176
+ else {
177
+ return t__namespace.success(Math.round(n));
178
+ }
179
+ })), t__namespace.Int.encode);
180
+
181
+ const PixelsRegex = /^([0-9]+)px$/;
182
+ const IntFromPixels = new t__namespace.Type("IntFromPixels", t__namespace.Int.is, (u, c) => pipeable.pipe(t__namespace.string.validate(u, c), Either.chain((strPixels) => {
183
+ try {
184
+ const matched = strPixels.match(PixelsRegex);
185
+ if (!matched)
186
+ return t__namespace.failure(u, c);
187
+ else {
188
+ const parsed = parseInt(matched[1]);
189
+ return t__namespace.success(parsed);
190
+ }
191
+ } catch (e) {
192
+ return t__namespace.failure(u, c);
193
+ }
194
+ })), String);
195
+
196
+ const SideConstraint = new t__namespace.Type("SideConstraints", (u) => {
197
+ return !u || typeof u === "number";
198
+ }, (u, context) => {
199
+ return Either.either.chain(t__namespace.union([
200
+ t__namespace.literal("auto"),
201
+ t__namespace.literal(""),
202
+ t__namespace.Int,
203
+ IntFromString.IntFromString,
204
+ IntFromNumber,
205
+ IntFromPixels,
206
+ t__namespace.null
207
+ ]).validate(u, context), (constraint) => {
208
+ if (constraint === "auto" || constraint === "")
209
+ return t__namespace.success(null);
210
+ return t__namespace.success(constraint);
211
+ });
212
+ }, (res) => res);
213
+ const ImageConstraint = t__namespace.partial({
214
+ width: SideConstraint,
215
+ height: SideConstraint
216
+ });
217
+
218
+ const DEFAULT_OPTION = "paragraph";
219
+ const options = [
220
+ "heading1",
221
+ "heading2",
222
+ "heading3",
223
+ "heading4",
224
+ "heading5",
225
+ "heading6",
226
+ "paragraph",
227
+ "strong",
228
+ "em",
229
+ "preformatted",
230
+ "hyperlink",
231
+ "image",
232
+ "embed",
233
+ "list-item",
234
+ "o-list-item",
235
+ "rtl"
236
+ ];
237
+ const RichTextOptions = new t__namespace.Type("RichTextOptions", (u) => typeof u === "string", (u, context) => {
238
+ return Either.either.chain(t__namespace.union([
239
+ t__namespace.string,
240
+ t__namespace.null
241
+ ]).validate(u, context), (s) => {
242
+ if (!s)
243
+ return t__namespace.success(DEFAULT_OPTION);
244
+ const entries = s.split(",").map((e) => e.trim());
245
+ const filtered = entries.filter((entry) => options.includes(entry));
246
+ if (!filtered.length)
247
+ return t__namespace.success(DEFAULT_OPTION);
248
+ return t__namespace.success(filtered.join(","));
249
+ });
250
+ }, (a) => a);
251
+ const NoLabels = (labels) => {
252
+ if (!labels)
253
+ return t__namespace.success([]);
254
+ };
255
+ const LabelsAsObject = (labels) => {
256
+ if (labels instanceof Object) {
257
+ const labelsObj = labels;
258
+ if (!Object.entries(labelsObj).length)
259
+ return t__namespace.success([]);
260
+ if (labelsObj[""]) {
261
+ return t__namespace.success(labelsObj[""].map((l) => l.name));
262
+ }
263
+ const convertedObjectToArray = Object.entries(labelsObj).reduce((acc, [, labelsEntries]) => {
264
+ return acc.concat(labelsEntries.map((l) => l.name));
265
+ }, []).filter(Boolean);
266
+ return t__namespace.success(convertedObjectToArray);
267
+ }
268
+ };
269
+ const LabelsAsArray = (labels) => {
270
+ if (labels instanceof Array) {
271
+ const isValidLabels = labels.reduce((acc, l) => acc && typeof l === "string", true);
272
+ if (isValidLabels)
273
+ return t__namespace.success(labels);
274
+ }
275
+ };
276
+ const LabelsAsString = (labels) => {
277
+ if (typeof labels === "string") {
278
+ return t__namespace.success([labels]);
279
+ }
280
+ };
281
+ const RichTextLabels = new t__namespace.Type("RichTextLabels", (u) => {
282
+ return u instanceof Array;
283
+ }, (u, context) => {
284
+ const legacyValidator = t__namespace.record(t__namespace.string, t__namespace.array(t__namespace.record(t__namespace.literal("name"), t__namespace.string)));
285
+ const validator = t__namespace.array(t__namespace.string);
286
+ return Either.either.chain(t__namespace.union([
287
+ legacyValidator,
288
+ validator,
289
+ t__namespace.string,
290
+ t__namespace.null
291
+ ]).validate(u, context), (labels) => {
292
+ return NoLabels(labels) || LabelsAsArray(labels) || LabelsAsObject(labels) || LabelsAsString(labels) || t__namespace.failure(u, context);
293
+ });
294
+ }, (res) => res);
295
+ const RichTextConfig = t__namespace.exact(t__namespace.partial({
296
+ label: StringOrNull,
297
+ placeholder: t__namespace.string,
298
+ useAsTitle: t__namespace.boolean,
299
+ single: RichTextOptions,
300
+ multi: RichTextOptions,
301
+ imageConstraint: ImageConstraint,
302
+ labels: RichTextLabels,
303
+ allowTargetBlank: t__namespace.boolean
304
+ }));
305
+ const RichText = t__namespace.exact(t__namespace.intersection([
306
+ t__namespace.type({
307
+ type: t__namespace.literal(WidgetTypes$1.RichText)
308
+ }),
309
+ t__namespace.partial({
310
+ fieldset: StringOrNull,
311
+ config: RichTextConfig
312
+ })
313
+ ]));
314
+
315
+ const StringFromBoolean = new t__namespace.Type("StringFromInt", t__namespace.string.is, (u, c) => pipeable.pipe(t__namespace.boolean.validate(u, c), Either.chain((i) => {
316
+ return t__namespace.success(i.toString());
317
+ })), (i) => i);
318
+
319
+ const StringFromNumber = new t__namespace.Type("StringFromInt", t__namespace.string.is, (u, c) => pipeable.pipe(t__namespace.number.validate(u, c), Either.chain((i) => {
320
+ return t__namespace.success(i.toString());
321
+ })), (i) => i);
322
+
323
+ const SelectConfig = t__namespace.exact(t__namespace.partial({
324
+ label: StringOrNull,
325
+ placeholder: t__namespace.string,
326
+ default_value: t__namespace.string,
327
+ options: t__namespace.array(t__namespace.union([t__namespace.string, StringFromNumber, StringFromBoolean]))
328
+ }));
329
+ const Select = t__namespace.exact(t__namespace.intersection([
330
+ t__namespace.type({
331
+ type: t__namespace.literal(WidgetTypes$1.Select)
332
+ }),
333
+ t__namespace.partial({
334
+ fieldset: StringOrNull,
335
+ config: SelectConfig
336
+ })
337
+ ]));
338
+
339
+ const SeparatorConfig = t__namespace.exact(t__namespace.partial({
340
+ label: StringOrNull
341
+ }));
342
+ const Separator = t__namespace.exact(t__namespace.intersection([
343
+ t__namespace.type({
344
+ type: t__namespace.literal(WidgetTypes$1.Separator)
345
+ }),
346
+ t__namespace.partial({
347
+ config: SeparatorConfig
348
+ })
349
+ ]));
350
+
351
+ const TextConfig = t__namespace.exact(t__namespace.partial({
352
+ label: StringOrNull,
353
+ useAsTitle: t__namespace.boolean,
354
+ placeholder: t__namespace.string
355
+ }));
356
+ const Text = t__namespace.exact(t__namespace.intersection([
357
+ t__namespace.type({
358
+ type: t__namespace.literal(WidgetTypes$1.Text)
359
+ }),
360
+ t__namespace.partial({
361
+ fieldset: StringOrNull,
362
+ config: TextConfig
363
+ })
364
+ ]));
365
+
366
+ const TimestampConfig = t__namespace.exact(t__namespace.partial({
367
+ label: StringOrNull,
368
+ placeholder: t__namespace.string,
369
+ default: t__namespace.string
370
+ }));
371
+ const Timestamp = t__namespace.exact(t__namespace.intersection([
372
+ t__namespace.type({
373
+ type: t__namespace.literal(WidgetTypes$1.Timestamp)
374
+ }),
375
+ t__namespace.partial({
376
+ fieldset: StringOrNull,
377
+ config: TimestampConfig
378
+ })
379
+ ]));
380
+
381
+ const arrayString = (entries) => {
382
+ if (entries instanceof Array) {
383
+ const isValidEntries = entries.reduce((acc, l) => acc && typeof l === "string", true);
384
+ if (isValidEntries)
385
+ return t__namespace.success(entries);
386
+ }
387
+ };
388
+ const plainString = (entries) => {
389
+ if (typeof entries === "string") {
390
+ return t__namespace.success([entries]);
391
+ }
392
+ };
393
+ const MasksArrayString = new t__namespace.Type("MasksArrayString", (u) => {
394
+ return u instanceof Array;
395
+ }, (u, context) => {
396
+ return Either.either.chain(t__namespace.union([
397
+ t__namespace.array(t__namespace.string),
398
+ t__namespace.string
399
+ ]).validate(u, context), (masks) => {
400
+ return arrayString(masks) || plainString(masks) || t__namespace.failure(u, context);
401
+ });
402
+ }, (res) => res);
403
+ const LinkConfig = t__namespace.exact(t__namespace.partial({
404
+ label: StringOrNull,
405
+ useAsTitle: t__namespace.boolean,
406
+ placeholder: t__namespace.string,
407
+ select: withFallback.withFallback(t__namespace.union([
408
+ t__namespace.literal("media"),
409
+ t__namespace.literal("document"),
410
+ t__namespace.literal("web"),
411
+ t__namespace.null
412
+ ]), null),
413
+ customtypes: t__namespace.array(t__namespace.string),
414
+ masks: MasksArrayString,
415
+ tags: MasksArrayString,
416
+ allowTargetBlank: t__namespace.boolean
417
+ }));
418
+ const Link = t__namespace.exact(t__namespace.intersection([
419
+ t__namespace.type({
420
+ type: t__namespace.literal(WidgetTypes$1.Link)
421
+ }),
422
+ t__namespace.partial({
423
+ fieldset: StringOrNull,
424
+ config: LinkConfig
425
+ })
426
+ ]));
427
+
428
+ const Thumbnail = t__namespace.exact(t__namespace.intersection([
429
+ t__namespace.type({
430
+ name: t__namespace.string
431
+ }),
432
+ ImageConstraint
433
+ ]));
434
+ const ImageConfig = t__namespace.exact(t__namespace.partial({
435
+ label: StringOrNull,
436
+ placeholder: t__namespace.string,
437
+ constraint: ImageConstraint,
438
+ thumbnails: t__namespace.array(Thumbnail)
439
+ }));
440
+ const Image = t__namespace.exact(t__namespace.intersection([
441
+ t__namespace.type({
442
+ type: t__namespace.literal(WidgetTypes$1.Image)
443
+ }),
444
+ t__namespace.partial({
445
+ fieldset: StringOrNull,
446
+ config: ImageConfig
447
+ })
448
+ ]));
449
+
450
+ const IntegrationFieldConfig = t__namespace.exact(t__namespace.partial({
451
+ label: StringOrNull,
452
+ placeholder: t__namespace.string,
453
+ catalog: t__namespace.string
454
+ }));
455
+ const IntegrationField = t__namespace.exact(t__namespace.intersection([
456
+ t__namespace.type({
457
+ type: t__namespace.literal(WidgetTypes$1.IntegrationField)
458
+ }),
459
+ t__namespace.partial({
460
+ fieldset: StringOrNull,
461
+ config: IntegrationFieldConfig
462
+ })
463
+ ]));
464
+
465
+ const NestableWidget = t__namespace.union([
466
+ Color,
467
+ BooleanField,
468
+ Embed,
469
+ GeoPoint,
470
+ Date,
471
+ Number,
472
+ Range,
473
+ RichText,
474
+ Select,
475
+ Separator,
476
+ Text,
477
+ Timestamp,
478
+ Link,
479
+ Image,
480
+ IntegrationField
481
+ ]);
482
+
483
+ const CompositeSliceConfig = t__namespace.exact(t__namespace.partial({
484
+ label: StringOrNull
485
+ }));
486
+ const CompositeSlice = t__namespace.exact(t__namespace.intersection([
487
+ t__namespace.type({
488
+ type: t__namespace.literal(SlicesTypes$1.Slice)
489
+ }),
490
+ t__namespace.partial({
491
+ fieldset: StringOrNull,
492
+ description: t__namespace.string,
493
+ icon: t__namespace.string,
494
+ display: t__namespace.string,
495
+ "non-repeat": t__namespace.record(t__namespace.string, NestableWidget),
496
+ repeat: t__namespace.record(t__namespace.string, NestableWidget),
497
+ config: CompositeSliceConfig
498
+ })
499
+ ]));
500
+
501
+ const UIDConfig = t__namespace.exact(t__namespace.partial({
502
+ label: StringOrNull,
503
+ useAsTitle: t__namespace.boolean,
504
+ placeholder: t__namespace.string
505
+ }));
506
+ const UID = t__namespace.exact(t__namespace.intersection([
507
+ t__namespace.type({
508
+ type: t__namespace.literal(WidgetTypes$1.UID)
509
+ }),
510
+ t__namespace.partial({
511
+ fieldset: StringOrNull,
512
+ config: UIDConfig
513
+ })
514
+ ]));
515
+
516
+ const GroupConfig = t__namespace.exact(t__namespace.partial({
517
+ label: StringOrNull,
518
+ repeat: t__namespace.boolean,
519
+ fields: t__namespace.record(t__namespace.string, NestableWidget)
520
+ }));
521
+ const Group = t__namespace.exact(t__namespace.intersection([
522
+ t__namespace.type({
523
+ type: t__namespace.literal(WidgetTypes$1.Group)
524
+ }),
525
+ t__namespace.partial({
526
+ fieldset: StringOrNull,
527
+ icon: t__namespace.string,
528
+ description: t__namespace.string,
529
+ config: GroupConfig
530
+ })
531
+ ]));
532
+
533
+ const LegacySlice = t__namespace.union([
534
+ UID,
535
+ NestableWidget,
536
+ Group
537
+ ]);
538
+
539
+ const IMAGE_PLACEHOLDER_URL = "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format";
540
+ const Variation = t__namespace.exact(t__namespace.intersection([
541
+ t__namespace.type({
542
+ id: t__namespace.string,
543
+ name: t__namespace.string,
544
+ description: t__namespace.string,
545
+ imageUrl: withFallback.withFallback(t__namespace.string, IMAGE_PLACEHOLDER_URL),
546
+ docURL: t__namespace.string,
547
+ version: t__namespace.string
548
+ }),
549
+ t__namespace.partial({
550
+ display: t__namespace.string,
551
+ primary: t__namespace.record(t__namespace.string, NestableWidget),
552
+ items: t__namespace.record(t__namespace.string, NestableWidget)
553
+ })
554
+ ]));
555
+ const SharedSlice = t__namespace.exact(t__namespace.intersection([
556
+ t__namespace.type({
557
+ id: t__namespace.string,
558
+ type: t__namespace.literal(SlicesTypes$1.SharedSlice),
559
+ name: t__namespace.string,
560
+ variations: t__namespace.array(Variation)
561
+ }),
562
+ t__namespace.partial({
563
+ description: t__namespace.string
564
+ })
565
+ ]));
566
+
567
+ const SharedSliceRef = t__namespace.exact(t__namespace.type({
568
+ type: t__namespace.literal(SlicesTypes$1.SharedSlice)
569
+ }));
570
+
571
+ const Slice = /*#__PURE__*/Object.freeze({
572
+ __proto__: null
573
+ });
574
+
575
+ var Format;
576
+ (function(Format2) {
577
+ Format2["Static"] = "static";
578
+ Format2["Dynamic"] = "dynamic";
579
+ })(Format || (Format = {}));
580
+
581
+ const SlicesLabels = t__namespace.union([
582
+ t__namespace.record(t__namespace.string, t__namespace.array(t__namespace.exact(t__namespace.intersection([
583
+ t__namespace.type({
584
+ name: t__namespace.string
585
+ }),
586
+ t__namespace.partial({
587
+ display: t__namespace.string
588
+ })
589
+ ])))),
590
+ t__namespace.null
591
+ ]);
592
+ function slicesConfigReader(format) {
593
+ return t__namespace.exact(t__namespace.partial({
594
+ label: StringOrNull,
595
+ labels: SlicesLabels,
596
+ choices: t__namespace.record(t__namespace.string, t__namespace.union([
597
+ LegacySlice,
598
+ CompositeSlice,
599
+ (() => {
600
+ switch (format) {
601
+ case Format.Static:
602
+ return SharedSlice;
603
+ case Format.Dynamic:
604
+ return SharedSliceRef;
605
+ default:
606
+ throw new Error(`Invalid Format Exception: ${format} doesn't exist`);
607
+ }
608
+ })()
609
+ ]))
610
+ }));
611
+ }
612
+ const StaticSlicesConfig = slicesConfigReader(Format.Static);
613
+ const DynamicSlicesConfig = slicesConfigReader(Format.Dynamic);
614
+ const SlicesConfig = {
615
+ toStatic(config, sharedSlices) {
616
+ const choices = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
617
+ if (slice.type === SlicesTypes$1.SharedSlice) {
618
+ const sharedSlice = sharedSlices.get(ref);
619
+ if (sharedSlice)
620
+ return { ...acc, [ref]: sharedSlice };
621
+ else
622
+ return acc;
623
+ } else {
624
+ return { ...acc, [ref]: slice };
625
+ }
626
+ }, {});
627
+ return { ...config, choices };
628
+ }
629
+ };
630
+ function slicesReader(format) {
631
+ return t__namespace.exact(t__namespace.intersection([
632
+ t__namespace.type({
633
+ type: t__namespace.union([t__namespace.literal(WidgetTypes$1.Slices), t__namespace.literal(WidgetTypes$1.LegacySlices)])
634
+ }),
635
+ t__namespace.partial({
636
+ fieldset: StringOrNull,
637
+ config: slicesConfigReader(format)
638
+ })
639
+ ]));
640
+ }
641
+ const StaticSlices = slicesReader(Format.Static);
642
+ const DynamicSlices = slicesReader(Format.Dynamic);
643
+ const Slices = {
644
+ toStatic(slices, sharedSlices) {
645
+ if (!slices.config)
646
+ return slices;
647
+ else {
648
+ return { ...slices, config: SlicesConfig.toStatic(slices.config, sharedSlices) };
649
+ }
650
+ }
651
+ };
652
+
653
+ const Slices$1 = /*#__PURE__*/Object.freeze({
654
+ __proto__: null,
655
+ slicesConfigReader: slicesConfigReader,
656
+ StaticSlicesConfig: StaticSlicesConfig,
657
+ DynamicSlicesConfig: DynamicSlicesConfig,
658
+ slicesReader: slicesReader,
659
+ StaticSlices: StaticSlices,
660
+ DynamicSlices: DynamicSlices,
661
+ Slices: Slices
662
+ });
663
+
664
+ exports.CompositeSlice = CompositeSlice;
665
+ exports.LegacySlice = LegacySlice;
666
+ exports.SharedSlice = SharedSlice;
667
+ exports.SharedSliceRef = SharedSliceRef;
668
+ exports.Slice = Slice;
669
+ exports.SliceZone = Slices$1;
670
+ exports.SlicesTypes = SlicesTypes$1;
671
+ //# sourceMappingURL=index.js.map