@prismicio/types-internal 2.4.0-alpha.3 → 2.4.0-alpha.5
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 +1035 -1
- package/lib/content/Document.js +4 -0
- package/lib/content/fields/GroupContent.d.ts +1 -0
- package/lib/content/fields/GroupContent.js +5 -1
- package/lib/content/fields/WidgetContent.d.ts +1035 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +1036 -2
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +26 -7
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +2060 -0
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.js +30 -0
- package/lib/content/fields/slices/Slice/index.d.ts +718 -1
- package/lib/content/fields/slices/Slice/index.js +1 -0
- package/lib/content/fields/slices/SliceItem.d.ts +717 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +1035 -1
- package/lib/content/fields/withDefaultValues.d.ts +3 -1
- package/lib/content/fields/withDefaultValues.js +26 -1
- package/package.json +1 -1
- package/src/content/Document.ts +4 -0
- package/src/content/fields/GroupContent.ts +5 -0
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +38 -22
- package/src/content/fields/slices/Slice/SlicePrimaryContent.ts +40 -0
- package/src/content/fields/slices/Slice/index.ts +1 -0
- package/src/content/fields/withDefaultValues.ts +48 -1
|
@@ -7,12 +7,14 @@ 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
9
|
const io_ts_types_1 = require("io-ts-types");
|
|
10
|
+
const customtypes_1 = require("../../../../customtypes");
|
|
10
11
|
const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
|
|
11
12
|
const utils_1 = require("../../../utils");
|
|
12
13
|
const GroupContent_1 = require("../../GroupContent");
|
|
13
14
|
const nestable_1 = require("../../nestable");
|
|
14
15
|
const withDefaultValues_1 = require("../../withDefaultValues");
|
|
15
16
|
const RepeatableContent_1 = require("./RepeatableContent");
|
|
17
|
+
const SlicePrimaryContent_1 = require("./SlicePrimaryContent");
|
|
16
18
|
exports.SharedSliceContentType = "SharedSliceContent";
|
|
17
19
|
const isSharedSliceContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.SharedSliceContentType;
|
|
18
20
|
exports.isSharedSliceContent = isSharedSliceContent;
|
|
@@ -40,7 +42,7 @@ const SharedSliceLegacy = (ctx) => {
|
|
|
40
42
|
parsedSlice.variation,
|
|
41
43
|
"primary",
|
|
42
44
|
]);
|
|
43
|
-
const result = (0,
|
|
45
|
+
const result = (0, SlicePrimaryContent_1.SlicePrimaryLegacy)(FieldCtx).decode(value);
|
|
44
46
|
if (!result)
|
|
45
47
|
return acc;
|
|
46
48
|
if ((0, Either_1.isLeft)(result))
|
|
@@ -61,7 +63,7 @@ const SharedSliceLegacy = (ctx) => {
|
|
|
61
63
|
s.variation,
|
|
62
64
|
"primary",
|
|
63
65
|
]);
|
|
64
|
-
const result = (0,
|
|
66
|
+
const result = (0, SlicePrimaryContent_1.SlicePrimaryLegacy)(FieldCtx).encode(value);
|
|
65
67
|
if (!result)
|
|
66
68
|
return acc;
|
|
67
69
|
return {
|
|
@@ -95,17 +97,15 @@ exports.SharedSliceLegacy = SharedSliceLegacy;
|
|
|
95
97
|
exports.SharedSliceContent = t.strict({
|
|
96
98
|
__TYPE__: t.literal(exports.SharedSliceContentType),
|
|
97
99
|
variation: t.string,
|
|
98
|
-
primary: t.record(t.string,
|
|
100
|
+
primary: t.record(t.string, SlicePrimaryContent_1.SlicePrimaryContent),
|
|
99
101
|
items: RepeatableContent_1.RepeatableWidgets,
|
|
100
102
|
});
|
|
101
103
|
function sharedSliceContentWithDefaultValues(customType, content) {
|
|
102
104
|
var _a, _b;
|
|
103
105
|
const variationConfig = customType.variations.find((v) => v.id === content.variation);
|
|
104
|
-
|
|
105
|
-
// we support group fields in primary
|
|
106
|
-
const primaryConfig = Object.fromEntries(Object.entries((_a = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.primary) !== null && _a !== void 0 ? _a : {}).filter(([_, value]) => value.type !== "Group"));
|
|
106
|
+
const primaryConfig = (_a = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.primary) !== null && _a !== void 0 ? _a : {};
|
|
107
107
|
const itemsConfig = (_b = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.items) !== null && _b !== void 0 ? _b : {};
|
|
108
|
-
const updatedPrimaryContent = (0, withDefaultValues_1.
|
|
108
|
+
const updatedPrimaryContent = (0, withDefaultValues_1.withDefaultSlicePrimaryContentValues)(primaryConfig, content.primary);
|
|
109
109
|
const updatedItemsContent = (0, withDefaultValues_1.repeatableContentWithDefaultNestableContentValues)(itemsConfig, content.items);
|
|
110
110
|
return {
|
|
111
111
|
...content,
|
|
@@ -119,6 +119,25 @@ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content,
|
|
|
119
119
|
const primary = Object.entries(content.widget.primary).reduce((acc, [fieldKey, fieldContent]) => {
|
|
120
120
|
var _a, _b;
|
|
121
121
|
const fieldDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b[fieldKey];
|
|
122
|
+
if ((0, GroupContent_1.isGroupContent)(fieldContent) && (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) {
|
|
123
|
+
const transformedGroupField = (0, GroupContent_1.traverseGroupContent)({
|
|
124
|
+
path: path.concat([
|
|
125
|
+
{ key: "primary", type: "primary" },
|
|
126
|
+
{ key: fieldKey, type: "Widget" },
|
|
127
|
+
]),
|
|
128
|
+
key: fieldKey,
|
|
129
|
+
apiId: sliceName,
|
|
130
|
+
content: fieldContent,
|
|
131
|
+
model: fieldDef,
|
|
132
|
+
})(transformWidget);
|
|
133
|
+
// Can happen if the transform function returns undefined to filter out a field
|
|
134
|
+
if (!transformedGroupField)
|
|
135
|
+
return acc;
|
|
136
|
+
return {
|
|
137
|
+
...acc,
|
|
138
|
+
[fieldKey]: transformedGroupField,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
122
141
|
const transformedField = transformWidget({
|
|
123
142
|
path: path.concat([
|
|
124
143
|
{ key: "primary", type: "primary" },
|