@prismicio/types-internal 2.4.1 → 2.5.0-alpha.1
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.d.ts +3982 -7936
- package/lib/content/fields/GroupContent.d.ts +17 -1754
- package/lib/content/fields/GroupContent.js +59 -21
- package/lib/content/fields/WidgetContent.d.ts +3375 -7328
- package/lib/content/fields/nestable/NestableContent.d.ts +3 -145
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +4 -212
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +2 -0
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +4 -184
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +10 -294
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -385
- package/lib/content/fields/slices/Slice/RepeatableContent.js +4 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +19 -1337
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +7 -1182
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +7 -1182
- package/lib/content/fields/slices/Slice/index.d.ts +991 -2943
- package/lib/content/fields/slices/SliceItem.d.ts +155 -2107
- package/lib/content/fields/slices/SlicesContent.d.ts +1134 -3912
- package/lib/content/fields/withDefaultValues.d.ts +4 -3
- package/lib/content/fields/withDefaultValues.js +17 -1
- package/lib/customtypes/CustomType.d.ts +70 -915
- package/lib/customtypes/Section.d.ts +70 -915
- package/lib/customtypes/diff/SharedSlice.d.ts +2 -340
- package/lib/customtypes/diff/Variation.d.ts +3 -340
- package/lib/customtypes/diff/Widgets.d.ts +1 -1
- package/lib/customtypes/widgets/Group.d.ts +15 -331
- package/lib/customtypes/widgets/Group.js +22 -5
- package/lib/customtypes/widgets/Widget.d.ts +7 -1014
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -168
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +2 -336
- package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +3 -338
- package/lib/customtypes/widgets/slices/Slices.d.ts +7 -1184
- package/package.json +5 -5
- package/src/content/fields/GroupContent.ts +101 -31
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +3 -1
- package/src/content/fields/slices/Slice/RepeatableContent.ts +9 -2
- package/src/content/fields/withDefaultValues.ts +27 -3
- package/src/customtypes/diff/Variation.ts +4 -2
- package/src/customtypes/diff/Widgets.ts +1 -7
- package/src/customtypes/widgets/Group.ts +60 -20
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -727
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +0 -327
- package/lib/customtypes/widgets/slices/SliceWidget.js +0 -8
|
@@ -1,27 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupContentDefaultValue = exports.
|
|
3
|
+
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupContentDefaultValue = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = 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
|
+
const function_2 = require("../../validators/function");
|
|
9
11
|
const LegacyContentCtx_1 = require("../LegacyContentCtx");
|
|
10
12
|
const utils_1 = require("../utils");
|
|
11
13
|
const nestable_1 = require("./nestable");
|
|
12
14
|
const withDefaultValues_1 = require("./withDefaultValues");
|
|
15
|
+
exports.GroupContentType = "GroupContentType";
|
|
16
|
+
const isGroupContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.GroupContentType;
|
|
17
|
+
exports.isGroupContent = isGroupContent;
|
|
18
|
+
const MAX_GROUP_DEPTH = 1;
|
|
19
|
+
const getGroupDepth = (group, depth = 0) => {
|
|
20
|
+
// Stop searching when we're over limit
|
|
21
|
+
if (depth > MAX_GROUP_DEPTH)
|
|
22
|
+
return depth;
|
|
23
|
+
for (const item of group.value) {
|
|
24
|
+
for (const [_key, widget] of item.value) {
|
|
25
|
+
if ((0, exports.isGroupContent)(widget)) {
|
|
26
|
+
depth = Math.max(depth, getGroupDepth(widget, depth + 1));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return depth;
|
|
31
|
+
};
|
|
32
|
+
exports.GroupContent = (0, function_2.refineType)(t.recursion("GroupContent", () => t.strict({
|
|
33
|
+
__TYPE__: t.literal(exports.GroupContentType),
|
|
34
|
+
value: t.array(exports.GroupItemContent),
|
|
35
|
+
})), "GroupContent", (g) => {
|
|
36
|
+
return getGroupDepth(g) <= MAX_GROUP_DEPTH;
|
|
37
|
+
});
|
|
13
38
|
exports.GroupItemContentType = "GroupItemContent";
|
|
14
|
-
exports.GroupItemContent = t.strict({
|
|
39
|
+
exports.GroupItemContent = t.recursion("GroupItemContent", () => t.strict({
|
|
15
40
|
__TYPE__: t.literal(exports.GroupItemContentType),
|
|
16
|
-
value: t.array(t.tuple([t.string, nestable_1.NestableContent])),
|
|
17
|
-
});
|
|
41
|
+
value: t.array(t.tuple([t.string, t.union([nestable_1.NestableContent, exports.GroupContent])])),
|
|
42
|
+
}));
|
|
18
43
|
const itemLegacyReader = t.record(t.string, t.unknown);
|
|
19
44
|
const GroupItemLegacy = (ctx) => {
|
|
20
45
|
return new t.Type("GroupItemLegacy", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.GroupItemContentType, (u) => {
|
|
21
46
|
const parsed = (0, function_1.pipe)(itemLegacyReader.decode(u), fp_ts_1.either.map((items) => {
|
|
22
47
|
const parsedItems = Object.entries(items).reduce((acc, [itemKey, itemValue]) => {
|
|
23
48
|
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(itemKey, ctx);
|
|
24
|
-
const result =
|
|
49
|
+
const result = itemCtx.fieldType === "Group"
|
|
50
|
+
? (0, exports.GroupLegacy)(itemCtx).decode(itemValue)
|
|
51
|
+
: (0, nestable_1.NestableLegacy)(itemCtx).decode(itemValue);
|
|
25
52
|
if (!result)
|
|
26
53
|
return acc;
|
|
27
54
|
if ((0, Either_1.isLeft)(result))
|
|
@@ -37,7 +64,9 @@ const GroupItemLegacy = (ctx) => {
|
|
|
37
64
|
}, (item) => {
|
|
38
65
|
return item.value.reduce((acc, [key, value]) => {
|
|
39
66
|
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(key, ctx);
|
|
40
|
-
const encoded = (0,
|
|
67
|
+
const encoded = (0, exports.isGroupContent)(value)
|
|
68
|
+
? (0, exports.GroupLegacy)(itemCtx).encode(value)
|
|
69
|
+
: (0, nestable_1.NestableLegacy)(itemCtx).encode(value);
|
|
41
70
|
if (!encoded)
|
|
42
71
|
return acc;
|
|
43
72
|
return {
|
|
@@ -75,13 +104,6 @@ const GroupLegacy = (ctx) => {
|
|
|
75
104
|
});
|
|
76
105
|
};
|
|
77
106
|
exports.GroupLegacy = GroupLegacy;
|
|
78
|
-
exports.GroupContentType = "GroupContentType";
|
|
79
|
-
const isGroupContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.GroupContentType;
|
|
80
|
-
exports.isGroupContent = isGroupContent;
|
|
81
|
-
exports.GroupContent = t.strict({
|
|
82
|
-
__TYPE__: t.literal(exports.GroupContentType),
|
|
83
|
-
value: t.array(exports.GroupItemContent),
|
|
84
|
-
});
|
|
85
107
|
exports.GroupContentDefaultValue = {
|
|
86
108
|
__TYPE__: exports.GroupContentType,
|
|
87
109
|
value: [],
|
|
@@ -126,15 +148,31 @@ function traverseGroupItemsContent({ path, model, content, }) {
|
|
|
126
148
|
]);
|
|
127
149
|
const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
128
150
|
const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
151
|
+
let transformedField;
|
|
152
|
+
if ((!fieldDef || (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) &&
|
|
153
|
+
fieldContent.__TYPE__ === exports.GroupContentType) {
|
|
154
|
+
console.log({ yes: "yes" });
|
|
155
|
+
transformedField = traverseGroupContent({
|
|
156
|
+
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
157
|
+
key: fieldKey,
|
|
158
|
+
apiId: fieldKey,
|
|
159
|
+
model: fieldDef,
|
|
160
|
+
content: fieldContent,
|
|
161
|
+
})(transform);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
transformedField = transform({
|
|
165
|
+
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
166
|
+
key: fieldKey,
|
|
167
|
+
apiId: fieldKey,
|
|
168
|
+
model: fieldDef,
|
|
169
|
+
content: fieldContent,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
136
172
|
// Can happen if the transform function returns undefined to filter out a field
|
|
137
|
-
if (!transformedField ||
|
|
173
|
+
if (!transformedField ||
|
|
174
|
+
!((0, nestable_1.isNestableContent)(transformedField) ||
|
|
175
|
+
(0, exports.isGroupContent)(transformedField)))
|
|
138
176
|
return acc;
|
|
139
177
|
return acc.concat([[fieldKey, transformedField]]);
|
|
140
178
|
}, []);
|