@prismicio/types-internal 3.9.0 → 3.10.0-alpha.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.
@@ -1,5 +1,5 @@
1
1
  import type { RepeatableContent, SharedSliceItemContent, SliceItemContent, WidgetContent } from "../content";
2
- import type { CompositeSlice, Group, NestableWidget, StaticSlices, UID, VariationFields } from "../customtypes";
2
+ import type { CompositeSlice, Group, NestableWidget, NestedGroup, StaticSlices, UID, VariationFields } from "../customtypes";
3
3
  export declare type TraverseSliceContentFn = <S extends SliceItemContent | SharedSliceItemContent, D extends VariationFields | CompositeSlice | Group | NestableWidget>({ path, key, apiId, model, content, }: {
4
4
  path: ContentPath;
5
5
  key: string;
@@ -29,3 +29,8 @@ export declare const ContentPath: {
29
29
  }>): ContentPath;
30
30
  };
31
31
  export declare type SliceModel = VariationFields | NestableWidget | CompositeSlice | Group;
32
+ export declare type OnFieldFn<T extends UID | NestableWidget | Group | NestedGroup> = (args: {
33
+ path: ReadonlyArray<string>;
34
+ key: string;
35
+ field: T;
36
+ }) => T;
@@ -4626,7 +4626,7 @@ declare function parseLegacyDocument(legacyDoc: unknown, customType: StaticCusto
4626
4626
  }): Document | undefined;
4627
4627
  declare function encodeToLegacyDocument(document: Document): DocumentLegacy;
4628
4628
  export declare const DocumentLegacy: {
4629
- _codec: (allTypes?: Map<string, "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Table" | "Text" | "Timestamp" | "Group" | "Slice" | "SharedSlice" | "Choice" | "Slices" | "UID" | "Repeatable.Link"> | undefined) => t.Type<{
4629
+ _codec: (allTypes?: Map<string, "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Table" | "Text" | "Timestamp" | "Group" | "UID" | "Slice" | "SharedSlice" | "Choice" | "Slices" | "Repeatable.Link"> | undefined) => t.Type<{
4630
4630
  [x: string]: {
4631
4631
  type: string;
4632
4632
  __TYPE__: "EmptyContent";
@@ -1,18 +1,90 @@
1
1
  import * as t from "io-ts";
2
2
  import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils";
3
- import type { Link, NestableWidget } from "../../customtypes";
3
+ import { type Link, NestableFieldTypes, NestableWidget } from "../../customtypes";
4
4
  import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
5
+ export declare const RepeatableContentType: "RepeatableContent";
6
+ export declare const RepeatableFieldType: "Repeatable";
7
+ export declare const RepeatableItemContent: t.ExactC<t.TypeC<{
8
+ __TYPE__: t.LiteralC<"LinkContent">;
9
+ value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
10
+ __TYPE__: t.LiteralC<"ImageLink">;
11
+ }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
12
+ kind: t.StringC;
13
+ id: t.StringC;
14
+ url: t.StringC;
15
+ height: t.StringC;
16
+ width: t.StringC;
17
+ size: t.StringC;
18
+ name: t.StringC;
19
+ }>>, t.ExactC<t.PartialC<{
20
+ date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
21
+ }>>]>, t.ExactC<t.PartialC<{
22
+ text: t.StringC;
23
+ }>>]>, t.ExactC<t.TypeC<{
24
+ kind: t.LiteralC<"image">;
25
+ text: t.StringC;
26
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
27
+ __TYPE__: t.LiteralC<"FileLink">;
28
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
29
+ kind: t.StringC;
30
+ id: t.StringC;
31
+ url: t.StringC;
32
+ name: t.StringC;
33
+ size: t.StringC;
34
+ }>, t.PartialC<{
35
+ date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
36
+ }>]>>, t.ExactC<t.PartialC<{
37
+ text: t.StringC;
38
+ }>>]>, t.ExactC<t.TypeC<{
39
+ kind: t.LiteralC<"file">;
40
+ text: t.StringC;
41
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
42
+ __TYPE__: t.LiteralC<"DocumentLink">;
43
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
44
+ id: t.Type<string, string, unknown>;
45
+ }>>, t.ExactC<t.PartialC<{
46
+ text: t.StringC;
47
+ }>>]>, t.ExactC<t.TypeC<{
48
+ kind: t.LiteralC<"document">;
49
+ text: t.StringC;
50
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
51
+ __TYPE__: t.LiteralC<"ExternalLink">;
52
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
53
+ url: t.StringC;
54
+ }>, t.PartialC<{
55
+ kind: t.LiteralC<"web">;
56
+ target: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
57
+ preview: t.UnionC<[t.Type<{
58
+ title?: string;
59
+ }, {
60
+ title?: string;
61
+ }, unknown>, t.NullC, t.UndefinedC]>;
62
+ }>]>>, t.ExactC<t.PartialC<{
63
+ text: t.StringC;
64
+ }>>]>, t.ExactC<t.TypeC<{
65
+ kind: t.LiteralC<"web">;
66
+ text: t.StringC;
67
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
68
+ __TYPE__: t.LiteralC<"MediaLink">;
69
+ }>>, t.ExactC<t.TypeC<{
70
+ kind: t.LiteralC<"media">;
71
+ text: t.StringC;
72
+ }>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
73
+ __TYPE__: t.LiteralC<"AnyLink">;
74
+ }>>, t.ExactC<t.TypeC<{
75
+ text: t.StringC;
76
+ }>>]>]>;
77
+ }>>;
78
+ export declare type RepeatableItemContent = t.TypeOf<typeof RepeatableItemContent>;
5
79
  export declare const RepeatableContent: t.ExactC<t.TypeC<{
6
80
  __TYPE__: t.LiteralC<"RepeatableContent">;
7
- type: t.LiteralC<"Link">;
8
- value: t.ArrayC<t.IntersectionC<[t.ExactC<t.TypeC<{
9
- key: t.Type<string, string, unknown>;
10
- }>>, t.ExactC<t.TypeC<{
81
+ type: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>;
82
+ value: t.ArrayC<t.ExactC<t.TypeC<{
11
83
  __TYPE__: t.LiteralC<"LinkContent">;
12
84
  value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
13
85
  __TYPE__: t.LiteralC<"ImageLink">;
14
- }>>, t.IntersectionC<[t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
15
- kind: t.Type<"image", "image", unknown>;
86
+ }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
87
+ kind: t.StringC;
16
88
  id: t.StringC;
17
89
  url: t.StringC;
18
90
  height: t.StringC;
@@ -21,35 +93,38 @@ export declare const RepeatableContent: t.ExactC<t.TypeC<{
21
93
  name: t.StringC;
22
94
  }>>, t.ExactC<t.PartialC<{
23
95
  date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
96
+ }>>]>, t.ExactC<t.PartialC<{
97
+ text: t.StringC;
24
98
  }>>]>, t.ExactC<t.TypeC<{
25
99
  kind: t.LiteralC<"image">;
26
- }>>]>, t.ExactC<t.PartialC<{
27
100
  text: t.StringC;
28
101
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
29
102
  __TYPE__: t.LiteralC<"FileLink">;
30
- }>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
31
- kind: t.Type<"file", "file", unknown>;
103
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
104
+ kind: t.StringC;
32
105
  id: t.StringC;
33
106
  url: t.StringC;
34
107
  name: t.StringC;
35
108
  size: t.StringC;
36
109
  }>, t.PartialC<{
37
110
  date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
38
- }>]>>, t.ExactC<t.TypeC<{
111
+ }>]>>, t.ExactC<t.PartialC<{
112
+ text: t.StringC;
113
+ }>>]>, t.ExactC<t.TypeC<{
39
114
  kind: t.LiteralC<"file">;
40
- }>>]>, t.ExactC<t.PartialC<{
41
115
  text: t.StringC;
42
116
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
43
117
  __TYPE__: t.LiteralC<"DocumentLink">;
44
- }>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.TypeC<{
118
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
45
119
  id: t.Type<string, string, unknown>;
46
- }>>, t.ExactC<t.TypeC<{
120
+ }>>, t.ExactC<t.PartialC<{
121
+ text: t.StringC;
122
+ }>>]>, t.ExactC<t.TypeC<{
47
123
  kind: t.LiteralC<"document">;
48
- }>>]>, t.ExactC<t.PartialC<{
49
124
  text: t.StringC;
50
125
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
51
126
  __TYPE__: t.LiteralC<"ExternalLink">;
52
- }>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
127
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
53
128
  url: t.StringC;
54
129
  }>, t.PartialC<{
55
130
  kind: t.LiteralC<"web">;
@@ -59,37 +134,33 @@ export declare const RepeatableContent: t.ExactC<t.TypeC<{
59
134
  }, {
60
135
  title?: string;
61
136
  }, unknown>, t.NullC, t.UndefinedC]>;
62
- }>]>>, t.ExactC<t.TypeC<{
137
+ }>]>>, t.ExactC<t.PartialC<{
138
+ text: t.StringC;
139
+ }>>]>, t.ExactC<t.TypeC<{
63
140
  kind: t.LiteralC<"web">;
64
- }>>]>, t.ExactC<t.PartialC<{
65
141
  text: t.StringC;
66
142
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
67
143
  __TYPE__: t.LiteralC<"MediaLink">;
68
- }>>, t.IntersectionC<[t.ExactC<t.TypeC<{
144
+ }>>, t.ExactC<t.TypeC<{
69
145
  kind: t.LiteralC<"media">;
70
- }>>, t.ExactC<t.PartialC<{
71
146
  text: t.StringC;
72
- }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
147
+ }>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
73
148
  __TYPE__: t.LiteralC<"AnyLink">;
74
- }>>, t.ExactC<t.IntersectionC<[t.TypeC<{
75
- kind: t.LiteralC<"any">;
76
- }>, t.PartialC<{
149
+ }>>, t.ExactC<t.TypeC<{
77
150
  text: t.StringC;
78
- }>]>>]>]>;
79
- }>>]>>;
151
+ }>>]>]>;
152
+ }>>>;
80
153
  }>>;
81
154
  export declare type RepeatableContent = t.TypeOf<typeof RepeatableContent>;
82
155
  export declare const isRepeatableContent: t.Is<{
83
156
  __TYPE__: "RepeatableContent";
84
- type: "Link";
85
- value: ({
86
- key: string;
87
- } & {
157
+ type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp";
158
+ value: {
88
159
  __TYPE__: "LinkContent";
89
160
  value: ({
90
161
  __TYPE__: "ImageLink";
91
- } & ((({
92
- kind: "image";
162
+ } & (({
163
+ kind: string;
93
164
  id: string;
94
165
  url: string;
95
166
  height: string;
@@ -98,41 +169,43 @@ export declare const isRepeatableContent: t.Is<{
98
169
  name: string;
99
170
  } & {
100
171
  date?: string | null | undefined;
172
+ } & {
173
+ text?: string;
101
174
  }) | {
102
175
  kind: "image";
103
- }) & {
104
- text?: string;
176
+ text: string;
105
177
  })) | ({
106
178
  __TYPE__: "FileLink";
107
- } & ((({
108
- kind: "file";
179
+ } & (({
180
+ kind: string;
109
181
  id: string;
110
182
  url: string;
111
183
  name: string;
112
184
  size: string;
113
185
  } & {
114
186
  date?: string | null | undefined;
187
+ } & {
188
+ text?: string;
115
189
  }) | {
116
190
  kind: "file";
117
- }) & {
118
- text?: string;
191
+ text: string;
119
192
  })) | ({
120
193
  __TYPE__: "MediaLink";
121
194
  } & {
122
195
  kind: "media";
123
- } & {
124
- text?: string;
196
+ text: string;
125
197
  }) | ({
126
198
  __TYPE__: "DocumentLink";
127
199
  } & (({
128
200
  id: string;
129
- } | {
130
- kind: "document";
131
- }) & {
201
+ } & {
132
202
  text?: string;
203
+ }) | {
204
+ kind: "document";
205
+ text: string;
133
206
  })) | ({
134
207
  __TYPE__: "ExternalLink";
135
- } & ((({
208
+ } & (({
136
209
  url: string;
137
210
  } & {
138
211
  kind?: "web";
@@ -140,20 +213,19 @@ export declare const isRepeatableContent: t.Is<{
140
213
  preview?: {
141
214
  title?: string;
142
215
  } | null | undefined;
216
+ } & {
217
+ text?: string;
143
218
  }) | {
144
219
  kind: "web";
145
- }) & {
146
- text?: string;
220
+ text: string;
147
221
  })) | ({
148
222
  __TYPE__: "AnyLink";
149
223
  } & {
150
- kind: "any";
151
- } & {
152
- text?: string;
224
+ text: string;
153
225
  });
154
- })[];
226
+ }[];
155
227
  }>;
156
- export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: "Link") => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>;
228
+ export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: NestableFieldTypes) => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>;
157
229
  export declare type RepeatableCustomType = Link;
158
230
  export declare function traverseRepeatableContent({ path, key, apiId, model, content, }: {
159
231
  path: ContentPath;
@@ -1,21 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = void 0;
3
+ exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = exports.RepeatableItemContent = exports.RepeatableFieldType = exports.RepeatableContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
7
7
  const function_1 = require("fp-ts/lib/function");
8
8
  const t = (0, tslib_1.__importStar)(require("io-ts"));
9
+ const customtypes_1 = require("../../customtypes");
9
10
  const nestable_1 = require("./nestable");
11
+ exports.RepeatableContentType = "RepeatableContent";
12
+ exports.RepeatableFieldType = "Repeatable";
13
+ exports.RepeatableItemContent = nestable_1.LinkContent;
10
14
  exports.RepeatableContent = t.strict({
11
- __TYPE__: t.literal("RepeatableContent"),
12
- type: t.literal("Link"),
13
- value: t.array(nestable_1.LinkContent),
15
+ __TYPE__: t.literal(exports.RepeatableContentType),
16
+ type: customtypes_1.NestableFieldTypes,
17
+ // TODO: How to ensure it's an array of only one type
18
+ value: t.array(exports.RepeatableItemContent),
14
19
  });
15
20
  exports.isRepeatableContent = exports.RepeatableContent.is;
16
21
  const RepeatableLegacy = (ctx, fieldType) => {
22
+ const codecDecode = t.array(t.unknown);
23
+ const codecEncode = t.array(exports.RepeatableItemContent);
17
24
  return new t.Type("RepeatableLegacy", exports.isRepeatableContent, (items) => {
18
- const parsed = (0, function_1.pipe)(t.array(t.unknown).decode(items), fp_ts_1.either.map((items) => {
25
+ const parsed = (0, function_1.pipe)(codecDecode.decode(items), fp_ts_1.either.map((items) => {
19
26
  const parsedItems = items.reduce((acc, item) => {
20
27
  let result;
21
28
  switch (fieldType) {
@@ -32,12 +39,12 @@ const RepeatableLegacy = (ctx, fieldType) => {
32
39
  return {
33
40
  value: parsedItems,
34
41
  type: fieldType,
35
- __TYPE__: "RepeatableContent",
42
+ __TYPE__: exports.RepeatableContentType,
36
43
  };
37
44
  }));
38
45
  return parsed;
39
46
  }, (r) => {
40
- const res = t.array(nestable_1.LinkContent).encode(r.value);
47
+ const res = codecEncode.encode(r.value);
41
48
  const encodedItems = res.reduce((acc, item) => {
42
49
  let encoded;
43
50
  switch (item.__TYPE__) {
@@ -72,9 +79,6 @@ function traverseRepeatableContent({ path, key, apiId, model, content, }) {
72
79
  // Can happen if the transform function returns undefined to filter out a field
73
80
  if (!transformedField)
74
81
  return acc;
75
- // If the transformed field is not a link content, we don't include it
76
- if (!(0, nestable_1.isLinkContent)(transformedField))
77
- return acc;
78
82
  return acc.concat(transformedField);
79
83
  }, []);
80
84
  return transform({
@@ -1,5 +1,7 @@
1
1
  import { Either } from "fp-ts/lib/Either";
2
2
  import * as t from "io-ts";
3
+ import type { OnFieldFn } from "../_internal/utils";
4
+ import type { Group, NestableWidget, NestedGroup, UID } from "./widgets";
3
5
  import type { SharedSlice } from "./widgets/slices/SharedSlice";
4
6
  import type { DynamicWidget } from "./widgets/Widget";
5
7
  import type { StaticWidget } from "./widgets/Widget";
@@ -572,6 +574,15 @@ export declare const StaticCustomType: t.ExactC<t.IntersectionC<[t.TypeC<{
572
574
  });
573
575
  };
574
576
  };
577
+ }) | ({
578
+ type: "UID";
579
+ } & {
580
+ fieldset?: string | null | undefined;
581
+ config?: {
582
+ label?: string | null | undefined;
583
+ useAsTitle?: boolean;
584
+ placeholder?: string;
585
+ };
575
586
  }) | ({
576
587
  type: "Choice" | "Slices";
577
588
  } & {
@@ -2077,15 +2088,6 @@ export declare const StaticCustomType: t.ExactC<t.IntersectionC<[t.TypeC<{
2077
2088
  });
2078
2089
  };
2079
2090
  };
2080
- }) | ({
2081
- type: "UID";
2082
- } & {
2083
- fieldset?: string | null | undefined;
2084
- config?: {
2085
- label?: string | null | undefined;
2086
- useAsTitle?: boolean;
2087
- placeholder?: string;
2088
- };
2089
2091
  });
2090
2092
  }, unknown, unknown>>;
2091
2093
  status: t.BooleanC;
@@ -2655,6 +2657,15 @@ export declare const CustomType: t.ExactC<t.IntersectionC<[t.TypeC<{
2655
2657
  });
2656
2658
  };
2657
2659
  };
2660
+ }) | ({
2661
+ type: "UID";
2662
+ } & {
2663
+ fieldset?: string | null | undefined;
2664
+ config?: {
2665
+ label?: string | null | undefined;
2666
+ useAsTitle?: boolean;
2667
+ placeholder?: string;
2668
+ };
2658
2669
  }) | ({
2659
2670
  type: "Choice" | "Slices";
2660
2671
  } & {
@@ -3407,15 +3418,6 @@ export declare const CustomType: t.ExactC<t.IntersectionC<[t.TypeC<{
3407
3418
  };
3408
3419
  };
3409
3420
  };
3410
- }) | ({
3411
- type: "UID";
3412
- } & {
3413
- fieldset?: string | null | undefined;
3414
- config?: {
3415
- label?: string | null | undefined;
3416
- useAsTitle?: boolean;
3417
- placeholder?: string;
3418
- };
3419
3421
  });
3420
3422
  }, unknown, unknown>>;
3421
3423
  status: t.BooleanC;
@@ -3437,4 +3439,8 @@ export declare function collectSharedSlices(customType: {
3437
3439
  customTypeId: string;
3438
3440
  fields: Record<string, StaticWidget>;
3439
3441
  }): Record<string, SharedSlice>;
3442
+ export declare function traverseCustomType<T extends CustomType | StaticCustomType>(args: {
3443
+ customType: T;
3444
+ onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>;
3445
+ }): T;
3440
3446
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectSharedSlices = exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenSections = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
3
+ exports.traverseCustomType = exports.collectSharedSlices = exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenSections = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const Either_1 = require("fp-ts/lib/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
@@ -163,3 +163,18 @@ function collectSharedSlices(customType) {
163
163
  }, {});
164
164
  }
165
165
  exports.collectSharedSlices = collectSharedSlices;
166
+ function traverseCustomType(args) {
167
+ const { customType, onField } = args;
168
+ return {
169
+ ...customType,
170
+ json: Object.entries(customType.json).reduce((acc, [key, section]) => {
171
+ acc[key] = (0, Section_1.traverseSection)({
172
+ path: [key],
173
+ section,
174
+ onField,
175
+ });
176
+ return acc;
177
+ }, {}),
178
+ };
179
+ }
180
+ exports.traverseCustomType = traverseCustomType;
@@ -1,4 +1,6 @@
1
1
  import * as t from "io-ts";
2
+ import type { OnFieldFn } from "../_internal/utils";
3
+ import { Group, NestableWidget, NestedGroup, UID } from "./widgets";
2
4
  import type { SharedSlice } from "./widgets/slices";
3
5
  import { DynamicWidget, StaticWidget } from "./widgets/Widget";
4
6
  export declare function sectionReader<T extends StaticWidget | DynamicWidget>(codec: t.Type<T, unknown>): t.RecordC<t.Type<string, string, unknown>, t.Type<T, unknown, unknown>>;
@@ -556,6 +558,15 @@ export declare const StaticSection: t.RecordC<t.Type<string, string, unknown>, t
556
558
  });
557
559
  };
558
560
  };
561
+ }) | ({
562
+ type: "UID";
563
+ } & {
564
+ fieldset?: string | null | undefined;
565
+ config?: {
566
+ label?: string | null | undefined;
567
+ useAsTitle?: boolean;
568
+ placeholder?: string;
569
+ };
559
570
  }) | ({
560
571
  type: "Choice" | "Slices";
561
572
  } & {
@@ -2061,15 +2072,6 @@ export declare const StaticSection: t.RecordC<t.Type<string, string, unknown>, t
2061
2072
  });
2062
2073
  };
2063
2074
  };
2064
- }) | ({
2065
- type: "UID";
2066
- } & {
2067
- fieldset?: string | null | undefined;
2068
- config?: {
2069
- label?: string | null | undefined;
2070
- useAsTitle?: boolean;
2071
- placeholder?: string;
2072
- };
2073
2075
  }), unknown, unknown>>;
2074
2076
  export declare type StaticSection = t.TypeOf<typeof StaticSection>;
2075
2077
  export declare const DynamicSection: t.RecordC<t.Type<string, string, unknown>, t.Type<({
@@ -2626,6 +2628,15 @@ export declare const DynamicSection: t.RecordC<t.Type<string, string, unknown>,
2626
2628
  });
2627
2629
  };
2628
2630
  };
2631
+ }) | ({
2632
+ type: "UID";
2633
+ } & {
2634
+ fieldset?: string | null | undefined;
2635
+ config?: {
2636
+ label?: string | null | undefined;
2637
+ useAsTitle?: boolean;
2638
+ placeholder?: string;
2639
+ };
2629
2640
  }) | ({
2630
2641
  type: "Choice" | "Slices";
2631
2642
  } & {
@@ -3378,17 +3389,13 @@ export declare const DynamicSection: t.RecordC<t.Type<string, string, unknown>,
3378
3389
  };
3379
3390
  };
3380
3391
  };
3381
- }) | ({
3382
- type: "UID";
3383
- } & {
3384
- fieldset?: string | null | undefined;
3385
- config?: {
3386
- label?: string | null | undefined;
3387
- useAsTitle?: boolean;
3388
- placeholder?: string;
3389
- };
3390
3392
  }), unknown, unknown>>;
3391
3393
  export declare type DynamicSection = t.TypeOf<typeof DynamicSection>;
3392
3394
  export declare const Sections: {
3393
3395
  toStatic(dynamic: DynamicSection, sharedSlices: Map<string, SharedSlice>): StaticSection;
3394
3396
  };
3397
+ export declare function traverseSection<T extends DynamicSection | StaticSection>(args: {
3398
+ path: ReadonlyArray<string>;
3399
+ section: T;
3400
+ onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>;
3401
+ }): T;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Sections = exports.DynamicSection = exports.StaticSection = exports.sectionReader = void 0;
3
+ exports.traverseSection = exports.Sections = exports.DynamicSection = exports.StaticSection = exports.sectionReader = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
6
  const common_1 = require("../common");
7
+ const widgets_1 = require("./widgets");
7
8
  const Widget_1 = require("./widgets/Widget");
8
9
  function sectionReader(codec) {
9
10
  return t.record(common_1.WidgetKey, codec); // WidgetId -> Widget Data
@@ -19,3 +20,57 @@ exports.Sections = {
19
20
  return section;
20
21
  },
21
22
  };
23
+ function traverseSection(args) {
24
+ const { path: prevPath, section, onField } = args;
25
+ return Object.entries(section).reduce((acc, [key, prevModel]) => {
26
+ const path = prevPath.concat(key);
27
+ let model;
28
+ switch (prevModel.type) {
29
+ case "Choice":
30
+ case "Slices":
31
+ model = (0, widgets_1.traverseSlices)({
32
+ path,
33
+ slices: prevModel,
34
+ onField: onField,
35
+ });
36
+ break;
37
+ case "Group":
38
+ model = onField({
39
+ path,
40
+ key,
41
+ field: (0, widgets_1.traverseGroup)({
42
+ path,
43
+ group: prevModel,
44
+ onField: onField,
45
+ }),
46
+ });
47
+ break;
48
+ case "Boolean":
49
+ case "Color":
50
+ case "Date":
51
+ case "Embed":
52
+ case "GeoPoint":
53
+ case "Image":
54
+ case "IntegrationFields":
55
+ case "Link":
56
+ case "Number":
57
+ case "Range":
58
+ case "Select":
59
+ case "Separator":
60
+ case "StructuredText":
61
+ case "Table":
62
+ case "Text":
63
+ case "Timestamp":
64
+ case "UID":
65
+ model = onField({
66
+ path,
67
+ key,
68
+ field: prevModel,
69
+ });
70
+ break;
71
+ }
72
+ acc[key] = model;
73
+ return acc;
74
+ }, {});
75
+ }
76
+ exports.traverseSection = traverseSection;
@@ -1,4 +1,6 @@
1
1
  import * as t from "io-ts";
2
+ import type { OnFieldFn } from "../../_internal/utils";
3
+ import { NestableWidget } from "./nestable/NestableWidget";
2
4
  export declare const GroupFieldType = "Group";
3
5
  export declare const NestedGroupConfig: t.ExactC<t.PartialC<{
4
6
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
@@ -1182,3 +1184,13 @@ export declare const Group: t.ExactC<t.IntersectionC<[t.TypeC<{
1182
1184
  }>>;
1183
1185
  }>]>>;
1184
1186
  export declare type Group = t.TypeOf<typeof Group>;
1187
+ export declare function traverseNestedGroup(args: {
1188
+ path: ReadonlyArray<string>;
1189
+ group: NestedGroup;
1190
+ onField: OnFieldFn<NestableWidget>;
1191
+ }): NestedGroup;
1192
+ export declare function traverseGroup(args: {
1193
+ path: ReadonlyArray<string>;
1194
+ group: Group;
1195
+ onField: OnFieldFn<NestableWidget | NestedGroup>;
1196
+ }): Group;