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