@prismicio/types-internal 3.10.2-alpha.3 → 3.11.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.
- package/lib/content/Document.js +61 -82
- package/lib/content/fields/RepeatableContent.d.ts +51 -123
- package/lib/content/fields/RepeatableContent.js +10 -14
- package/lib/content/fields/nestable/RichTextContent/Block.d.ts +1036 -0
- package/lib/content/fields/nestable/RichTextContent/Block.js +31 -0
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.d.ts +60 -0
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.js +53 -0
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.d.ts +203 -0
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.js +36 -0
- package/lib/content/fields/nestable/RichTextContent/TableBlock.d.ts +500 -0
- package/lib/content/fields/nestable/RichTextContent/TableBlock.js +21 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +590 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +80 -0
- package/lib/customtypes/CustomType.js +11 -18
- package/lib/customtypes/Section.js +33 -41
- package/lib/customtypes/widgets/Group.js +32 -52
- package/lib/customtypes/widgets/nestable/Link.d.ts +49 -0
- package/lib/customtypes/widgets/nestable/Link.js +3 -3
- package/lib/customtypes/widgets/slices/SharedSlice.js +45 -64
- package/package.json +3 -3
- package/src/content/Document.ts +67 -87
- package/src/customtypes/CustomType.ts +12 -19
- package/src/customtypes/Section.ts +33 -47
- package/src/customtypes/widgets/Group.ts +39 -61
- package/src/customtypes/widgets/nestable/Link.ts +1 -1
- package/src/customtypes/widgets/slices/SharedSlice.ts +50 -78
package/lib/content/Document.js
CHANGED
|
@@ -149,89 +149,68 @@ function traverseDocument({ document, customType, }) {
|
|
|
149
149
|
? simplifyCustomType(customType)
|
|
150
150
|
: customType;
|
|
151
151
|
return ({ transformWidget = ({ content }) => content, transformSlice = ({ content }) => content, }) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
const fieldModels = model &&
|
|
153
|
+
Object.entries(model.fields).reduce((acc, [key, def]) => ({ ...acc, [key]: def }), {});
|
|
154
|
+
return Object.entries(document).reduce((acc, [key, content]) => {
|
|
155
|
+
const fieldModel = fieldModels && fieldModels[key];
|
|
156
|
+
const path = utils_1.ContentPath.make([
|
|
157
|
+
{ key: model === null || model === void 0 ? void 0 : model.customTypeId, type: "CustomType" },
|
|
158
|
+
{ key, type: "Widget" },
|
|
159
|
+
]);
|
|
160
|
+
const transformedWidget = (() => {
|
|
161
|
+
switch (content.__TYPE__) {
|
|
162
|
+
case "SliceContentType":
|
|
163
|
+
return (0, fields_1.traverseSlices)({
|
|
164
|
+
path,
|
|
165
|
+
key,
|
|
166
|
+
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Slices" || (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Choice"
|
|
167
|
+
? fieldModel
|
|
168
|
+
: undefined,
|
|
169
|
+
content,
|
|
170
|
+
})({ transformWidget, transformSlice });
|
|
171
|
+
case "GroupContentType":
|
|
172
|
+
return (0, fields_1.traverseGroupContent)({
|
|
173
|
+
path,
|
|
174
|
+
key,
|
|
175
|
+
apiId: key,
|
|
176
|
+
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Group" ? fieldModel : undefined,
|
|
177
|
+
content,
|
|
178
|
+
})(transformWidget);
|
|
179
|
+
case "RepeatableContent":
|
|
180
|
+
return (0, fields_1.traverseRepeatableContent)({
|
|
181
|
+
path,
|
|
182
|
+
key,
|
|
183
|
+
apiId: key,
|
|
184
|
+
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Link" ? fieldModel : undefined,
|
|
185
|
+
content,
|
|
186
|
+
})(transformWidget);
|
|
187
|
+
case "TableContent":
|
|
188
|
+
return (0, fields_1.traverseTableContent)({
|
|
189
|
+
path,
|
|
190
|
+
key,
|
|
191
|
+
apiId: key,
|
|
192
|
+
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Table" ? fieldModel : undefined,
|
|
193
|
+
content,
|
|
194
|
+
})(transformWidget);
|
|
195
|
+
default:
|
|
196
|
+
return transformWidget({
|
|
197
|
+
path,
|
|
198
|
+
key,
|
|
199
|
+
apiId: key,
|
|
200
|
+
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Group" &&
|
|
201
|
+
(fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Slices" &&
|
|
202
|
+
(fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Choice"
|
|
203
|
+
? fieldModel
|
|
204
|
+
: undefined,
|
|
205
|
+
content,
|
|
206
|
+
});
|
|
163
207
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (key) {
|
|
171
|
-
const content = document[key];
|
|
172
|
-
if (content) {
|
|
173
|
-
const fieldModel = fieldModels && fieldModels[key];
|
|
174
|
-
const path = utils_1.ContentPath.make([
|
|
175
|
-
{ key: model === null || model === void 0 ? void 0 : model.customTypeId, type: "CustomType" },
|
|
176
|
-
{ key, type: "Widget" },
|
|
177
|
-
]);
|
|
178
|
-
const transformedWidget = (() => {
|
|
179
|
-
switch (content.__TYPE__) {
|
|
180
|
-
case "SliceContentType":
|
|
181
|
-
return (0, fields_1.traverseSlices)({
|
|
182
|
-
path,
|
|
183
|
-
key,
|
|
184
|
-
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Slices" ||
|
|
185
|
-
(fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Choice"
|
|
186
|
-
? fieldModel
|
|
187
|
-
: undefined,
|
|
188
|
-
content,
|
|
189
|
-
})({ transformWidget, transformSlice });
|
|
190
|
-
case "GroupContentType":
|
|
191
|
-
return (0, fields_1.traverseGroupContent)({
|
|
192
|
-
path,
|
|
193
|
-
key,
|
|
194
|
-
apiId: key,
|
|
195
|
-
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Group" ? fieldModel : undefined,
|
|
196
|
-
content,
|
|
197
|
-
})(transformWidget);
|
|
198
|
-
case "RepeatableContent":
|
|
199
|
-
return (0, fields_1.traverseRepeatableContent)({
|
|
200
|
-
path,
|
|
201
|
-
key,
|
|
202
|
-
apiId: key,
|
|
203
|
-
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Link" ? fieldModel : undefined,
|
|
204
|
-
content,
|
|
205
|
-
})(transformWidget);
|
|
206
|
-
case "TableContent":
|
|
207
|
-
return (0, fields_1.traverseTableContent)({
|
|
208
|
-
path,
|
|
209
|
-
key,
|
|
210
|
-
apiId: key,
|
|
211
|
-
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Table" ? fieldModel : undefined,
|
|
212
|
-
content,
|
|
213
|
-
})(transformWidget);
|
|
214
|
-
default:
|
|
215
|
-
return transformWidget({
|
|
216
|
-
path,
|
|
217
|
-
key,
|
|
218
|
-
apiId: key,
|
|
219
|
-
model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Group" &&
|
|
220
|
-
(fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Slices" &&
|
|
221
|
-
(fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Choice"
|
|
222
|
-
? fieldModel
|
|
223
|
-
: undefined,
|
|
224
|
-
content,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
})();
|
|
228
|
-
if (transformedWidget) {
|
|
229
|
-
result[key] = transformedWidget;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return result;
|
|
208
|
+
})();
|
|
209
|
+
return {
|
|
210
|
+
...acc,
|
|
211
|
+
...(transformedWidget ? { [key]: transformedWidget } : {}),
|
|
212
|
+
};
|
|
213
|
+
}, {});
|
|
235
214
|
};
|
|
236
215
|
}
|
|
237
216
|
exports.traverseDocument = traverseDocument;
|
|
@@ -1,90 +1,18 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils";
|
|
3
|
-
import {
|
|
3
|
+
import type { Link, 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>;
|
|
79
5
|
export declare const RepeatableContent: t.ExactC<t.TypeC<{
|
|
80
6
|
__TYPE__: t.LiteralC<"RepeatableContent">;
|
|
81
|
-
type: t.
|
|
82
|
-
value: t.ArrayC<t.ExactC<t.TypeC<{
|
|
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<{
|
|
83
11
|
__TYPE__: t.LiteralC<"LinkContent">;
|
|
84
12
|
value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
85
13
|
__TYPE__: t.LiteralC<"ImageLink">;
|
|
86
|
-
}>>, t.
|
|
87
|
-
kind: t.
|
|
14
|
+
}>>, t.IntersectionC<[t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
15
|
+
kind: t.Type<"image", "image", unknown>;
|
|
88
16
|
id: t.StringC;
|
|
89
17
|
url: t.StringC;
|
|
90
18
|
height: t.StringC;
|
|
@@ -93,38 +21,35 @@ export declare const RepeatableContent: t.ExactC<t.TypeC<{
|
|
|
93
21
|
name: t.StringC;
|
|
94
22
|
}>>, t.ExactC<t.PartialC<{
|
|
95
23
|
date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
96
|
-
}>>]>, t.ExactC<t.PartialC<{
|
|
97
|
-
text: t.StringC;
|
|
98
24
|
}>>]>, t.ExactC<t.TypeC<{
|
|
99
25
|
kind: t.LiteralC<"image">;
|
|
26
|
+
}>>]>, t.ExactC<t.PartialC<{
|
|
100
27
|
text: t.StringC;
|
|
101
28
|
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
102
29
|
__TYPE__: t.LiteralC<"FileLink">;
|
|
103
|
-
}>>, t.
|
|
104
|
-
kind: t.
|
|
30
|
+
}>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
31
|
+
kind: t.Type<"file", "file", unknown>;
|
|
105
32
|
id: t.StringC;
|
|
106
33
|
url: t.StringC;
|
|
107
34
|
name: t.StringC;
|
|
108
35
|
size: t.StringC;
|
|
109
36
|
}>, t.PartialC<{
|
|
110
37
|
date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
111
|
-
}>]>>, t.ExactC<t.
|
|
112
|
-
text: t.StringC;
|
|
113
|
-
}>>]>, t.ExactC<t.TypeC<{
|
|
38
|
+
}>]>>, t.ExactC<t.TypeC<{
|
|
114
39
|
kind: t.LiteralC<"file">;
|
|
40
|
+
}>>]>, t.ExactC<t.PartialC<{
|
|
115
41
|
text: t.StringC;
|
|
116
42
|
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
117
43
|
__TYPE__: t.LiteralC<"DocumentLink">;
|
|
118
|
-
}>>, t.
|
|
44
|
+
}>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.TypeC<{
|
|
119
45
|
id: t.Type<string, string, unknown>;
|
|
120
|
-
}>>, t.ExactC<t.
|
|
121
|
-
text: t.StringC;
|
|
122
|
-
}>>]>, t.ExactC<t.TypeC<{
|
|
46
|
+
}>>, t.ExactC<t.TypeC<{
|
|
123
47
|
kind: t.LiteralC<"document">;
|
|
48
|
+
}>>]>, t.ExactC<t.PartialC<{
|
|
124
49
|
text: t.StringC;
|
|
125
50
|
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
126
51
|
__TYPE__: t.LiteralC<"ExternalLink">;
|
|
127
|
-
}>>, t.
|
|
52
|
+
}>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
128
53
|
url: t.StringC;
|
|
129
54
|
}>, t.PartialC<{
|
|
130
55
|
kind: t.LiteralC<"web">;
|
|
@@ -134,33 +59,37 @@ export declare const RepeatableContent: t.ExactC<t.TypeC<{
|
|
|
134
59
|
}, {
|
|
135
60
|
title?: string;
|
|
136
61
|
}, unknown>, t.NullC, t.UndefinedC]>;
|
|
137
|
-
}>]>>, t.ExactC<t.
|
|
138
|
-
text: t.StringC;
|
|
139
|
-
}>>]>, t.ExactC<t.TypeC<{
|
|
62
|
+
}>]>>, t.ExactC<t.TypeC<{
|
|
140
63
|
kind: t.LiteralC<"web">;
|
|
64
|
+
}>>]>, t.ExactC<t.PartialC<{
|
|
141
65
|
text: t.StringC;
|
|
142
66
|
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
143
67
|
__TYPE__: t.LiteralC<"MediaLink">;
|
|
144
|
-
}>>, t.ExactC<t.TypeC<{
|
|
68
|
+
}>>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
145
69
|
kind: t.LiteralC<"media">;
|
|
70
|
+
}>>, t.ExactC<t.PartialC<{
|
|
146
71
|
text: t.StringC;
|
|
147
|
-
}>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
72
|
+
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
148
73
|
__TYPE__: t.LiteralC<"AnyLink">;
|
|
149
|
-
}>>, t.ExactC<t.TypeC<{
|
|
74
|
+
}>>, t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
75
|
+
kind: t.LiteralC<"any">;
|
|
76
|
+
}>, t.PartialC<{
|
|
150
77
|
text: t.StringC;
|
|
151
|
-
}>>]>]>;
|
|
152
|
-
}
|
|
78
|
+
}>]>>]>]>;
|
|
79
|
+
}>>]>>;
|
|
153
80
|
}>>;
|
|
154
81
|
export declare type RepeatableContent = t.TypeOf<typeof RepeatableContent>;
|
|
155
82
|
export declare const isRepeatableContent: t.Is<{
|
|
156
83
|
__TYPE__: "RepeatableContent";
|
|
157
|
-
type: "
|
|
158
|
-
value: {
|
|
84
|
+
type: "Link";
|
|
85
|
+
value: ({
|
|
86
|
+
key: string;
|
|
87
|
+
} & {
|
|
159
88
|
__TYPE__: "LinkContent";
|
|
160
89
|
value: ({
|
|
161
90
|
__TYPE__: "ImageLink";
|
|
162
|
-
} & (({
|
|
163
|
-
kind:
|
|
91
|
+
} & ((({
|
|
92
|
+
kind: "image";
|
|
164
93
|
id: string;
|
|
165
94
|
url: string;
|
|
166
95
|
height: string;
|
|
@@ -169,43 +98,41 @@ export declare const isRepeatableContent: t.Is<{
|
|
|
169
98
|
name: string;
|
|
170
99
|
} & {
|
|
171
100
|
date?: string | null | undefined;
|
|
172
|
-
} & {
|
|
173
|
-
text?: string;
|
|
174
101
|
}) | {
|
|
175
102
|
kind: "image";
|
|
176
|
-
|
|
103
|
+
}) & {
|
|
104
|
+
text?: string;
|
|
177
105
|
})) | ({
|
|
178
106
|
__TYPE__: "FileLink";
|
|
179
|
-
} & (({
|
|
180
|
-
kind:
|
|
107
|
+
} & ((({
|
|
108
|
+
kind: "file";
|
|
181
109
|
id: string;
|
|
182
110
|
url: string;
|
|
183
111
|
name: string;
|
|
184
112
|
size: string;
|
|
185
113
|
} & {
|
|
186
114
|
date?: string | null | undefined;
|
|
187
|
-
} & {
|
|
188
|
-
text?: string;
|
|
189
115
|
}) | {
|
|
190
116
|
kind: "file";
|
|
191
|
-
|
|
117
|
+
}) & {
|
|
118
|
+
text?: string;
|
|
192
119
|
})) | ({
|
|
193
120
|
__TYPE__: "MediaLink";
|
|
194
121
|
} & {
|
|
195
122
|
kind: "media";
|
|
196
|
-
|
|
123
|
+
} & {
|
|
124
|
+
text?: string;
|
|
197
125
|
}) | ({
|
|
198
126
|
__TYPE__: "DocumentLink";
|
|
199
127
|
} & (({
|
|
200
128
|
id: string;
|
|
201
|
-
}
|
|
202
|
-
text?: string;
|
|
203
|
-
}) | {
|
|
129
|
+
} | {
|
|
204
130
|
kind: "document";
|
|
205
|
-
|
|
131
|
+
}) & {
|
|
132
|
+
text?: string;
|
|
206
133
|
})) | ({
|
|
207
134
|
__TYPE__: "ExternalLink";
|
|
208
|
-
} & (({
|
|
135
|
+
} & ((({
|
|
209
136
|
url: string;
|
|
210
137
|
} & {
|
|
211
138
|
kind?: "web";
|
|
@@ -213,19 +140,20 @@ export declare const isRepeatableContent: t.Is<{
|
|
|
213
140
|
preview?: {
|
|
214
141
|
title?: string;
|
|
215
142
|
} | null | undefined;
|
|
216
|
-
} & {
|
|
217
|
-
text?: string;
|
|
218
143
|
}) | {
|
|
219
144
|
kind: "web";
|
|
220
|
-
|
|
145
|
+
}) & {
|
|
146
|
+
text?: string;
|
|
221
147
|
})) | ({
|
|
222
148
|
__TYPE__: "AnyLink";
|
|
223
149
|
} & {
|
|
224
|
-
|
|
150
|
+
kind: "any";
|
|
151
|
+
} & {
|
|
152
|
+
text?: string;
|
|
225
153
|
});
|
|
226
|
-
}[];
|
|
154
|
+
})[];
|
|
227
155
|
}>;
|
|
228
|
-
export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType:
|
|
156
|
+
export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: "Link") => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>;
|
|
229
157
|
export declare type RepeatableCustomType = Link;
|
|
230
158
|
export declare function traverseRepeatableContent({ path, key, apiId, model, content, }: {
|
|
231
159
|
path: ContentPath;
|
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent =
|
|
3
|
+
exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = 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");
|
|
10
9
|
const nestable_1 = require("./nestable");
|
|
11
|
-
exports.RepeatableContentType = "RepeatableContent";
|
|
12
|
-
exports.RepeatableFieldType = "Repeatable";
|
|
13
|
-
exports.RepeatableItemContent = nestable_1.LinkContent;
|
|
14
10
|
exports.RepeatableContent = t.strict({
|
|
15
|
-
__TYPE__: t.literal(
|
|
16
|
-
type:
|
|
17
|
-
|
|
18
|
-
value: t.array(exports.RepeatableItemContent),
|
|
11
|
+
__TYPE__: t.literal("RepeatableContent"),
|
|
12
|
+
type: t.literal("Link"),
|
|
13
|
+
value: t.array(nestable_1.LinkContent),
|
|
19
14
|
});
|
|
20
15
|
exports.isRepeatableContent = exports.RepeatableContent.is;
|
|
21
16
|
const RepeatableLegacy = (ctx, fieldType) => {
|
|
22
|
-
const codecDecode = t.array(t.unknown);
|
|
23
|
-
const codecEncode = t.array(exports.RepeatableItemContent);
|
|
24
17
|
return new t.Type("RepeatableLegacy", exports.isRepeatableContent, (items) => {
|
|
25
|
-
const parsed = (0, function_1.pipe)(
|
|
18
|
+
const parsed = (0, function_1.pipe)(t.array(t.unknown).decode(items), fp_ts_1.either.map((items) => {
|
|
26
19
|
const parsedItems = items.reduce((acc, item) => {
|
|
27
20
|
let result;
|
|
28
21
|
switch (fieldType) {
|
|
@@ -39,12 +32,12 @@ const RepeatableLegacy = (ctx, fieldType) => {
|
|
|
39
32
|
return {
|
|
40
33
|
value: parsedItems,
|
|
41
34
|
type: fieldType,
|
|
42
|
-
__TYPE__:
|
|
35
|
+
__TYPE__: "RepeatableContent",
|
|
43
36
|
};
|
|
44
37
|
}));
|
|
45
38
|
return parsed;
|
|
46
39
|
}, (r) => {
|
|
47
|
-
const res =
|
|
40
|
+
const res = t.array(nestable_1.LinkContent).encode(r.value);
|
|
48
41
|
const encodedItems = res.reduce((acc, item) => {
|
|
49
42
|
let encoded;
|
|
50
43
|
switch (item.__TYPE__) {
|
|
@@ -79,6 +72,9 @@ function traverseRepeatableContent({ path, key, apiId, model, content, }) {
|
|
|
79
72
|
// Can happen if the transform function returns undefined to filter out a field
|
|
80
73
|
if (!transformedField)
|
|
81
74
|
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;
|
|
82
78
|
return acc.concat(transformedField);
|
|
83
79
|
}, []);
|
|
84
80
|
return transform({
|